Deploying apps in the Fast Lane!

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):

  1. cd swrlList — the project directory
  2. mkdir fastlane

  3. touch fastlane/Appfile fastlane/Fastfile

  4. brew install fastlane — (Or use sudo gem install fastlane -NV)
  5. sudo gem install bundler — NB fastlane add_plugin cordova errored for me, so I used bundler which worked.
  6. touch Gemfile
  7. Added this to the Gemfile:
    source "https://rubygems.org" 
    gem "fastlane"
  8. bundle update
  9. bundle exec fastlane add_plugin cordova — answered ‘y’ when prompted
  10. Created GitHub repo for match (this is private of course, so you can’t see it): https://github.com/mrkyle7/swrl-list-certificates
  11. bundle exec fastlane match init – Initialise the match plugin for keys. I chose git as my store.
  12. 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.
  13. 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!
  14. Created an API user for the Google Play Store (as per this guide) and put the play-store-keys.json file in the root of the project. Remember to add this to your .gitignore file so you don’t check it in
  15. Added json_key_file "play-store-keys.json" to fastlane/Appfile
  16. 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.
  17. In fastlane/.env set the passwords to sign the apk (again add to .gitignore):
    KEYPASSWORD="****"
    STOREPASSWORD="****"
  18. 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
    1. Notes
      1. You need specify the package_name in the upload_to_play_store step
      2. supply is an alias for upload_to_play_store but I prefer the more explicit name
      3. The ENV[“…”] properties need to match what is in the .env file
      4. My App is still in Beta, so I’m using the beta track
  19. Added: <icon src="res/icon/icon.png" /> to set the app icon (more details here)
  20. This is the first time I’m uploading the app to the Play Store, so I needed to deploy it manually first.
    1. 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, eg P*&!SSWD would be P\*\&\!SSWD
    2. 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
    3. Uploaded the APK to the Google Play Store
      1. This involved updating all the site listing information. Make sure all the ticks are Green on the left hand side of the console window!
      2. 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.
  21. 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 into fastlane/metadata/android
  22. Updated config.xml and release notes for the release:
    1. Set the Android Version: android-versionCode="10001" in the <widget> section
    2. Added a changelog file to fastlane/metadata/android/en-GB/changelogs/10001.txt: note 10001 is the same number as the android-versionCode set
    3. 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/
  23.  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!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.