android - 每个风格和构建类型的signingConfig 必须不同

标签 android gradle

我在同一个 Android Studio 项目中有两个不同的应用程序。我有两种 flavor 'flavor1' 和 'flavor2' 具有三种不同的构建类型 'staging'、'debug' 和 'release'

问题是我需要为每个应用程序使用不同的 keystore 。

现在我有了这个,但它只用同一个 keystore 签名。

signingConfigs {
    release {
        def Properties props = new Properties()
        def propFile = new File('./signing.properties')
        if (propFile.canRead()) {
            props.load(new FileInputStream(propFile))

            if (props != null && props.containsKey('STORE_FILE')
                    && props.containsKey('STORE_PASSWORD')
                    && props.containsKey('KEY_ALIAS')
                    && props.containsKey('KEY_PASSWORD')) {
                android.signingConfigs.release.storeFile = file(props.getProperty('STORE_FILE'))
                android.signingConfigs.release.storePassword = props.getProperty('STORE_PASSWORD')
                android.signingConfigs.release.keyAlias = props.getProperty('KEY_ALIAS')
                android.signingConfigs.release.keyPassword = props.getProperty('KEY_PASSWORD')
            } else {
                println 'signing.properties found but some entries are missing'
                android.buildTypes.release.signingConfig = null
            }
        } else {
            println 'signing.properties not found'
            android.buildTypes.release.signingConfig = null
        }
    }
} 

buildTypes {
    staging {
        debuggable true
        signingConfig android.signingConfigs.debug
    }
    debug {
        debuggable true
        signingConfig android.signingConfigs.debug
    }
    release {
        debuggable false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        signingConfig signingConfigs.release
        minifyEnabled false
    }
}

最佳答案

您可以创建特定于 flavor 的签名配置:

一个例子:

   signingConfigs {
        flavor1Release {
            storeFile file('home/keys/flavor1keystore.keystore')
            storePassword 'keystorePassword'
            keyAlias 'alias'
            keyPassword 'aliasPassword'
        }
        flavor2Release {
            storeFile file('home/keys/flavor2keystore.keystore')
            storePassword 'keystorePassword2'
            keyAlias 'alias2'
            keyPassword 'aliasPassword2'
        }
   }

然后按照您的喜好,选择正确的签名配置:
  productFlavors {
        def flavor1SigningVariable = signingConfigs.flavor1Release
        def flavor2SigningVariable = signingConfigs.flavor2Release

        flavor1 {
            signingConfig flavor1SigningVariable
        }
        flavor2 {
            signingConfig flavor2SigningVariable
        }
 }

关于android - 每个风格和构建类型的signingConfig 必须不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31295437/

相关文章:

使 imageView 圆形不起作用的 Android 代码

android - Listview 单击以在 ImageView 中显示图像

java - Activity 占用 140mb 内存

java - 无法连接到 selenium webdriver 中的主机 127.0.0.1 问题

android firebase 在 gradle 中添加依赖项时显示错误

android - Android-找不到* .apk

java - 为什么 gradle 初始化有时需要很长时间?

firebase - 进程异常: Process "...\gradlew.bat" exited abnormally: Starting a Gradle Daemon (subsequent builds will be faster)

gradle - Logback筛选器-限制性错误日志消息

eclipse - 如何使用Gradle构建Xtext Eclipse插件?