Boo*_*ese 3 android gradle build.gradle
问题的关键在于,并非每个在此应用程序上工作的人都可以访问 storefile,并且必须按照以下方式注释掉这些行以进行 gradle 同步:
signingConfigs {
release {
// storeFile file('.../android_keystore.keystore')
// storePassword RELEASE_STORE_PASSWORD
// keyAlias RELEASE_KEY_ALIAS
// keyPassword RELEASE_KEY_PASSWORD
}
}
Run Code Online (Sandbox Code Playgroud)
在我们的构建类型中,我们定义调试中没有signingconfig:
buildTypes{
release {
...
}
debug {
singingConfig null
...
}
}
Run Code Online (Sandbox Code Playgroud)
问题在于 Gradle Syncs 与构建类型无关,因此它每次都会检查签名配置(storePassword、keyAlias、keyPassword),除非我将这些行注释掉。
有没有更自动化的方法来忽略这些行?
你可以使用这样的东西:
android {
signingConfigs {
release
}
buildTypes {
release {
signingConfig 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['STORE_FILE'])
android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
android.signingConfigs.release.keyPassword = props['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
}
Run Code Online (Sandbox Code Playgroud)
在哪里signing.properties:
STORE_FILE=/path/to/your.keystore
STORE_PASSWORD=yourkeystorepass
KEY_ALIAS=projectkeyalias
KEY_PASSWORD=keyaliaspassword
Run Code Online (Sandbox Code Playgroud)
将 @Gabriele 的答案标记为答案,因为它更完整、更正确,但想发布有关我的最终(简单且简单)解决方案的更新,如果没有他的答案,我就无法弄清楚;
我所要做的就是检查该文件是否存在。我没有意识到我可以在 Gradle 文件中调用方法并使用 if 语句;
signingConfigs {
release {
storeFile file('.../android_keystore.keystore')
if (storeFile.exists()) {
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
441 次 |
| 最近记录: |