I have been working on adding flavors to project and ran into below problem. Instead of adding the keystore path, alias and password, I added them in a .properties file and tried accessing them in build.gradle.
So this is how I did,
The project is in git, so other users also get my local path to .properties file path if I keep it in gradle.properties. For that reason I added the .properties path in local.properties. In build.gradle I'm reading the variable from local.properties and getting the each variables written in properties file.
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
}
}
}
}
}
Here, in the line properties.load(new FileInputStream(propFile)) it always throws
Malformed \uxxxx encoding.
I have tried,
Hard coding the path of
pro.propertiesinstead of taking fromlocal.propertiesTried as given in the following link
Also tried with changing the
forward-slash,backslashandescape-charcombinations
But nothing helped so far. Any help will be appreciated
In pro.properties file
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