Last active
October 18, 2018 23:11
-
-
Save farwayer/64370e04808d53e7c19f0201a954d9b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
... | |
} | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment