Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Android Studio signing with a properties file

I´m trying to sign my app with the gradle build file. When I use the plain signingConfigs it works (signingConfigs.release)! But If I´m trying to read the properties from the properties-file it won´t 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'
            }
        }

Properties file:

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

When I run the project, android studios show a dialog which says:

xyz.apk is not signed. Please configure the signing information for the selected flavor using the Project Structure dialog.

The property file is read correctly because I can log some properties from the file throw the console.

Some of my system details:

Android Studio 0.8.6 Windows 8.1 x64 gradle 1.12

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

like image 350
Adam Avatar asked Aug 14 '14 14:08

Adam


People also ask

What is Gradle properties file in Android?

Gradle properties file in an Android project structure view. By default, Gradle uses a file called gradle. properties in the root directory for Android Projects. This extension file is widely used in Java projects, so it is also used for Android projects. The file has a simple key — value data structure.

How do I add properties in build Gradle?

Project properties You can add properties directly to your Project object via the -P command line option. Gradle can also set project properties when it sees specially-named system properties or environment variables.

Where is Gradle properties file in Android Studio?

In the Project window, right click your Project name and choose New > File. The new file name is "gradle. properties".


1 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"]
    }
}

My local.properties file contains a path to a "keystore.properties" file. That contains my info about the keystore:

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

Perhaps the loading of two Propreties file is redundant, but it does work for me.

like image 118
ariets Avatar answered Oct 25 '22 00:10

ariets