After Deploying Cordova apps to Heroku, now I want to push my app to mobile App Stores! After Googling around, I come across fastlane, an open source project to automate building, signing and pushing Apps to the Google Play Store and Apple App Store.
Here’s how it works for a Cordova app.
Installing Fastlane
Installing this for my Cordova project was a little tricky. The guides I used were:
https://medium.com/bam-tech/introducing-our-new-cordova-plugin-for-fastlane-3ec3ef9f1642
https://docs.fastlane.tools/getting-started/android/setup/
https://docs.fastlane.tools/actions/match/
But I ran into some errors following those steps, like: An error occurred while installing unf_ext (0.0.7.5), and Bundler cannot continue.
Here’s the steps I ran which worked for me (I’m using MacOS, brew and have gem installed):
cd swrlList— the project directory-
mkdir fastlane
-
touch fastlane/Appfile fastlane/Fastfile brew install fastlane— (Or usesudo gem install fastlane -NV)sudo gem install bundler— NBfastlane add_plugin cordovaerrored for me, so I used bundler which worked.touch Gemfile- Added this to the Gemfile:
source "https://rubygems.org" gem "fastlane" bundle updatebundle exec fastlane add_plugin cordova— answered ‘y’ when prompted- Created GitHub repo for match (this is private of course, so you can’t see it): https://github.com/mrkyle7/swrl-list-certificates
bundle exec fastlane match init– Initialise the match plugin for keys. I chose git as my store.- Uncommented and changed the app identifier line in the Matchfile to:
app_identifier(["co.swrl.List2"])— this is the id of my App, so change it to the ID of yours. bundle exec fastlane match development— followed the prompts. At this point I skipped iOS deploys as I don’t have a development account yet with Apple and don’t want to shell out $99 yet!- Created an API user for the Google Play Store (as per this guide) and put the
play-store-keys.jsonfile in the root of the project. Remember to add this to your .gitignore file so you don’t check it in - Added
json_key_file "play-store-keys.json"to fastlane/Appfile - Generated a keystore to sign the Android APK, see here for how. Note that if you have uploaded an app before to the Play Store and want to now use the App Signing from Google (recommended) you will need to create a new keystore.
- In fastlane/.env set the passwords to sign the apk (again add to .gitignore):
KEYPASSWORD="****" STOREPASSWORD="****"
- Updated fastlane/FastFile (you will need to replace the paths to keys and package name accordingly):
platform :ios do desc "Deploy ios app on the appstore" lane :create do produce(app_name: "SwrlList2") end lane :deploy do match( type: "appstore", git_url: "git@github.com:mrkyle7/swrl-list-certificates.git" ) cordova(platform: 'ios') # Using the Cordova Fastlane Plugin appstore(ipa: ENV['CORDOVA_IOS_RELEASE_BUILD_PATH']) end end platform :android do desc "Deploy android app on play store" lane :deploy do cordova( platform: 'android', keystore_path: '/Users/kyle/androidkey-swrl.jks', keystore_alias: 'kjhandroid', key_password: ENV['KEYPASSWORD'], keystore_password: ENV['STOREPASSWORD'] ) # Cordova Fastlane Plugin upload_to_play_store( apk: ENV["CORDOVA_ANDROID_RELEASE_BUILD_PATH"], track: "beta", package_name: "co.swrl.List2" ) end end- Notes
- You need specify the package_name in the
upload_to_play_storestep supplyis an alias forupload_to_play_storebut I prefer the more explicit name- The ENV[“…”] properties need to match what is in the .env file
- My App is still in Beta, so I’m using the beta track
- You need specify the package_name in the
- Notes
- Added:
<icon src="res/icon/icon.png" />to set the app icon (more details here) - This is the first time I’m uploading the app to the Play Store, so I needed to deploy it manually first.
- Built and signed the apk using cordova:
cordova build android --release -- --keystore=/Users/kyle/androidkey-swrl.jks --storePassword=***** --alias=kjhandroid --password=*****— NB use\to escape any special characters in your passwords, egP*&!SSWDwould beP\*\&\!SSWD - Output looked like this:
BUILD SUCCESSFUL in 6s 46 actionable tasks: 2 executed, 44 up-to-date Built the following apk(s): /Users/kyle/projects/swrlList/platforms/android/app/build/outputs/apk/release/app-release.apk
- Uploaded the APK to the Google Play Store
- This involved updating all the site listing information. Make sure all the ticks are Green on the left hand side of the console window!
- I needed a privacy policy. See https://app-privacy-policy-generator.firebaseapp.com/# for an easy way to generate one for your app for free! Host it on Heroku, see Deploying Cordova apps to Heroku to see how to easily host your cordova app on Heroku.
- Built and signed the apk using cordova:
- Downloaded the Store Listing information to the project:
bundle exec fastlane supply init— when prompted, gave the application package ID as per your config.xml. This created all the listing files like screenshots and descriptions intofastlane/metadata/android - Updated
config.xmland release notes for the release:- Set the Android Version:
android-versionCode="10001"in the <widget> section - Added a changelog file to fastlane/metadata/android/en-GB/changelogs/10001.txt: note 10001 is the same number as the android-versionCode set
- Updated any screenshots and images I wished for the listing. Apparently FastLane can do this for you which is cool! See: https://docs.fastlane.tools/getting-started/android/screenshots/
- Set the Android Version:
- Built and deployed to the Play Store with one line command:
bundle exec fastlane android deploy
PHEW! That was a lot of hard work. Luckily it was all a one-off exercise.
Now, the only steps I need to do to deploy changes to the play store are #22 and #23! Simples!
The working example referenced in this blog is here: https://play.google.com/store/apps/details?id=co.swrl.List2
And the source is here: https://github.com/mrkyle7/SwrlList2
One thought on “Deploying apps in the Fast Lane!”