Generate debug and signed Apk from my server without IDE - android

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)

Related

Build android release locally while Google Play manages the app signing key

How do I compile build variants locally while being opted in to Google Play app signing? They created my signing key and I therefore only have an upload key.
I would like to test my staging and release build variants locally, but Android studio requires me to create a signingConfig in my gradle file, with the path to my storeFile the storePassword, keyAlias and keyPassword. When I provide my upload key details and try to build the release or staging version for local testing purposes I just get 'Invalid keystore format'.
My build.gradle files looks something like the following (omitted my details and some buildType variables)
My signing config
signingConfigs {
config {
storeFile file('')
storePassword ''
keyAlias 'upload'
keyPassword ''
}
}
My buildTypes
buildTypes {
debug {
}
staging {
signingConfig signingConfigs.config
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}

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 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 0.4.+ custom debug keystore

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
}
}

"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