gpt4 book ai didi

android - 用于多项目构建的全局签名配置

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:08:39 24 4
gpt4 key购买 nike

我正在使用这样的项目结构:

root
|--build.gradle
|--settings.gradle
|
|--child1
| |--build.gradle
|
|--child2
|--build.gradle

在两个子项目中,build.gradle 包含以下内容:

apply plugin: 'android'

...

android {
...

signingConfigs {
release {
storeFile file("release.keystore")
storePassword "pass"
keyAlias "alias"
keyPassword "pass"
}
}

buildTypes {
release {
signingConfig signingConfigs.release
}
}
...
}

如何将 signingConfigs 部分移动到根项目以减少代码重复?

最佳答案

我已经尝试过这段代码并且它有效。请注意不要在 android-library 项目中使用 signingConfigs。

subprojects {

afterEvaluate {
def isAndroidProject = project.plugins.hasPlugin('android')
def isLibraryProject = project.plugins.hasPlugin('android-library')
if (isAndroidProject || isLibraryProject) {
android {
compileSdkVersion 19
buildToolsVersion 19.0.1

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

if (isAndroidProject) {
signingConfigs {
release {
storeFile file("${rootDir}/platform.keystore")
storePassword "android"
keyAlias "platform"
keyPassword "android"
}
}

buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), "${project.projectDir}/proguard-project.txt"
}
}

android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def buildType = variant.buildType.name
if (buildType.equals('release')) {
def fileName = "${project.name}.apk";
output.outputFile = new File(output.outputFile.parent, fileName)

output.assemble.doLast {
copy {
from output.outputFile.getAbsolutePath()
into "../apks/"
}
}
}
}
}
}
}
}
}

关于android - 用于多项目构建的全局签名配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20731783/

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