问题的关键在于,并非每个在此应用程序上工作的人都可以访问 storefile,并且必须按照以下方式注释掉这些行以进行 gradle 同步:

signingConfigs {
    release {
//        storeFile file('.../android_keystore.keystore')
//        storePassword RELEASE_STORE_PASSWORD
//        keyAlias RELEASE_KEY_ALIAS
//        keyPassword RELEASE_KEY_PASSWORD
    }
}

在我们的构建类型中,我们定义调试中没有signingconfig:
buildTypes{
     release {
          ...
     }
     debug {
          singingConfig null
          ...
     }
}

问题在于 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
}

其中 signing.properties 是:
STORE_FILE=/path/to/your.keystore
STORE_PASSWORD=yourkeystorepass
KEY_ALIAS=projectkeyalias
KEY_PASSWORD=keyaliaspassword

关于android - 在构建应用程序的调试版本时是否可以忽略 storeFile?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49053305/

10-14 12:23
查看更多