Android.Gradle: Sign release apk and put on specific folder - android

Gradle 4.2, Android Studio 2.3.3.
My app/build.gradle
android {
compileSdkVersion 26
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.myproject"
minSdkVersion 16
targetSdkVersion 23
versionCode 3
versionName "1.2.3"
}
signingConfigs {
release {
keyAlias keystoreProperties['KEY_ALIAS_RELEASE']
keyPassword keystoreProperties['KEY_PASSWORD_RELEASE']
storeFile file(keystoreProperties['STORE_FILE_RELEASE'])
storePassword keystoreProperties['STORE_PASSWORD_RELEASE']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
If I want to create sign apk I use the next command:
gradlew assembleRelease
As result I get sign apk in the path = \my_project\app\build\outputs\apk\app-release.apk
OK. It's work fine.
Now I has some custom requirements:
Sign release apk
The resul apk name must be "myproject_xxx.apk", where xxx = versionName. So in this example result apk name = "myproject_1.2.3.apk"
The file "myproject_xxx.apk" must be in the directory: my_project\result_apks\
So to do all of this points I need to write my custom gradle task. I'm right?

Related

Signed Flutter App: Not Installed Android APK

I am trying to build an android apk to share but, when installing I get the "App Not Installed" error message.
I have placed my credentials in the build.gradle file:
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.buddiesDrivers"
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
signingConfigs {
release {
keyAlias 'key'
keyPassword 'abc123'
storeFile file('/Users/test/key.jks')
storePassword 'abc123'
}
}
I run the keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key option and ad the creds shown above then:
Flutter clean
Flutter Build APK
The build file creates the apk but, it cannot be installed. What did I miss?
Remove your previous installation, if it was the debug so it won't work usually. Uninstall that first then try installing the release version.
it could be because you have set minsdkversion to a higher version.
go to Android/app/build.gradle and change minsdversion to 19 or below.
it worked for me after trying all the solutions.

Cannot generate apk in release mode

I was following this documentation "Configure the build process to automatically sign your app" https://developer.android.com/studio/publish/app-signing#sign-auto and trying to generate apk for release version.
However, the apk that is generated always locate inside debug folder even though I did setting for release on Module Setting.
This is gradle file.
android {
signingConfigs {
config {
keyAlias 'key0'
keyPassword 'password'
storeFile file('C:/path/to/filename.jks')
storePassword 'password'
}
}
compileSdkVersion 28
defaultConfig {
applicationId "com.packagename"
minSdkVersion 19
targetSdkVersion 28
versionCode 3
versionName "2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}
}
and I clicked Build Bundle(s)/APK(s) -> Build APK(s)
Is this what it supposed to do? If not, how can I fix this?
In android studio click on Build variant option on left vertical bar and then select release Build variant then Build Bundle(s)/APK(s) -> Build APK(s)

Need to enter keystore details manually in Android Studio even though they exist in build.gradle

I have the following lines in my "project module" build.gradle (i.e. in /ProjectName/ProjectName/build.gradle):
android {
signingConfigs {
release {
keyAlias "mykeyalias"
keyPassword "mykeypassword"
storeFile file("/Users/MyUsername/Documents/AndroidStudio/android_keystore")
storePassword "mykeystorepassword"
}
}
compileSdkVersion 28
buildToolsVersion '28.0.2'
defaultConfig {
applicationId "com.example.mypackagename"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
signingConfig signingConfigs.release
}
...
Still, when I click Build->Generate signed APK..., I still have to enter everything manually. This used to work before, not sure when it broke. I have double- and triple checked the path to the keystore file.
Any ideas what could be wrong?
Because it's working as designed, i-e whenever you select to generate signed apk from Build->Generate Signed APK that wizard will always ask you to enter keystore information regardless of any configs being mentioned in gradle files ( although you can mark checkbox to remember that info for later use.)
If you don't want to mention keystore infomation while generating build, switch to release variant and just select Build->Build APK(s). It will generate release apk with the signing configs you have mentioned in your build.gradle file.

INSTALL_PARSE_FAILED_NO_CERTIFICATES with OWN .apk

Since I updated my Android Studio, I cant install my App anymore, neither in the debug nor in the release mode.
I always get the error:
pkg: /data/local/tmp/com.myappdomain.mypp
Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]
Installation failed since the APK was either not signed, or signed incorrectly.
If this is a Gradle-based project, then make sure the signing configuration is specified in the Gradle build script.
Error while Installing APK
From what I googled, this just happens when trying to install unsigned third party .apk
This is my own App though, signed with Android Studio
Gradle looks like this:
android {
signingConfigs {
release {
storeFile file("...")
keyAlias "..."
storePassword "..."
keyPassword "..."
}
}
buildTypes {
release {
minifyEnabled true
zipAlignEnabled true
signingConfig signingConfigs.release
}
}
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId '...'
minSdkVersion 14
targetSdkVersion 22
}
productFlavors {
}
}
I solved it by updating the target SDK to 23 and updating all my used libraries. Maybe it helps you too.

Differentiate between productFlavors in Android app.gradle file during build process

android {
final String analyticsJSON = "lite"
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.ralok.apps"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
productFlavors {
findlostandroidphone {
versionCode 1
versionName 'v1.0'
applicationId 'com.ralok.apps.findlostandroidphone'
}
findlostandroidphonepro {
versionCode 1
versionName 'v1.0'
applicationId 'com.ralok.apps.findlostandroidphonepro'
}
if (analyticsJSON.equals("lite")) {
println "--> FLPLite JSON copied!"
copy {
from 'src/findlostandroidphone/'
include 'google-services.json'
into '.'
}
} else {
println "--> FLPPro JSON copied!"
copy {
from 'src/findlostandroidphonepro/'
include 'google-services.json'
into '.'
}
}
}
signingConfigs {
lite_release {
keyAlias 'ASDFGHJKL'
keyPassword 'ASDFGHJKL'
storeFile file('ASDFGHJKL.jks')
storePassword 'ASDFGHJKL'
}
pro_release {
keyAlias 'POIUYTREWQ'
keyPassword 'POIUYTREWQ'
storeFile file('POIUYTREWQ.jks')
storePassword 'POIUYTREWQ'
}
}
buildTypes {
debug {
minifyEnabled false
debuggable true
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Every time I have to manually change the final String analyticsJSON = "lite/pro" so that the if loop copies the right json file to the root directory. Is there anyway I can automate this and always have the correct productFlavour in analyticsJSON String instead of me changing the value manually every time I switch between productFlavors. My groovy is bad and I have tried but failed to achieve this.
You don't need to differentiate the build system will do it for you. Simply place the files in the correct path per build flavor. For example.
For findlostandroidphone place your google-services.json in the following location.
src/findlostandroidphone/google-services.json the build the file will be copied into the final location automatically for that product flavor. Same for the pro version.
What you have right now will be executed in the configuration phase. which probably works... for a single build type. If you want to build both types at the same time then you should move the files and remove the final String analyticsJSON = "lite" entirely. Then during the execution phase gradle will copy the file and execute the build with the correct file for that productFlavor.
Finally a solution for handling different flavors is implemented in version com.google.gms:google-services:2.0.0-alpha3
https://developers.google.com/android/guides/google-services-plugin#adding_the_json_file
https://github.com/googlesamples/google-services/issues/54
Another alternative solution is on
How do i keep different configurations for my android app with GCM 3.0

Categories

Resources