一、读取properties数据
读取properties配置文件信息有两种方法:
1、写第一种方法的同时将自动化打包方法顺便写了,因为这俩可以共通
将密钥(appstore)相关信息写在程序自建的 gradle.properties 文件内
appstore密钥放置在程序的 app 文件夹下
变量前必须添加前缀,systemProp.
systemProp.releaseStoreFile = ../app/android.keystore systemProp.releaseStorePassword = android systemProp.releaseKeyAlias = android-alias systemProp.releaseKeyPassword = android
读取配置数据:
在 app 文件夹内 build.gradle 内 android {} 下加入 signingCofigs {}
但必须写在 buildTypes {} 前面
signingConfigs { appStrore { storeFile file(System.properties['releaseStoreFile']) storePassword System.properties['releaseStorePassword'] keyAlias System.properties['releaseKeyAlias'] keyPassword System.properties['releaseKeyPassword'] } }
从上面能看出来读取 gradle.properties 内数据的方式就是,获取到的是字符串:
System.properties['key']
然后再配置 buildType {}
buildTypes { release { signingConfig signingConfigs.appStrore }然后就可以直接动手打包了,打开Android Studio的Terminal根据自己想打的版本填写命令:gradlew assembleRelease或者 gradlew assembleDebugdebug { signingConfig signingConfigs.appStrore }}
相应的apk会出现在 app / build / output / apk
当然,release版本和debug版本不一定用同一套appstore,可以分别设置不同的密钥
2、第二种方法, local.properties 文件下或者自己建立一个xxxx .properties 配置文件写键值对都可以
ver