My build gradle:
signingConfigs {
general {
keyAlias 'key'
keyPassword '123abc'
storeFile file('../store.jks')
storePassword '123abc'
}
lomza {
keyAlias 'key2'
keyPassword '123abc'
storeFile file('../store.jks')
storePassword '123abc'
}
}
So, there are 2 signing configs, each one is created and intended to use to its own build flavor. It works if I choose flavor and hit Shift+F10 (or push green arrow) - chosen build flavor will generate apk signed with correct key, as configured in build.gradle:
productFlavors {
general {
applicationId <id1>
signingConfig signingConfigs.general
}
lomza {
applicationId <id2>
signingConfig signingConfigs.key2
}
}
However, if I choose Build->Generate signed apk, I am forced to set only single keystore path. If I choose to build multiple flavors, all of them will be signed with the same key, chosen in first step in "Generate signed apk" window.
How to force "Build signed apk" to use respective signing config for each flavor to build, defined in build.gradle?
Related
I have build.gradle that can have signingConfigs, but I want TO ignore this setting and use other credentials. I don't want to edit or replace values in build.gradle.
Does gradle have same command like gradle assemble -storeFile='PATH' -storePassword='password' -keyAlias='alias' -keyPassword='password'?
If it's no way create signed apk with other signingConfigs, is it possible to create unsigned apk?
There is no gradle build command which takes sign configs.
You have two options based on the requirement you mentioned in your question.
1.Edit the build.gradle to create multiple build flavors and provide different signing details for each build flavor.
android {
signingConfigs {
abc {
keyAlias 'abc'
keyPassword 'yyy'
storeFile file('keystore/astro.keystore')
storePassword 'zzz'
}
xyz {
keyAlias 'xxx'
keyPassword 'xxx'
storeFile file('keystore/sample.keystore')
storePassword 'xxx'
}
//add another block for new customer
}}
Create multiple copies of keystore properties file with different signing config and when you want to use one particular copy of keystore.properties file, rename it to "keystore.properties".
def keystorePropertiesFile = rootProject.file("keystore.properties")
https://developer.android.com/studio/publish/app-signing#secure-shared-keystore
I suggest you using the solution reported by #Ranjan. It is the cleaner and a standard solution.
However if you would like to use the command line command, all properties passed to gradle in the command line via -P parameter are accessible in the project variable in your gradle script.
You can do something like that:
gradle assembleRelease -PmyKeyPassword='xxx' -PmyStorePassword='xxx' -PmyKeyAlias='xxx' -PmyStoreFile='...xxx.keystore'
and then define in your build.gradle.
signingConfigs {
release {
storeFile project.mystoreFile
storePassword project.myStorePassword
keyAlias project.myKeyAlias
keyPassword project.myKeyPassword
}
}
Pay attention because it can cause errors if you don't specify the keys in the gradle command (not so good in my point of view).
You can mitigate the issue doing a check on the parameter (using the project.hasProperty(xxx) method) and defining the default value in the build.gradle.
Something like that:
signingConfigs {
release {
storeFile project.hasProperty('myStoreFile') ? project.myStoreFile : 'default'
//..
}
}
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?
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
}
}
If you have provided keystore path and credentials in gradle. Then for generating signed apks follow this steps.
Go to Build Variants
Select build variants as release
Click the play/run button
Apk will be published in Project/build/outputs/apk folder
I am developing an app in such an android device that requires each app to be signed with a specific key, even the testing apk.
I know how to sign an app by configuring build.gradle. But signing testing app (Instrumentation test) seems no such configing, am I missing something ?
try this in build.gradle
signingConfigs {
release {
keyPassword 'your pw'
storeFile file('your keystore file path')
storePassword 'your pw'
keyAlias 'your alias'
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
debug {
minifyEnabled false
signingConfig signingConfigs.release
}
}
Thanks for NateZh and TWL.
Yes, the answer is to add flowing lines to build.gradle:
signingConfigs {
debug {
keyPassword 'your pw'
storeFile file('your keystore file path')
storePassword 'your pw'
keyAlias 'your alias'
}
}
But, there are more to be take care of:
When using signingConfigs.debug, this tells gradle it's debug key, no need to specific buildTypes.debug.signingConfig again
SigingConfigs.debug also take effect when building instrumentation test
In multi-modules project, if you want to test a module, you should include signingConfigs.debug in the module's build.gradle.
For example, my project looks like:
app
-build.gradle
libs
-src/androidTest/java/com/my/MyTest.java
-build.gradle
Adding signingConfigs.debug to app has no effect when I want to run libs' AndroidDebugTest. Instead, adding signingConfigs.debug to libs' build.gradle do the work.
Hope it's helpful to others.
My first Android project is finish. I want to load Google Play.
when I make build -> Generate Signed APK give error android studio.
For Gradle-based projects, the signing configuration should be
specified in the Gradle build scripts.See the Gradle User Guide for
more info."
I tried to sign configs as this sample
signingConfigs {
release {
storeFile file("mykeystore")
storePassword "mypassword"
keyAlias "my alias"
keyPassword "mykeypassword"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
But I dont know mykeystore and my password and other infos.
release {
storeFile file("mykeystore") -> what is mykeystore ?
storePassword "mypassword" -> what is mypassword ?
keyAlias "my alias" -> what is myalias ?
keyPassword "mykeypassword" -> what is mykeypassword ?
}
I cant build apk my project. This is my first project.
I use android studio 2.0.11 and mac os x lion.
Please help. Sorry bad english.
Thanks.
I have a big issue when I come to sign my application: I have set the signing configuration in accordance with the doc:
signingConfigs {
release {
storeFile file("lomapnew.keystore")
storePassword "myPassword"
keyAlias "myAlias"
keyPassword "Something...."
}
}
But I still get this error message: "The signing configuration should be specified in Gradle build scripts"
I'm going to go out on a limb and guess that you haven't set the signing configuration for the release build type. The debug build type is automatic, so it's not obvious that this is a necessary step for all other build types, including release.
You can apply the signing config like so:
android {
signingConfigs {
// It's not necessary to specify, but I like to keep the debug keystore
// in SCM so all our debug builds (on all workstations) use the same
// key for convenience
debug {
storeFile file("debug.keystore")
}
release {
storeFile file("release.keystore")
storePassword "myPassword"
keyAlias "myAlias"
keyPassword "Something...."
}
}
buildTypes {
/* This one happens automatically
debug {
signingConfig signingConfigs.debug
}
*/
release {
signingConfig signingConfigs.release
}
}
}
I like to keep passwords out of my build file. Hence I create a properties file that I load with
def keystorePropertiesFile = rootProject.file("./local.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
Then I define signingConfigs like so:
signingConfigs {
releaseSigning {
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['keystore.live.storepassword']
keyAlias = keystoreProperties['keystore.live.keyalias']
keyPassword = keystoreProperties['keystore.live.keypassword']
}
debugSigning {
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['keystore.debug.storepassword']
keyAlias = keystoreProperties['keystore.debug.keyalias']
keyPassword = keystoreProperties['keystore.debug.keypassword']
}
}
This doesn't work well with the menu option "create Signed apk" so I create flavors:
productFlavors {
mydebug {
signingConfig signingConfigs.debugSigning
}
myrelease {
signingConfig signingConfigs.releaseSigning
}
}
and now the signingconfigs work with the run button on the toolbar. For a default keystore the local.properties looks like
ndk.dir=/opt/sdk/ndk-bundle
sdk.dir=/opt/sdk
storeFile=/home/christine/.android/debug.keystore
keystore.debug.storepasswd=android
keystore.debug.keyalias=androiddebugkey
keystore.debug.keypassword=android
keystore.live.storepasswd=android
keystore.live.keyalias=androiddebugkey
keystore.livetest.keypassword=android
In your Jenkins build script, you need to create a symbolic link from local.properties to where the properties file is on your build server.
Answer is already given but i would like to highlight the other ways also,
We can specify the information manually like below where we have to specify full path to our keystore location like this
signingConfigs {
release {
storeFile file('O:/Android/Projects/yourKeyStore.jks')
storePassword "qwerty"
keyAlias "yourProjectKeyAlias"
keyPassword "ProjectKeyPassword"
}
}
This can also be specified in Signing Report if you go in
File-->Project Structure
Choose your project app module and select the signing report where you can fill up the information and it will automatically add previous release information in the gradle file.
Finally you just have to add
signingConfig android.signingConfigs.release
in the buildTypes {...} section. That will complete the signing procedure.