gpt4 book ai didi

android - 如何使用自定义 gradle 任务一次构建多个 apk?

转载 作者:行者123 更新时间:2023-11-29 02:30:55 33 4
gpt4 key购买 nike

我正在努力寻找一种使用 gradle 一次构建多个 apk 的方法。

我想要一个自定义 gradle 任务,它只考虑带有 enviroment = "production" 的变体和所有品牌,但nonPublishedBrandbuildtype = "release" (见下面的代码)。

对于每个变体,我需要:

  1. 生成签名的apk

  2. 使用相关任务将 prodguard 映射上传到 bugsnag uploadBugsnag${variant.name}-releaseMapping

  3. 将 apk 重命名为 <brand>-<version>.apk并将其移至公共(public)文件夹 $buildDir/myApks

我只找到了一种方法来让组装任务也运行我的自定义任务,但这并不理想,因为我不想在每次构建生产版本变体时上传映射,但只有在它意味着启动特定的 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
}
}

最佳答案

circle.ci is an efficient way to generate builds with each commit.
Documentation : 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

assemblePreassembleRelease 是在上述情况下执行的任务。您可以尝试在此处编写自定义任务。

关于android - 如何使用自定义 gradle 任务一次构建多个 apk?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49654628/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com