I'm developing some applications that need system UID. So I made a special keystore file "PFDebug.keystore" made from AOSP's platform.pk8 and platform.x509.pem.
I set it in Eclipse >window >preferences >android >build >cutstom debug keystore. That works fine.
But I am also developing non-privileged applications that use my own debug.keystore file. So I have to change keystore file for each build. I know that default debug.keystore is used when I set blank.
How can I bind debug keystore files for each android project?
It's doable with gradle.
For each project you have a build.gradle in which you can specify a signingConfig. Like that :
signingConfigs {
debug {
storeFile file("../debug.keystore")
}
release {
storeFile file("../prod.keystore")
storePassword 'prod'
keyAlias 'prod'
keyPassword 'prod'
}
}
Related
in android studio 2 you can save key store password and key password but in android studio 3 you can just save key password and you have to write key store password every time you want to build apk is there a settings or way to save key store password in android studio 3?
I Know I can save the password in my build.gradle file but I don't want to password be saved on git.
I am having the same issue. But you can add your signing configs this way so they won't be checked into version control:
Put this into ~/.gradle/gradle.properties
RELEASE_STORE_FILE={path to your keystore}
RELEASE_STORE_PASSWORD=*****
RELEASE_KEY_ALIAS=*****
RELEASE_KEY_PASSWORD=*****
Modify your build.gradle like this:
...
signingConfigs {
release {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
Source: How to create a release signed apk file using Gradle?
It seems to be a bug.
On Mac you can fix this by manually adding a Keychain Access entry:
I used android studio to generate sign APK (build->generate sign APK).
both V1 and V2 checkboxes were marked in the signature version.
To upload an APK via CI-CD, I am running assemleRelease cmd.
The problem is that the sign from assembleRelease is different (probably it's signed with V1 only).
How can I run assembleRelease to sign with the same signature as android studio (build->generate sign APK)?
my code:
android {
signingConfigs {
release {
storeFile file('../config/xx.jks')
Properties props = new Properties()
props.load(new FileInputStream(file("../local.properties")))
storePassword "password"
keyAlias "my-alias"
keyPassword "password"
v2SigningEnabled true
}
debug {
storeFile file("../Config/xx.keystore")
}
}
My mistake, The path from the studio linked to another key-store file (not the one the "storeFile file('../config/xx.jks')" linked to..
I am trying implement In-App billing in my Androd app and when I test the purchase functionality I get the error "This version of the application is not configured for billing through Google Play."
I suspect that I did not properly generate a signed APK and that the problem is with my buil.gradle file.
I genereated a keystore by following the instructions here and generated .jks. My question is what exactly do I put for the storeFile file() in signingConfigs?
The following example is from the Android docs:
signingConfigs {
release {
storeFile file("myreleasekey.keystore")
storePassword "password"
keyAlias "MyReleaseKey"
keyPassword "password"
}
}
Simply putting the path to my .jks file didn't work. Is a .jks file different than a .keystore file? If so, how do I genereate a .keystore?
UPDATE
I learned that the .keystore and .jks are arbitrary file extensions from this answer.
My plan is to simply copy the my keystore.jks file in to the app directory then add the tag as follows:
storeFile file("keystore.jks")
Is this correct? Unfortunately it will take a few hours for the apk to be published by Google Play so I can't get a quick answer on this.
I solved the problem. The key was to choose the app directory as the key store path.
Here are detailed instructions on how I generated a signed apk in Android Studio:
Go to Build->Generate Signed apk
Select the app module, click next.
Under Key store path, click create new.
The following window will pop up.
Select your app directory for the keystore path. It will create a keystore with default name "keystore.jks". You can change it if you like.
Enter a password for the keystore. We will call it "StorePassword"
Enter a Key Alias (let's call it "KeyAlias") and a Key password (let's call it "KeyPassword")
In the build.gradle file add the following:
Example Signing config:
signingConfigs {
release {
storeFile file("keystore.jks")
storePassword "StorePassword"
keyAlias "KeyAlias"
keyPassword "KeyPassword"
}
}
Continue through the Generate Signed apk Wizard and enter in the appropriate passwords and generate the apk. The key is to make sure that the build.gradle is updated in the final signed apk.
To confirm that you successfully signed the .apk see this question.
And of course, have secure backups and be extremely protective of the keystore once it is genereated.
keytool -genkey -v -keystore name_of_your_file.keystore -alias your_alias -keyalg RSA -keysize 2048 -validity 10000
This is command will generate new keys
change name_of_your_file for your name
and your_alias for your alias
the keystore will be generated in folder where you call this
Then add this to your build.gradle
signingConfigs {
config {
storeFile file("${rootDir}/name_of_your_file.keystore")
storePassword "qwerty"
keyAlias "your_alias"
keyPassword "qwerty"
}
}
buildTypes {
release {
signingConfig android.signingConfigs.config
}
}
but change qwerty to your password
and your_alias to your alias name which you use when you generate keystore
and name_of_your_file to name of your kestore
clean your project and run ./gradlew task assembleRelease
In Android Studio go to Build->Generate Signed apk and follow steps. You don't need to add signingConfigsin build.gradle At least on current android studio version which is 1.3.2
I've been developing my project in Eclipse IDE. The app is submitted on Play Store, and I've published a couple of versions updates successfully.
Recently I've migrated to Android Studio (and gradle, of course). I've done some changes to the project code base, including min and target sdk changes, but package name remains the same. The project is successfully compiled and debug app is successfully assembled and running ok.
But now I can not assemble a release version because of :
Keystore was tampered with, or password was incorrect
The keystore have not changed, and I do know it's password.
I've set signingconfigs in build.gradle:
android {
...
signingConfigs {
release {
storeFile file("keystore/motolife.keystore")
storePassword "***"
keyAlias "motolife"
keyPassword "***"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
...
}
I've tried also to sign using jarsigner:
jarsigner -verbose -keystore keystore/motolife.keystore build/outputs/apk/motolife-new-debug.apk motolife
But no luck.
I've even installed gradle support for Eclipse and tried to assemble signed release app , but got the same "Keystore was tampered with, or password was incorrect" error.
try doing something like this then:
release {
storeFile file("keystoreName.keystore") //change value per signing
def pass = System.console().readPassword("\nPlease enter key password: ")
pass = new String(pass)
storePassword pass
keyAlias "revision3" //need to change these values per signing
keyPassword pass
}
As I am working with Google Maps API, I have been used to work with a custom debug key in Eclipse (that is in fact my production key)
This manipulation allowed me to use the same API key for Maps and most of Google Play Services (in app billing) in my debug and release build.
This was really convenient because there was no need to change the key in the manifest.
Unfortunately, with the migration to Android Studio, I am missing this feature.
Any idea where I can find this option back?
Thank a lot.
You define a keystore in your build.gradle file. See the Signing Configurations section here: https://developer.android.com/studio/build/index.html
In your case, you want to redefine the keystore for the debug variant:
android {
signingConfigs {
debug {
storeFile file("your.keystore")
}
}
}
However, you should really be using two different keystores for debug and release configurations.
On recent Android Studio 0.8.9 you will find this at a way better place:
File->Project Structure
Add a keystore at "Signing" Tab
Select it for your debug/release "Build types".
Make sure the alias name matchs with your keystore (keytool -list -v shows your alias name)
It creates the gradle stuff, syncrhonizes automatically on "Apply" and worked immediately like a charm.
Hi If you don't want to go for hard code all of this stuff , then go for below easy steps
->Your project
->Your Module
->Right click on your module
->go to open module settings
->Go to Signing section
->Specify all the attribute here and browse your Custom debug key in Store File
Then you will find below code which will be auto-create by android studio in build.gradle
signingConfigs {
debug {
storeFile file('custom_debug_keystore')
keyAlias 'androiddebugkey'
keyPassword 'android'
storePassword 'android'
}
}
Note:
1) Please do not use .keystore in the code manually you go for manual configuration
2) Please specify correct Alias and password
Here is a complete step-by-step that I took to move both of my keys out of the gradle.build file into a file that will not be included in any builds or repository commits.
1) Create a 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 you specified in Step 2 with the following information:
keystore=C:\\path\\to\\keystore\\yourapps.keystore
keystore.password=your_secret_password
4) Modify your 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 of your keys will be outside of the root of the directory and yet you still have the joys of automation for each build.
If you get an error in your gradle.build file about the "props" variable it's because you are not executing the "android {}" block inside the very first if condition where the props variable gets assigned so just move the entire android{ ... } section into the condition in which the props variable is assigned then try again.
I pieced these steps together from the information found here and here.
You can specify the debug.keystore for your project independently.
Two steps with the following images: (Android Studio v0.5.2)
Step 1: Click the button of project structure.
Step 2: Add the debug.keystore as follows.
The keystore needs to be in build.gradle, example follows:
android{
signingConfigs {
release {
storeFile file('/path/platform.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
...
buildTypes {
release {
signingConfig signingConfigs.release
}
}
Eclipse didn't really ask for a password or alias, but gradle does. I believe Eclipse just assumed it was password:android and alias:androiddebugkey. This might not be true for your keystore but I would try it like that on gradle.
If you know the password, but you are not sure of the alias you can also run the following command to get the alias:
keytool -list -keystore /path/platform.keystore link
As pointed out, you can use the gradle file to specify it.
I also found very convenient to use the Home folder as part of the path. It makes it easier when working within a team. Here is my suggestion :
android {
signingConfigs {
debug {
storeFile file(System.properties['user.home']+"/.android/custom.debug.keystore")
}
}
}