【问题标题】:Android flavors signing not working as expectedAndroid 风格签名未按预期工作
【发布时间】:2020-04-13 01:10:51
【问题描述】:

我需要使用特定的签名配置对产品风格进行签名。我在 stackoverflow 上找到了一些参考资料,例如 thisthis。它适用于我的版本版本,但不适用于调试版本。我在 gradle 中有这个配置:

...
signingConfigs {
    release {
        storeFile file("../config/keystores/release_keystore")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }

    debug {
        storeFile file("../config/keystores/debug.keystore")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }

    other {
        storeFile file("../config/keystores/other")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }
}

flavorDimensions "dim"

productFlavors {
    production {
        dimension "dim"
    }

    other {
        dimension "dim"
    }
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        
        productFlavors.other.signingConfig signingConfigs.other
        productFlavors.production.signingConfig signingConfigs.release
    }

    debug {
        productFlavors.other.signingConfig signingConfigs.other
        productFlavors.production.signingConfig signingConfigs.debug
    }
}

这很适合otherRelease 的味道。但是当我使用构建配置otherDebug 时,我的APK 没有使用other 签名配置签名。 release 版本已正确签名。

有谁知道为什么在调试模式下签名配置没有按照配置应用?

【问题讨论】:

  • “但它不适用于 otherDebug” 定义“它不起作用”是什么意思。
  • 抱歉,我想不清楚。正如我在productFlavors.other.signingConfig signingConfigs.other 中定义的那样,它没有使用我的other 签名配置进行签名。我会更新我的问题。
  • 它与哪个密钥库 签署?还是根本没有签名?
  • 有没有简单的方法来获取签名信息?我没有找到。我所做的是将我的密码更改为无效密码,因此release 版本因密码错误而中断,debug 组装了一个有效的 APK。我还在设备中安装了productionDebug,我可以将其替换为otherDebug,这意味着它们具有相同的签名信息(我没有收到任何关于签名差异的警告)。

标签: android gradle android-gradle-plugin build.gradle code-signing


【解决方案1】:

感谢@AllanHasegawa 在另一个问题中的评论:Signing product flavors with gradle,我终于弄清楚了哪里出了问题。简而言之,我不得不在buildTypes 中添加signingConfig null,因为Android 添加了一些默认的签名配置。即使我试图覆盖它。基于我的问题的完整示例:

...
signingConfigs {
    release {
        storeFile file("../config/keystores/release_keystore")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }

    debug {
        storeFile file("../config/keystores/debug.keystore")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }

    other {
        storeFile file("../config/keystores/other")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }
}

flavorDimensions "dim"

productFlavors {
    production {
        dimension "dim"
    }

    other {
        dimension "dim"
    }
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        // this loop is a better implementation than my previous example
        productFlavors.all { flavor ->
                flavor.signingConfig signingConfigs.release
        }        
        productFlavors.other.signingConfig signingConfigs.other
    }

    debug {
        signingConfig null
        // this loop is a better implementation than my previous example
        productFlavors.all { flavor ->
                flavor.signingConfig signingConfigs.debug
        }
        productFlavors.other.signingConfig signingConfigs.other
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-25
    • 1970-01-01
    相关资源
    最近更新 更多