Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
CI, short for Continuous Integration, is a good practice to move fast and confidently where code is integrated into shared repository many times a day. The ability to have pull requests get built, tested and release builds get distributed to testers allows team to verify automated build and identify problems quickly.
I âve been using BuddyBuild for both iOS and Android apps and were very happy with it. The experience from creating new apps and deploying build is awesome. It works so well that Apple acquired it, which then lead to the fact that Android apps are no longer supported and new customers canât register.
We are one of those who are looking for new alternatives. Weâve been using TravisCI, CircleCI and Jenkins to deploy to Fabric. There is also TeamCity that is promising. But after a quick survey with friends and people, Bitrise is the most recommended. So maybe I should try that.
The thing I like about Bitrise is its wide range support of workflow. They are just scripts that execute certain actions, and most of them are open source. Thereâs also yml config file, but all things can be done using web interface, so I donât need to look into pages of documentation just to get the configuration right.
This post is not a promote for Bitrise, it is just about trying and adapting to new things. There is no eternal thing in tech, things come ad go fast. Below are some of the lessons I learn after using Bitrise, hope you find them useful.
Variant to build
For some strange reasons, Bitrise does not have Android Build step by default, although it can recognise all build variants at app creation. I hope this get solved soon, in the mean time we can easily add new step. Usually I want app module and stagingRelease build variant as we need to deploy staging builds to internal testers.
If you go to Bitrise.yml tab you can see that the configuration file has been updated. This is very handy. Iâve used some other CI services and I needed to lookup their documentation on how to make this yml work.
Bump version code automatically
Iâve used some other CI services before and the app version code surely does not start from 0. So it makes sense that Bitrise can auto bump version code from the current number. There are some predefined steps in Workflow but they donât serve my need
For the Set Android Manifest Version code and name step, the source code is here so I understand what it does. It works by modify AndroidManifest.xml file using sed . This article Adjust your build number is not clear enough.
sed -i.bak âs/android:versionCode=â\â${VERSIONCODE}\ââ/android:versionCode=â\â${CONFIG_new_version_code}\ââ/â ${manifest_file}
In our projects, the versionCode is from an environment variable BUILD_NUMBER in Jenkins, so we need look up the same thing in Available Environment Variables, and it is BITRISE_BUILD_NUMBERÂ , which is a build number of the build on bitrise.io.
This is how versionCode looks like in build.gradle
versionCode (System.getenv("BITRISE_BUILD_NUMBER") as Integer ?: System.getenv("BUILD_NUMBER") as Integer ?: 243)
243 is the current version code of this project, so letâs go to appâs Settings and change Your next build number will be
Deploy to Fabric
I hope Bitrise has its own Crash reporting tool. For now I use Crashlytics in Fabric. And despite that Bitrise can distribute builds to testers, I still need to cross deploy to Fabric for historial reasons.
There is only script steps-fabric-crashlytics-beta-deploy to deploy IPA file for iOS apps, so we need something for Android. Fortunately I can use the Fabric plugin for gradle.
Add Fabric plugin
Follow Install Crashlytics via Gradle to add Fabric plugin. Basically you need to add these dependencies to your app âs build.gradle
buildscript { repositories { google() maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'io.fabric.tools:gradle:1.+' }}apply plugin: 'io.fabric'
dependencies { compile('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') { transitive = true; }}
and API credentials in Manifest file
<meta-data android:name=âio.fabric.ApiKeyâ android:value=â67ffdb78ce9cd50af8404c244fa25df01ea2b5bcâ />
Deploy command
Modern Android Studio usually includes a gradlew execution file in the root of your project. Run ./gradlew tasks for the list of tasks that you app can perform, look for Build tasks that start with assemble . Read more Build your app from the command line
You can execute all the build tasks available to your Android project using the Gradle wrapper command line tool. Itâs available as a batch file for Windows (gradlew.bat) and a shell script for Linux and Mac (gradlew.sh), and it's accessible from the root of each project you create with Android Studio.
For me, I want to deploy staging release build variant, so I run. Check that the build is on Fabric.
./gradlew assembleStagingRelease crashlyticsUploadDistributionStagingRelease
Manage tester group
Go to your app on Fabric.io and create group of testers. Note that alias that is generated for the group
Go to your appâs build.gradle and add ext.betaDistributionGroupAliases=âmy-internal-testers' to your desired productFlavors or buildTypes . For me I add to staging under productFlavors
productFlavors { staging { // ⊠ext.betaDistributionGroupAliases=âhyper-internal-testers-1' } production { // ⊠}}
Now that the command is run correctly, letâs add that to Bitrise
Gradle Run step
Go to Workflow tab and add a Gradle Run step and place it below Deploy to Bitrise.io step.
Expand Config, and add assembleStagingRelease crashlyticsUploadDistributionStagingRelease to Gradle task to run .
Now start a new build in Bitrise manually or trigger new build by making pull request, you can see that the version code is increased for every build, crossed build gets deployed to Fabric to your defined tester groups.
Where to go from here
I hope those tips are useful to you. Here are some more links to help you explore further
- Convert old Android workflows and configure new steps based on the old Gradle tasks on Bitrise
- Replace whole line containing a string using Sed
- Alternatives to Buddybuild?
- Simplifying Android app distribution with Beta by Crashlytics
- Fabric app for Android Studio
- Crashlytics distribution for app with multiple flavors
- Gradle plugins
- Setting up a new app in Crashlytics without the IDEÂ plugin
Using Bitrise CI for Android apps was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.