资源文件适配名称及apk签名配置

2018-05-30  本文已影响19人  3Q竹林
android{
signingConfigs {
   debug {
     storeFile file('../buildsystem/debug.keystore')
     storePassword 'android'
     keyAlias 'androiddebugkey'
     keyPassword 'android'
     v2SigningEnabled false
   }
   release {
     storeFile file('../buildsystem/release.jks')
     storePassword 'K684S6P'
     keyAlias 'cxtx'
     keyPassword '9qRdSEQZ'
     v2SigningEnabled false
   }
 }
}
signingConfigs {
    
    //debug签名
    debug {
        //签名秘钥库文件的存放的位置,这里使用的是相对路径
        storeFile file('sign/debug.keystore')
        
        //秘钥库的访问密码
        storePassword 'android'
        
        //别名,因为一个密码库可以供多个项目使用,所以别名不同,最后的签名也是不同的。
        keyAlias 'androidreleasekey'
        
        //别名的私钥密码
        keyPassword 'android'
    }
    
    release {
        storeFile file('sign/platform.keystore')
        storePassword 'android'
        keyAlias 'androidreleasekey'
        keyPassword 'android'
    }
}

在项目的根目录下添加一个keystore.properties文件。

//test
debugStoreFile=sign/debug.keystore
debugStorePassword=android
debugKeyAlias=androidreleasekey
debugKeyPassword=android

//release
releaseStoreFile=sign/platform.keystore
releaseStorePassword=android
releaseKeyAlias=androidreleasekey
releaseKeyPassword=android


在app模块的build.gradle中,解析这个文件

// Create a variable called keystorePropertiesFile, and initialize it to your
// keystore.properties file, in the rootProject folder.
def keystorePropertiesFile = rootProject.file("keystore.properties")

// Initialize a new Properties() object called keystoreProperties.
def keystoreProperties = new Properties()

// Load your keystore.properties file into the keystoreProperties object.
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android{
    .....
}

修改signConfigs闭包,引用文件中定义的属性

signingConfigs {
    debug {
        keyAlias keystoreProperties['debugKeyAlias']
        keyPassword keystoreProperties['debugKeyPassword']
        storeFile file(keystoreProperties['debugStoreFile'])
        storePassword keystoreProperties['debugStorePassword']
    }
    
    release{
        keyAlias keystoreProperties['releaseKeyAlias']
        keyPassword keystoreProperties['releaseKeyPassword']
        storeFile file(keystoreProperties['releaseStoreFile'])
        storePassword keystoreProperties['releaseStorePassword']
    }
}

详情网址:https://www.jianshu.com/p/ffcb7bba21a2

上一篇下一篇

猜你喜欢

热点阅读