我使用Travis和Fastlane构建我的应用并将其发布到Google Play商店,但在同时处理多种口味时,供应无法找到要上传的APK。
这是我的快速文件:
fastlane_version "2.59.0"
default_platform :android
platform :android do
before_all do
gradle(task: "clean")
end
desc "Submit Whitelabels to Play Store"
lane :whitelabels_playstore do
gradle(
task: 'releaseWhitelabel'
)
lane_context[SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS].each do | apk |
puts "Uploading APK to Play Store: " + apk
begin
supply(
skip_upload_images: true,
skip_upload_screenshots: true,
validate_only: true,
apk: apk
)
rescue => ex
puts ex
end
end
end
end
任务releaseWhitelabel代码是:
def releaseTask = tasks.create(name: 'releaseWhitelabel') {
group 'Whitelabel'
description "Assembles and release all Whitelabels"
}
android.applicationVariants.all { variant ->
if (variant.buildType.name == 'release') {
variant.productFlavors.each { flavor ->
def flavorName = flavor.name.capitalize()
def releaseFlavorTaskName = "releaseWhitelabel${flavorName}"
def releaseFlavorTask
flavorsMap.each { name, jsonItem ->
if (flavorName.toUpperCase().startsWith(name.toUpperCase())) {
releaseFlavorTask = tasks.create(name: releaseFlavorTaskName) {
group 'Whitelabel'
description "Assembles and release build for flavor $flavorName"
}
releaseFlavorTask.dependsOn variant.assemble
releaseTask.dependsOn releaseFlavorTask
}
}
}
}
}
当我执行通道时,当本地运行时,任务完美运行,我收到一条错误消息,指出lane_context[SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS]
不能为nill。
当我运行以下gradle配置时,我工作正常,但只有一种味道可以通过这种方式发布,我的口味是动态生成的。
gradle(
task: 'assemble',
flavor: 'Dell',
build_type: 'Release'
)
如何使用每个apk构建的路径正确更新lane_context[SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS]
?
答案 0 :(得分:0)
我采用的方法是使用JSON文件控制所有白标,并从那里获取数据。
lane :whitelabels_playstore do
gradle(
task: "whitelabelRelease"
)
begin
# Retrieving Flavors from JSON file
require "json"
file = File.read "../buildsystem/whitelabels.json"
data = JSON.parse(file)
# Supply will deploy each flavor to Play Store
data['list'].each do | whitelabel |
begin
supply(
// application_id_suffix is provided by JSON file
package_name: "my.app.package.#{whitelabel['application_id_suffix']}",
skip_upload_images: true,
skip_upload_screenshots: true,
// flavor_nameis provided by JSON file
apk: "app/build/outputs/apk/app-#{whitelabel['flavor_name']}-release.apk"
)
rescue => ex
puts ex
slack(
message: "Error uploading => #{/([^\/]*)$/.match(apk)} #{get_version_name} - #{get_version_code}: #{ex}",
slack_url: "SLACK_HOOK_URL",
success: false,
default_payloads: [:git_branch, :lane, :test_result]
)
end
end
rescue => ex
puts ex
end
end