Android Studio 0.4.+ custom debug keystore - android

Prior to Android Studio 0.4, I was able to set a custom debug keystore via
File -> Project Structure -> Facets -> Compiler Tab
This option has gone at least with Android Studio 0.4.2. Where can I set the custom keystore for being able to share it over different PCs, e.g. via a VCS?

This can be solved by adding signingConfigs to the build.gradle configuration.
android {
// ...
signingConfigs {
debug {
storeFile file('../debug.keystore')
}
/*
release {
storeFile file('release.keystore')
storePassword "mystorepassword"
keyAlias "mykeyalias"
keyPassword "mykeypassword"
}
*/
}

You can do the same using signingConfigs in build.gradle file and putting certificates in project directory
Step 1. Create a directory inside you module like
--YourProject
--your_module
--KeystoreCertificates
--myCertificates
--other_certificates
build.gradle file inside your_module dir
android {
signingConfigs {
myCustomDebug {
storeFile file("KeystoreCertificates/myCertificates")
storePassword "certi_password"
keyAlias "certi_alias"
keyPassword "alias_password"
}
}
buildTypes {
debug {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.myCustomDebug
}
}

Related

How to use V1 (Jar signature) or V2 (Full APK signature) from build.gradle file

I have this in my gradle file:
android {
signingConfigs {
mySigningConfig {
keyAlias 'theAlias'
keyPassword 'thePassword'
storeFile file('theKeystore.jks')
storePassword 'thePassword'
}
}
...
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.mySigningConfig
}
}
...
}
Then when I generate my release APK, I simply go to Build -> Build Bundle(s) / APK(s) -> Build APK(s) and APK is created. Unlike if I go to Build -> Generate Signed Bundle / APK, it prompts me for this:
My question is, what version of signature does my current gradle file generate with? Is it V1 or V2? How do I modify my gradle file so that it specifically build with V1 or V2?
Found it! I have adjusted my gradle file like so:
signingConfigs {
mySigningConfig {
keyAlias 'theAlias'
keyPassword 'thePassword'
storeFile file('theKeystore.jks')
storePassword 'thePassword'
v1SigningEnabled true
v2SigningEnabled true
}
}
Reference: https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.SigningConfig.html

Generate debug and signed Apk from my server without IDE

I have source code of android app with gradle support. I want to generate Apk online through my server.
anyone guide me the commands for cmd or terminal by which, I can generate debug and signed apk using my source code.
For generating debug and signed apk file from android project.you should add signingConfigs into your app moulde's build.gradle file as follow:
signingConfigs {
...
release {
...
keyAlias YOUR-KEY-ALIAS
keyPassword YOUR-KEY-PASSWORD
storeFile YOUR-KEYSTORE-FILE-PATH//here is your keystore file path
storePassword KEY-STORE-PASSWORD
...
}
debug{//debug keystore
...
keyAlias "androiddebugkey"
keyPassword "android"
storeFile rootProject.file("debug.keystore")//here is your keystore file path
storePassword "android"
...
}
...
}
in your buildTypes block add:
buildTypes {
...
debug{
...
signingConfig signingConfigs.debug
...
}
release {
...
signingConfig signingConfigs.release
...
}
...
}
finally,your can input command in your project's directory:gradlew assemble,that will output your porject's apk file in some derectory(YOUR-PROJECT-DIRECTORY/app/build/outputs/apk)

Generate signed apk without typing key

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

Android studio- adding signing configurations to gradle

I am very new to the android world and I was trying to just get to run a simple hello world app on my phone.
when I tried this I learnt that the APK generated by an android studio is an unsigned one. So to sign this I have gone through the process of creating a Key store and then a private Key, its alias and I was successful in signing the APK and installing on my phone and running it too.
Then I went through this link for adding signing configurations to the gradle to automatically sign the release with the newly created key store file.
I have followed the steps n the above link properly and did not miss anything but still when I finish my signing configurations I have an error saying
Gradle project sync failed.Basic functionality(eg. editing, debugging)
will not work properly.
Error:(19, 0) Could not find property 'config' on SigningConfig
container.
I was taken by a surprise! and now I am not able to sign my APKs manually too.
Now when I try to sign manually, it says the gradle is not in sync
I guess this file will be of help to help me solve this error. build.gradle of the project. I am trying to understand is what is mentioned here is same as the one I configured through the Android Studio UI while making the signing configurations.
apply plugin: 'com.android.application'
android {
signingConfigs {
release {
storeFile file("<path>\\firstKeystore.jks")
storePassword "******"
keyAlias "usual password"
keyPassword "******"
}
}
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {
applicationId 'com.tech.vasanth.newsfeed'
minSdkVersion 19
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
debuggable false
jniDebugBuild false
renderscriptDebugBuild false
zipAlign true
}
debug {
signingConfig signingConfigs.config
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
There is a mistake in the buildTypes.release block. The signing config should be:
signingConfig signingConfigs.release
Note, that this is how you named the configuration in the signingConfigs block above.
Also leave out the signing config in the buildTypes.debug block (or, if you really want to have it, set it like above).
I have been using below configurations for Debug/Release.
signingConfigs {
release {
keyAlias 'keyAlias'
keyPassword 'keyPassword'
storePassword 'storePassword'
storeFile file("${rootDir}/keystores/app.keystore")
}
debug {
storeFile file("${rootDir}/keystores/debug.keystore")
keyAlias 'androiddebugkey'
keyPassword 'android'
storePassword 'android'
}
}
While defining a release module:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'other-rules.pro'
signingConfig signingConfigs.release
}
debug {
signingConfig signingConfigs.debug
}
}
Note: Here rootDir is your project root directory. Please store your keystore in mentioned directory.
structure of get a release is like this :
signingConfigs {
release {
storeFile file("release.keystore")
storePassword "******"
keyAlias "******"
keyPassword "******"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}

"The signing configuration should be specified in Gradle build scripts"... I did it

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.

Categories

Resources