Skip to content

Instantly share code, notes, and snippets.

@joshdholtz
Last active November 1, 2020 10:20
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save joshdholtz/b4ff6480fe6c682da92cbf6713346aca to your computer and use it in GitHub Desktop.
Save joshdholtz/b4ff6480fe6c682da92cbf6713346aca to your computer and use it in GitHub Desktop.
Integrate fastlane into your Ionic/Cordova build process
FASTLANE_TEAM_ID = <your team id>
FASTLANE_USER = <your user email>
PRODUCE_APP_IDENTIFIER = com.fastlanescreencast.FastlaneScreencast
CERT_APP_IDENTIFIER = com.fastlanescreencast.FastlaneScreencast
SIGH_APP_IDENTIFIER = com.fastlanescreencast.FastlaneScreencast
ANDROID_KEYSTORE_KEYSTORE_NAME = FastlaneScreencast.keystore
ANDROID_KEYSTORE_ALIAS_NAME = fastlanescreencast
ANDROID_KEYSTORE_PASSWORD = supersecret
ANDROID_KEYSTORE_KEY_PASSWORD = supersecret
ANDROID_KEYSTORE_FULL_NAME = Fastlane Screencast
ANDROID_KEYSTORE_ORG = fastcast
ANDROID_KEYSTORE_ORG_UNIT = fastcast
ANDROID_KEYSTORE_CITY_LOCALITY = Chicago
ANDROID_KEYSTORE_STATE_PROVINCE = IL
ANDROID_KEYSTORE_COUNTRY = US
ANDROID_KEYSTORE_KEYSTORE_NAME = FastlaneScreencast.keystore
ANDROID_KEYSTORE_ALIAS_NAME = fastlanescreencast
ANDROID_KEYSTORE_PASSWORD = supersecret
ANDROID_KEYSTORE_KEY_PASSWORD = supersecret
ANDROID_KEYSTORE_FULL_NAME = Fastlane Screencast
ANDROID_KEYSTORE_ORG = fastcast
ANDROID_KEYSTORE_ORG_UNIT = fastcast
ANDROID_KEYSTORE_CITY_LOCALITY = Chicago
ANDROID_KEYSTORE_STATE_PROVINCE = IL
ANDROID_KEYSTORE_COUNTRY = US
FASTLANE_TEAM_ID = <your team id>
FASTLANE_USER = <your user email>
PRODUCE_APP_IDENTIFIER = com.fastlanescreencast.FastlaneScreencast
CERT_APP_IDENTIFIER = com.fastlanescreencast.FastlaneScreencast
SIGH_APP_IDENTIFIER = com.fastlanescreencast.FastlaneScreencast
$: fastlane add_plugin android_keystore
$: fastlane build android
$: fastlane build ios
platform :android do
lane :build do
# fastlane plugin added by running `fastlane add_plugin android_keystore`
output_directory = android_keystore(generate_cordova_release_signing: true)
UI.user_error! "`android_keystore` directory needs to exists" unless File.directory?(output_directory)
# Delete platforms/android so we always start from scratch
FileUtils.rm_rf('../platforms/android')
# Add Android platform to Ionic project
sh "(cd .. && ionic cordova platform add android)"
# Copy contents of ".android_signing" to platforms/android
FileUtils.cp_r Dir.glob("#{output_directory}/*"), '../platforms/android'
# Build Android release APK
sh "(cd .. && ionic cordova build android --release)"
# Get APK path
apk_path = Dir.glob(File.join(Dir.pwd, "../platforms/android/build/outputs/apk/*-release.apk")).first
apk_path = File.absolute_path apk_path
UI.success "Successfully built APK: #{apk_path}"
end
end
platform :ios do
lane :build do
# Create app in the iOS dev center
produce(
app_name: 'FastlaneScreencast',
language: 'English',
app_version: '1.0',
sku: 'FastlaneScreencast_001',
skip_itc: true # this will only create the app in the iOS dev center
)
# Create distribution cert
cert
# Create/fetch provisioning profile
profile_uuid = sigh
# Delete iOS platform
FileUtils.rm_rf('../platforms/ios')
# Add iOS platform
sh "(cd .. && ionic cordova platform add ios)"
# Creating build.json folder to be used for release signing
# This will get placed in our platforms/ios directory
build_json = {
"ios": {
"release": {
"codeSignIdentity": "iPhone Distribution",
"provisioningProfile": "#{profile_uuid}",
"packageType": "app-store",
"developmentTeam": ENV["FASTLANE_TEAM_ID"]
}
}
}
# Writing build.json to platforms/ios directory
out_file = File.new("../platforms/ios/build.json", "w")
out_file.puts(JSON.generate(build_json))
out_file.close
# Build iOS release IPA
sh "(cd .. && ionic cordova build ios --device --prod --release --buildConfig=./platforms/ios/build.json)"
# Get IPA path
ipa_path = Dir.glob(File.join(Dir.pwd, "../platforms/ios/build/device/*.ipa")).first
ipa_path = File.absolute_path ipa_path
UI.success "Successfully built IPA: #{ipa_path}"
end
end
platform :android do
lane :build do
# fastlane plugin added by running `fastlane add_plugin android_keystore`
output_directory = android_keystore(generate_cordova_release_signing: true)
UI.user_error! "`android_keystore` directory needs to exists" unless File.directory?(output_directory)
# Delete platforms/android so we always start from scratch
FileUtils.rm_rf('../platforms/android')
# Add Android platform to Ionic project
sh "(cd .. && ionic cordova platform add android)"
# Copy contents of ".android_signing" to platforms/android
FileUtils.cp_r Dir.glob("#{output_directory}/*"), '../platforms/android'
# Build Android release APK
sh "(cd .. && ionic cordova build android --release)"
# Get APK path
apk_path = Dir.glob(File.join(Dir.pwd, "../platforms/android/build/outputs/apk/*-release.apk")).first
apk_path = File.absolute_path apk_path
UI.success "Successfully built APK: #{apk_path}"
end
end
platform :ios do
lane :build do
# Create app in the iOS dev center
produce(
app_name: 'FastlaneScreencast',
language: 'English',
app_version: '1.0',
sku: 'FastlaneScreencast_001',
skip_itc: true # this will only create the app in the iOS dev center
)
# Create distribution cert
cert
# Create/fetch provisioning profile
profile_uuid = sigh
# Delete iOS platform
FileUtils.rm_rf('../platforms/ios')
# Add iOS platform
sh "(cd .. && ionic cordova platform add ios)"
# Creating build.json folder to be used for release signing
# This will get placed in our platforms/ios directory
build_json = {
"ios": {
"release": {
"codeSignIdentity": "iPhone Distribution",
"provisioningProfile": "#{profile_uuid}",
"packageType": "app-store",
"developmentTeam": ENV["FASTLANE_TEAM_ID"]
}
}
}
# Writing build.json to platforms/ios directory
out_file = File.new("../platforms/ios/build.json", "w")
out_file.puts(JSON.generate(build_json))
out_file.close
# Build iOS release IPA
sh "(cd .. && ionic cordova build ios --device --prod --release --buildConfig=./platforms/ios/build.json)"
# Get IPA path
ipa_path = Dir.glob(File.join(Dir.pwd, "../platforms/ios/build/device/*.ipa")).first
ipa_path = File.absolute_path ipa_path
UI.success "Successfully built IPA: #{ipa_path}"
end
end
$: npm install cordova ionic
$: ionic start fastlaneScreencast
$: cd fastlaneScreencast
$: npm install --save-dev @ionic/cli-plugin-cordova
$: ionic serve
@bhavincb
Copy link

where do you put .env file?? what about project structure?

@laurentyhuel
Copy link

Hello @joshdholtz
Is it working with Ionic V4 project ?
Do you have a tutorial about this ?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment