Skip to content

Instantly share code, notes, and snippets.

@farwayer
Last active October 18, 2018 23:11
Show Gist options
  • Save farwayer/64370e04808d53e7c19f0201a954d9b0 to your computer and use it in GitHub Desktop.
Save farwayer/64370e04808d53e7c19f0201a954d9b0 to your computer and use it in GitHub Desktop.
def getVersionCode = { ->
def code = project.hasProperty('versionCode') ? versionCode.toInteger() : 9999999
println "versionCode is $code"
return code
}
def getCodePushKey = { ->
def key = project.hasProperty('codePushKey') ? codePushKey : ""
println "codePushKey is $key"
return "\"${key}\""
}
android {
...
defaultConfig {
...
versionCode getVersionCode()
...
}
buildTypes {
debug {
buildConfigField "String", "CODEPUSH_KEY", '""'
}
release {
buildConfigField "String", "CODEPUSH_KEY", getCodePushKey()
...
}
}
...
def normalize_path(path)
File.expand_path(path, '..')
end
def read_file(path)
unless File.file?(path)
puts "You must provide '#{path}' file"
exit 1
end
File.read(path)
end
def write_file(path, data)
File.write(path, data)
end
def get_version(path)
path = normalize_path(path)
version = read_file(path).to_i
version = version + 1
write_file(path, version)
version
end
def check_keystore(path)
path = normalize_path(path)
unless File.file?(path)
puts "You must provide '#{path}' keystore file for release or next version"
exit 1
end
end
version_file = 'fastlane/version'
keystore_file = 'fastlane/release.jks'
platform :android do
private_lane :build do |options|
version_code = get_version(version_file)
check_keystore(keystore_file)
gradle(
task: 'clean',
project_dir: 'android'
)
gradle(
project_dir: 'android',
properties: {
versionCode: version_code,
codePushKey: options[:codePushKey]
},
**options[:gradle]
)
end
desc 'Build release version'
lane :build_release do |options|
build(
gradle: {task: 'assemble', build_type: 'Release'},
**options
)
sign_apk(
keystore_path: keystore_file,
alias: 'release',
tsa: 'http://timestamp.digicert.com',
**keystore_keys
)
zipalign(apk_path: lane_context[SharedValues::SIGNED_APK_PATH])
end
desc 'Upload Google Play release'
lane :release do
build_release(codePushKey: push_code_keys['android']['release'])
supply(
apk: lane_context[SharedValues::SIGNED_APK_PATH],
)
end
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment