Gradle Android Studio signing with properties file

I am trying to sign my application with gradle build file. When I use simple signConfigs, it works (signedConfigs.release)! But if I try to read the properties from the properties file, it will not work. (SigningConfigs.config)

Properties props = new Properties(); props.load(new FileInputStream(file(rootProject.file("signing.properties")))) android { signingConfigs { config { storeFile file(props["storeFile"]) storePassword props["storePassword"] keyAlias props["keyAlias"] keyPassword props["KeyPassword"] } release { storeFile file("..\\xyz.jks") storePassword "****" keyAlias "****" keyPassword "****" } } . . . buildTypes { release { runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' signingConfig signingConfigs.release } debug { applicationIdSuffix '.debug' versionNameSuffix '-SNAPSHOT' } } 

Property File:

 storeFile=xyz.jks storePassword=xyz keyAlias=xyz keyPassword=xyz 

When I start the project, Android studios show a dialog saying:

xyz.apk is not signed. Configure the subscription data for the selected flavor using the "Project Structure" dialog.

The property file is read correctly, because I can register some properties from the file by dropping the console.

Some of my system details:

Android Studio 0.8.6 Windows 8.1 x64 gradle 1.12

Hope someone can help me. If you want to know more details, ask me.

+5
source share
4 answers

This is what I do and it works for me:

 signingConfigs { release { def Properties localProps = new Properties() localProps.load(new FileInputStream(file('../local.properties'))) def Properties keyProps = new Properties() assert localProps['keystore.props.file']; keyProps.load(new FileInputStream(file(localProps['keystore.props.file']))) storeFile file(keyProps["store"]) keyAlias keyProps["alias"] storePassword keyProps["storePass"] keyPassword keyProps["pass"] } } 

The local.properties file contains the path to the keystore.properties file. This contains my key store information:

 store=*** alias=*** pass=*** storePass=*** 

It might be redundant to download two Propreties files, but it works for me.

+9
source

I found a mistake !!! The problem was case sensitive! I write

keyPassword props ["KeyPassword"]

but the file contains only

keyPassword

Why doesn't gradle tell me?

0
source

Here is the complete step by step that I used to use the properties file to move both of my keys from the gradle.build file to a file that will not be included in any assemblies or repository.

1) Create gradle.properties (if you don't already have one).

The location for this file depends on your OS:

  /home/<username>/.gradle/ (Linux) /Users/<username>/.gradle/ (Mac) C:\Users\<username>\.gradle (Windows) 

2) Add an entry pointing to yourprojectname.properties file. (example for Windows)

 yourprojectname.properties=c:\\Users\\<username>\\signing\\yourprojectname.properties 

3) Create yourprojectname.properties file in the location specified in step 2 with the following information:

 keystore=C:\\path\\to\\keystore\\yourapps.keystore keystore.password=your_secret_password 

4) Modify the gradle.build file to point to yourprojectname.properties file to use the variables.

 if(project.hasProperty("yourprojectname.properties") && new File(project.property("yourprojectname.properties")).exists()) { Properties props = new Properties() props.load(new FileInputStream(file(project.property("yourprojectname.properties")))) android { signingConfigs { release { keyAlias 'release' keyPassword props['keystore.password'] storeFile file(props['keystore']) storePassword props['keystore.password'] } debug { keyAlias 'debug' keyPassword props['keystore.password'] storeFile file(props['keystore']) storePassword props['keystore.password'] } } compileSdkVersion 19 buildToolsVersion "20.0.0" defaultConfig { applicationId "your.project.app" minSdkVersion 16 targetSdkVersion 17 } buildTypes { release { } } } } dependencies { ... } 

5) Enjoy! Now all your keys will be outside the root of the directory, and yet you still have the joys of automation for each assembly.

If you get an error in the gradle.build file about the "requisite" variable, because you are not executing the "android {}" block in the very first if state, where the props variable gets so just move the entire android section {...} to the condition, in which the attribute variable is assigned, then try again.

I gathered these steps together from the information I found here and here .

0
source

An alternative to juggling variables is to include / use the gradle file containing the signing config.

So in your build.gradle

 android { // the part to include if (project.hasProperty("yourproject.signing") && new File(project.property("yourproject.signing")).exists()) { println 'apply yourproject signing property'; apply from: project.property("yourproject.signing"); } else { println 'no yourproject signing property'; } // the rest of the usual stuff compileSdkVersion etc. 

In your .gradle directory (depending on your OS where it is) add the gradle.properties file or if it exists add the following line

 yourproject.signing=*the full path to your magic file*signing.gradle 

In the file pointed to by the above record, you include the signing config, as in the build.gradle file

 android { signingConfigs { release { keyAlias '*your release key alias*' keyPassword '*your key password*' storeFile file('*the full path to your keystore file*.jks') storePassword '*your keystore password*' } } } 

Yes, additional android packaging should be there. The advantage is that the above is a normal gradle file, so you can do all the magic you want there.

Add additional signature parameters if necessary, use the usual method, for example.

 signingConfig signingConfigs.release 
0
source

Source: https://habr.com/ru/post/1200328/


All Articles