我一直致力于为项目添加口味并遇到以下问题。我没有添加keystore
路径,别名和密码,而是将其添加到.properties
文件中,并尝试在build.gradle
中访问它们。
这就是我的做法,
该项目是git,因此如果我将其保存在.properties
中,其他用户也会获得gradle.properties
文件路径的本地路径。出于这个原因,我在.properties
中添加了local.properties
路径。在build.gradle
我从local.properties
读取变量并将每个变量写入属性文件中。
local.properties
variable.prop=C\:\\Users\\user\\signing\\project\\pro.properties
的build.gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.neenbedankt.android-apt'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
def versionMajor = 1
def versionMinor = 0
def versionPatch = 1
def versionBuild = 1
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
Properties props = new Properties()
props.load(project.rootProject.file('local.properties').newDataInputStream())
def localPropertiesPath = props.getProperty('variable.prop', null);
if (localPropertiesPath == null)
throw new GradleException("Unable to find properties file. Variable might not be added in local.properties or file may not exist in given path")
else {
def propFile = file(localPropertiesPath)
if (propFile.canRead()) {
Properties properties = new Properties()
properties.load(new FileInputStream(propFile))
signingConfigs {
uat {
storeFile file(properties['uatKeystorePath'])
keyAlias properties['uatKeyAlias']
keyPassword properties['uatKeyPassword']
storePassword properties['uatStorePassword']
}
release {
storeFile file(properties['releaseKeystorePath'])
keyAlias properties['releaseKeyAlias']
keyPassword properties['releaseKeyPassword']
storePassword properties['releaseStorePassword']
}
}
defaultConfig {
applicationId "com.package.name"
minSdkVersion 15
targetSdkVersion 23
versionCode versionMajor * 1000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
setMultiDexEnabled true
}
dexOptions {
javaMaxHeapSize "2048M"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfig.release
}
}
}
}
}
此处,在行properties.load(new FileInputStream(propFile))
中,它始终抛出
Malformed \uxxxx encoding.
我试过了,
对pro.properties
的路径进行硬编码,而非取自local.properties
尝试以下link
还尝试更改forward-slash
,backslash
和escape-char
组合
但到目前为止没有任何帮助。任何帮助将不胜感激
在 pro.properties 文件
中uatKeystorePath=C:\Users\user\.signing\project\uat_keystore.jks
uatStorePassword=StorePassword
uatKeyAlias=AliasName
uatKeyPassword=KeyPassword
releaseKeystorePath=C:\Users\user\.signing\project\release_keystore.jks
releaseStorePassword=StorePassword
releaseKeyAlias=AliasName
releaseKeyPassword=KeyPassword
答案 0 :(得分:0)
我无法发表评论,所以我必须回答,但我只是想问你,如果你的真实档案中有与你的问题相同的拼写错误?
variable.prop=C\:\\Users\\user\\signing\\project\\pro.properties
我的意思是C
和: