我正在努力寻找一种方法,用gradle一次构建几个apk。
我想要一个自定义gradle任务,该任务仅考虑enviroment = "production"
的变体以及nonPublishedBrand
和buildtype = "release"
以外的所有品牌(参见下面的代码)。
对于我需要的每个变种:
生成签名的apk
使用相对任务uploadBugsnag${variant.name}-releaseMapping
将apk重命名为<brand>-<version>.apk
并将其移至公共文件夹$buildDir/myApks
我只找到了一种方法来使汇编任务也运行我的自定义任务,但这并不理想,因为我不想在每次构建生产版本变体时上传映射,但仅限于#&# 39; s意味着启动特定的gradle任务。
有可能用gradle实现吗?你能指点我正确的方向吗?
请参阅我的build.gradle android部分以供参考:
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 15
targetSdkVersion 27
versionCode 1000000
versionName "1.0.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
storeFile file("keystore/keystore")
storePassword '*******'
keyAlias '*******'
keyPassword '*******'
}
}
buildTypes {
debug {
applicationIdSuffix ".debug"
versionNameSuffix ".debug"
manifestPlaceholders = [buildTypePrefix: "D_"]
}
release {
debuggable false
signingConfig signingConfigs.release
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
manifestPlaceholders = [buildTypePrefix: ""]
}
}
flavorDimensions "environment", "brand"
productFlavors {
//ENVIRONMENTS
staging {
dimension "environment"
applicationIdSuffix ".staging"
versionNameSuffix ".staging"
buildConfigField("String", "BASE_URL", "\"http://baseurl-staging.com\"")
manifestPlaceholders = [environmentPrefix: "S_"]
}
production {
dimension "environment"
buildConfigField("String", "BASE_URL"l, "\"http://baseurl-prod.com\"")
manifestPlaceholders = [environmentPrefix: ""]
}
//BRANDS
nonPublishedBrand {
dimension "brand"
applicationId "${packageBaseName}.nonpublishedbrand"
manifestPlaceholders = [appName: "Non published brand"]
ext {
facebook_app_id = [
staging: "0000000",
prod : "11111111"
]
}
}
brand1 {
dimension "brand"
applicationId "${packageBaseName}.brand1"
manifestPlaceholders = [appName: "Brand 1"]
ext {
facebook_app_id = [
staging: "22222222",
prod : "33333333"
]
}
}
brand2 {
dimension "brand"
applicationId "${packageBaseName}.brand2"
manifestPlaceholders = [appName: "Brand 2"]
ext {
facebook_app_id = [
staging: "44444444",
prod : "555555555"
]
}
}
}
productFlavors {
applicationVariants.all { variant ->
def isDebug = false
if (variant.buildType.name == "debug") {
isDebug = true
}
def isStaging = false
def flavors = variant.productFlavors
def environment = flavors[0]
if (environment.name == "staging") {
isStaging = true
}
def facebookAppId = ""
if (isStaging){
facebookAppId = flavors[1].facebook_app_id.staging
}else{
facebookAppId = flavors[1].facebook_app_id.prod
}
variant.buildConfigField "String", "FACEBOOK_APP_ID", "\"${facebookAppId}\""
}
}
dataBinding {
enabled = true
}
bugsnag {
autoUpload false
}
}
答案 0 :(得分:0)
circle.ci 是每次提交生成构建的有效方式。
文档:https://circleci.com/docs/2.0/
你的circle.yml文件会是这样的:
override:
- ./gradlew clean :mobile:assemblePre -PdisablePreDex -Pandroid.threadPoolSize=1 -Dorg.gradle.parallel=false -Dorg.gradle.jvmargs="-Xms2048m -Xmx4608m"
- cp -r ~ build/outputs/apk/build/pre/*.apk $CIRCLE_ARTIFACTS
- ./gradlew clean :mobile:assembleRelease -PdisablePreDex -Pandroid.threadPoolSize=1 -Dorg.gradle.parallel=false -Dorg.gradle.jvmargs="-Xms2048m -Xmx4608m"
- cp -r ~build/outputs/apk/build/release/*.apk $CIRCLE_ARTIFACTS
assemblePre 和 assembleRelease 是在上述情况下执行的任务。您可以尝试在此处编写自定义任务。