3

First of all here goes my signinConfigs:

signingConfigs {
        development {
            storeFile file("mykey.jks") //Path to the keystore file
            keyAlias "mykey"
            storePassword "mykeydev"
            keyPassword "mykeydev"
        }
        production {
            storeFile file("mykey.jks") //Path to the keystore file
            keyAlias "mykey"
            storePassword "mykeyprod"
            keyPassword "mykeyprod"
        }
}

And now my flavors:

productFlavors {
    development{
        applicationId "br.com.myapp.dev"
        signingConfig signingConfigs.development
        resValue "string", "app_name", "DEV"
    }

    production {
        applicationId "br.com.myapp"
        signingConfig signingConfigs.production
        resValue "string", "app_name", "PROD"
    }
}

I have under by buildTypes this:

buildTypes {
    release {
        minifyEnabled false
        productFlavors.production.signingConfig signingConfigs.production
        productFlavors.development.signingConfig signingConfigs.development
    }
}

And here goes my question, Why am I asked for keyPassword and storePassword every time i want to generate a new signed apk file, if all keys and stuff are inside my .gradle file?

guisantogui
  • 4,017
  • 9
  • 49
  • 93

2 Answers2

2

If you have provided keystore path and credentials in gradle. Then for generating signed apks follow this steps.

  1. Go to Build Variants
  2. Select build variants as release
  3. Click the play/run button

Apk will be published in Project/build/outputs/apk folder

abhishesh
  • 3,246
  • 18
  • 20
2

When you build from the "Build -> Generate Signed apk" you'll need to enter Android's studio password once in a while, but it saves the passwords encrypted for you. This is the safest way to go.

But since you need an automated way, you can use the "Terminal" view, and type: ./gradlew assembleRelease. (If you're in a windows machine I think it's gradlew assembleRelease).

In any case, it's not advisable to write your password inside the build.gradle file:

android {

  signingConfigs {
    release {
        storeFile file('/your/keystore/location/key')
        keyAlias 'your_alias'
        keyPasswordString ps = System.getenv("ps")
        storePasswordif System.getenv("ps"ps == null) {
             throw new GradleException('missing ps env variable')
        }
        keyPassword ps
        storePassword ps
    }
}
Graham
  • 7,431
  • 18
  • 59
  • 84
Amir Uval
  • 14,425
  • 4
  • 50
  • 74