cordova
Fastlane pluginIf you decided to build your project with the cordova
Fastlane plugin follow these instructions:
The details for building apps greatly depend on the versions of the software and build tools used to build, and in Cordova’s case on the version of the libraries used to create the app.
This article was created when the following versions of the tools and Cordova libraries were current:
cordova-ios
4.5.4cordova-android
6.3.0If your software and libraries are older than this, it is very much possible that these instructions don’t work 100% for you. If your local setup is newer than the listed versions, you should probably be fine. (Please comment at the end of this article if you encounter any problems - make sure to include your local versions!)
Though you can execute shell commands directly from Fastlane with the sh
action and so could theoretically execute the CLI commands as usual, there is a much more convenient solution available: Fastlane Plugins.
cordova
Fastlane pluginThe Cordova plugin packages the cordova build
command in a handy Fastlane action that can be used inside a Fastfile
. It takes the usual parameters like the platform or --debug
.
Install it by executing the following command on the command line:
fastlane add_plugin cordova
This will setup your project for fastlane plugins by adding a Gemfile
and Gemfile.lock
to the project root. (These are similar to package.json
and package-lock.json
for JavaScript dependencies, just for ruby gems.)
This will create a Pluginfile
next to the Appfile
and Fastfile
in your fastlane
folder :
# Autogenerated by fastlane
#
# Ensure this file is checked in to source control!
gem 'fastlane-plugin-cordova'
Now you can use the cordova
action in your lanes.
The first step is to do a “Debug” build that is debuggable. It can be used to test the app on a device or emulator, but later also to distribute it to your testers via a third party distribution service like HockeyApp.
Just copy the following lanes in the correct platform
area of your Fastfile
:
Start with Android, as everything is simpler with Android:
desc "Build Debug"
lane :build_debug do
cordova(
platform: 'android',
release: false
)
end
You can run this by executing fastlane android build_debug
.
When you try to build your iOS project with the expected iOS equivalents to the Android actions you will unfortunately encounter a big red error message: You have to take care of certificates to be able to build for iOS.
Fortunately, Fastlane offers its own tool for this. Read more about how to setup iOS certificate handling with Fastlane’s match
before continuing.
When you are done, the certificates are in place and you only have to add a match
call to your lane:
desc "Build Debug"
lane :build_debug do
match(type: 'development')
cordova(
platform: 'ios',
release: false,
type: 'development'
)
end
You can run this by executing fastlane ios build_debug
.
Now that you can build the Debug version of your app, go and upload your app for testing with HockeyApp.
When you are done with testing it’s time to build a Release version of your app. As with the CLI commands you are used to, only minimal changes are needed here.
For Android the Release version of an app has to be signed (and zipaligned). The plugin can of course take care of that, but you need a key and a keystore file that contains it, both secured with a password before you can begin.
You can create those using Android Studio (Open Android Studio -> Build -> Generate Signed APK… -> Create New) if you have it installed or do it manually on the command line using keytool
.
Put the generated file one level above your Ionic/Cordova project, and you can use a lane similar to this to build your Android project for production:
desc "Build Release"
lane :build_release do
cordova(
platform: 'android',
release: true,
keystore_path: '../FastlaneIonic.keystore',
keystore_password: 'xyz',
keystore_alias: 'FastlaneIonic',
key_password: 'xyz'
)
end
If you remove keystore_password
and key_password
it will prompt you during the (first) build process.
For iOS you don’t have to change that much as you already had to do additional work for the Debug build by initiating and configuring match
to handle certificates. Now this pays off, as you only have to change some parameters slightly:
desc "Build Release"
lane :build_release do
match(type: 'appstore')
cordova(
platform: 'ios',
release: true
)
end
With the Release version of your app also built, you can either upload this build for testing with Testflight and Play Store Alpha) or even publish your app to the stores.