gradlew assembleDebug requires my release key password - gradle

I added the signing settings as the guide says. Now when I run ./gradlew assembleDebug, it requires my keystore and key passwords, and there are two APK files at the end:
./Main/build/outputs/apk/Main-debug.apk
./Main/build/outputs/apk/Main-debug-unaligned.apk
So Gradle builds a debug version of my module but requires the release key.
The build.gradle file of the built module is below.
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
signingConfigs {
release {
storeFile file("my-release-key.keystore")
storePassword System.console().readLine("\nKeystore password: ")
keyPassword System.console().readLine("Key password: ")
keyAlias "my_key"
}
}
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.release
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile project(':Log-Wrapper')
compile 'com.google.android.gms:play-services:+'
}
Update #1.
The solution on https://stackoverflow.com/a/24281294/1065835 works, and I accepted the answer. But I personally prefer using the approach described here. Release keys are stored locally and safely, and there is no need to type passwords every time when compiling a release version.

Seems I could merge some suggestions picked up here and there.. ..and I got it working.
The problem seems to be the fact that writing ANYWHERE in build.gradle something like:
storePassword System.console().readLine("\nKeystore password: ")
it will be executed ANYTIME.
The solution I put together was, creating a signingCongif block BEFORE buildTypes block:
signingConfigs {
release {
storeFile file("c://my.keystore")
storePassword "" // REQUIRED otherwise cannot be overwritten
keyAlias "myAlias"
keyPassword "" // REQUIRED otherwise cannot be overwritten
}
}
buildTypes {
[...]
and tweaking gradle configuration with this:
gradle.taskGraph.whenReady { taskGraph ->
if(taskGraph.hasTask(assembleRelease) || taskGraph.hasTask(installRelease)) {
// Only execute when we are trying to assemble a release build
def passKeystore = System.console().readLine("\nKeystore password: ")
def passKey = System.console().readLine("\nKey password: ")
android.signingConfigs.release.storePassword = passKeystore
android.signingConfigs.release.keyPassword = passKey
}
}
Note that:
1. This block was outside and before the "android {}" one.
2. This was tested in COMMAND LINE execution only. Seems some fixes are needed where no console is available.

It appears as though there are only 3 options:
Extract my signing config to a separate pseduo-project
Automate the signature, but sign EVERYTHING with release keys
Enter the passwords manually on the command line
This is my workaround and your 4th option to achieve a perfect balance:
apply plugin: 'com.android.application'
gradle.taskGraph.whenReady { taskGraph ->
if(taskGraph.hasTask(':app:assembleRelease')) {
android.signingConfigs.release.storeFile = file(KEYSTORE)
android.signingConfigs.release.storePassword = STOREPASS
android.signingConfigs.release.keyAlias = KEY_ALIAS
android.signingConfigs.release.keyPassword = KEYPASS
}
}
android {
...
defaultConfig {
...
}
signingConfigs {
debug {
}
release {
}
}
buildTypes {
debug {
...
}
release {
...
//signingConfig signingConfigs.release
}
}
}
This allows you to use a stored key and signature ONLY on release builds

Related

How to Sign Android App to avoid App not installed from Play Store error?

I'm trying to release new update to my users on play store, but whenever I roll out the release all users complaint me about app is not updating or not installing after downloading update from play store.
How do I configure my gradle / manifest / or build settings such that users will successfully install the new update without needing to uninstall the existing apk from the device?
Please correct me if my settings are configured incorrectly.
build.gradle(app)
android {
compileSdkVersion 31
defaultConfig {
applicationId "com.myapp"
minSdkVersion 23
targetSdkVersion 31
versionCode 11
versionName "2.2.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.debug
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
debuggable true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
debug {
signingConfig signingConfigs.debug
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
bundle{
language{
enableSplit=false
}
}
}
build.gradle(project)
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
proguard-rules.pro
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-keepattributes Signature
-keep class androidx.appcompat.widget.** { *; }
-keepclassmembers class com.myapp.Firebase** {
*;
}
I'm not able to understand which part of the mentioned code having issues with. Sometimes my build takes so much time during running app for testing on device. I new in this signing process. I will really appreciate your help.

OpenAPI Generator gradle plugin task not executed

In my android project I am trying to include the openapi-generator plugin to generate a client. I've copied the instructions from the readme for my project. Unfortunately, the task doesen't seem to be executed.
I am new to gradle and android. So I haven't a lot of knowledge on these subjects yet.
This is the projects build.gradle file:
buildscript {
ext {
nav_version = '2.4.2'
}
dependencies {
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
classpath "org.openapitools:openapi-generator-gradle-plugin:5.4.0"
}
}
plugins {
id 'com.android.application' version '7.1.3' apply false
id 'com.android.library' version '7.1.3' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This is the build.gradle file of my module:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'androidx.navigation.safeargs.kotlin'
id 'kotlin-kapt'
id "org.openapi.generator"
}
android {
compileSdk 31
defaultConfig {
applicationId "..."
minSdk 29
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
dataBinding true
}
sourceSets {
main {
kotlin {
srcDirs += 'build/generated/source/navigation-args/'
}
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
openApiGenerate {
generatorName = "kotlin"
inputSpec = "$rootDir/app/src/main/assets/swagger.yml".toString()
outputDir = "$buildDir/generated".toString()
apiPackage = "org.openapi.example.api"
invokerPackage = "org.openapi.example.invoker"
modelPackage = "org.openapi.example.model"
configOptions = [
dateLibrary: "java8"
]
}
In the output of the build was no hint that the openApiGenerate task was executed and on the filesystem I didn't find the generated client.
Probably there is a mistake in the configuration, but I don't know what is wrong.
Can you help me?
This command should generate the client :
./gradlew openApiGenerate
If you want to avoid manually running this every time your schema changes, then you can go to the drop down here:
Now choose edit configurations:
Now add a gradle task with the + button:
Then:
Enter the task in run:
Now edit the app configuration, by adding what you just created to the before launch section:
You will see the YourAppsName[openApiGenerate] configuration you created as an option, so select that, then apply changes, and now every time you run your application your client will be built.

Program type already present: androidx.work.ArrayCreatingInputMerger

D8: Program type already present:androidx.work.ArrayCreatingInputMerger
FAILURE: Build failed with an exception.
in gradle.properties
```android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M```
in build.gradle
```def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.xyz"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
minifyEnabled true
useProguard true
// shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
flutter {
source '../..'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.firebase:firebase-firestore:18.0.0'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.6'
}
apply plugin: 'com.google.gms.google-services'```
8: Program type already present: androidx.work.ArrayCreatingInputMerger
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
com.android.build.api.transform.TransformException: Error while generating the main dex list:
Error while merging dex archives:
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: androidx.work.ArrayCreatingInputMerger
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 4s
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See goo.gl/CP92wY for more information on the problem and how to fix it.
Gradle task assembleDebug failed with exit code 1

react-native: create my own gradle build config

I don't really know how to word this issue which is probably why i can't find any answers online.
in react-native we can do
./gradlew assembleRelease
and it will read ~/.gradle/gradle.properties and the SigningConfig in android/app/build.gradle
signingConfigs {
release {
storeFile file(BLAH_RELEASE_STORE_FILE)
storePassword BLAH_RELEASE_STORE_PASSWORD
keyAlias BLAH_RELEASE_KEY_ALIAS
keyPassword BLAH_RELEASE_KEY_PASSWORD
}
}
to produce a signed apk.
I'd like to create signed apks but using a different keystore file from a single command
so ideally
./gradlew assembleDev
and it would create an signed apk with a different output name and signed with a different key. Ideally with a different identifier so that the app can be installed side by side with the release version of the app.
I know i need to make changes to gradle config, but searching around i can't figure out how to do this. Is there a ready made tutorial that walks someone how to do this?
I'm thinking i can't possibly be the first person to want this.
You could use the buildType as the prefix for the property names
android {
signingConfigs {
release {
storeFile file(property('release.storeFile'))
storePassword property('release.storePassword')
...
}
dev {
storeFile file(property('dev.storeFile'))
storePassword property('dev.storePassword')
...
}
}
buildTypes {
release {
signingConfig signingConfigs.release
...
}
dev {
signingConfig signingConfigs.dev
...
}
}
}

Android Gradle Build Resource.getIdentifier() always returns 0

I'm getting started on porting my Game over to the new Gradle Build system for Android.
I'm using the Resource.getIdentifier() method to load some resources by name instead of ID. However, ever since switching to the Gradle build, this call always returns 0. The assets are included in the built jar, and the R.class in the dex file contains all of my resources and ID's as expected, so I am at a loss as to explain this. This code worked before I changed to the gradle build. My build.gradle is below:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
dependencies {
compile 'com.android.support:support-v4:18.0.+'
}
android {
compileSdkVersion 18
buildToolsVersion "19"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
buildTypes {
debug {
packageNameSuffix ".debug"
}
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
TIA.
D'oh! my problem was that Resources.getIdentifer() takes 3 parameters, one of which is the package name. The debug section of my gradle script was tacking on ".debug" to the package name on the device. Solution is to remove the .debug suffix in the build.gradle.

Resources