Build type is always "Release" - android

I am obtaining that BuildConfig.BUILD_TYPE returns always "release", even if I am compiling it in debug mode.
I include here a part of my build.gradle:
buildTypes {
debug {
debuggable true
minifyEnabled false
}
release {
debuggable false
minifyEnabled false
//md5 sign certificate split in two
proguardFile './dexguard-config/dexguard-release-conservative.pro'
//proguardFile getDefaultDexGuardFile('dexguard-release-aggressive.pro')
proguardFile 'dexguard-project.txt'
}
Thank you!

Make sure you are importing BuildConfig of your own module, with the package name from its AndroidManifest.xml.
Other modules' BuildConfigs might be hardwired to release.

Check your option in Build Variants in Android Studio.
PS: You can also run your release APK in debug mode.

Related

Error on uploading app to play console- "Upload failed The Android App Bundle was not signed ."

When I upload the signed bundle of the app to play store it gives an error-
"Upload failed
The Android App Bundle was not signed."
In my case, for the same issue, debuggable was true in the selected build type while generating build.
After setting it to false, the generated build started to get uploaded in Play Store. Play Store does not accept builds with debuggable on.
In seems that The Android App Bundle was not signed (Набор Android App Bundle не подписан) error can be produced by some incompatible debug or testing-related options in release build type. In my case problem was solved by removing testCoverageEnabled true from release build type section.
Now these sections looks like this:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
testCoverageEnabled true
}
}
like said above, make debuggable be false , and also , when generating signed bundle , be sure you pressed the "export encrypted key for enrolling..." .

How to have different gradle.properties files for release/debug builds?

We need to have gradle.properties files with different configs for release and debug builds, because some of the features we use are experimental and they break some things. Is that possible?
Example of our gradle.properties file
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx1500m -XX:MaxPermSize=512m
org.gradle.parallel=true
kotlin.incremental=true
android.enableD8=true
As per official document:
You can create and configure build types in the module-level build.gradle file inside the android block. When you create a new module, Android Studio automatically creates the debug and release build types for you. Although the debug build type doesn't appear in the build configuration file, Android Studio configures it with debuggable true. This allows you to debug the app on secure Android devices and configures APK signing with a generic debug keystore.
You can add the debug build type to your configuration if you want to add or change certain settings. The following sample specifies an applicationIdSuffix for the debug build type, and configures a "staging" build type that is initialized using settings from the debug build type.
You can use same build.gradle for release and debug modes like:
buildTypes {
release {
// Do whatever you want to do in release mode
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
// Do whatever you want to do in debug mode
applicationIdSuffix ".debug"
debuggable true
}
/**
* The `initWith` property allows you to copy configurations from other build types,
* then configure just the settings you want to change. This one copies the debug build
* type, and then changes the manifest placeholder and application ID.
*/
staging {
initWith debug
manifestPlaceholders = [hostName:"internal.example.com"]
applicationIdSuffix ".debugStaging"
}
}
Ref: Source
buildTypes {
release {
shrinkResources true
minifyEnabled true
debuggable false
signingConfig signingConfigs.releaseConfig
}
debug1 {
debuggable true
signingConfig signingConfigs.debug
}
debug2 {
debuggable true
signingConfig signingConfigs.debug
}
}
You came different build variants like above and on Android studios select the build variants option(usually in the bottom left corner). select which variant you want to build the apk and run the app.

ProGuard doesn't obfuscate when building alternative buildType from Android Studio

So in a few words ProGuard doesn't obfuscate sources when I build alternative buildType from Android Studio but works when I use "Generate Signed APK..." option to create apk file.
And some more details here: Android Studio 2.1.1, Gradle version: 2.10, plugin version .2.1.0
I've 3 build types with the following configuration:
buildTypes {
release {
minifyEnabled true
...
proguardFile 'proguard-rules.pro'
proguardFile getDefaultProguardFile('proguard-android.txt')
signingConfig signingConfigs.release
}
releaseDebug {
debuggable true
minifyEnabled true
...
proguardFile 'proguard-rules.pro'
proguardFile getDefaultProguardFile('proguard-android.txt')
signingConfig signingConfigs.release
}
debug {
debuggable true
minifyEnabled false
...
proguardFile getDefaultProguardFile('proguard-android.txt')
testProguardFile 'proguard-rules-test.pro'
signingConfig signingConfigs.release
}
}
I run application directly from Android Studio and have such results:
release - obfuscated
releaseDebug - NOT obfuscated
debug - not obfuscated
When I use "Generate Signed APK..." option:
release - obfuscated
releaseDebug - obfuscated
debug - not obfuscated
Is it a build system issue or I missed something?
P.S. Just for clarification, minifyEnabled is already enabled for releaseDebug build type and ProGuard is working but not in this particular case. This is not related to debug mode.
Finally, after some tests, I recognized that this issue is caused by debuggable true statement in releaseDebug configuration.
So Android Studio (or Gradle) will not use ProGuard obfuscation if you use debuggable true and minifyEnabled true statements in your alternative build type.

How to debug the Android App in release mode using Android studio

For some reason I have to run my Android App in release mode.I have to run through the code when running the app just like we use in debug mode. My break points are not hitting when I run in release mode, I have added android:debuggable="true" in manifest. Still the breakpoint is not hitting. Any help.
Thanks in Advance
In your gradle file, you must add debuggable ability in your release flavor.
buildTypes {
release {
debuggable true
minifyEnabled false
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
debuggable true
minifyEnabled false
applicationIdSuffix '.debug'
}
}
signingConfig is release configuration it must be added in gradle file in android{} block, something like this:
signingConfigs {
release {
keyAlias 'YourAppKey'
keyPassword 'somePassword'
storeFile file('appkeyfile.jks')
storePassword 'somePassword'
}
}
In my case, I have created the debug configuration same as previous release build and started debugging. It means you have to give sign build in debug version also in build gradle.
signingConfigs {
config {
keyAlias 'abc'
keyPassword 'xyz'
storeFile file('<<KEYSTORE-PATH>>.keystore')
storePassword 'password'
}
}
buildTypes {
debug {
debuggable true
signingConfig signingConfigs.config
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
So It will have the same sign as release build and you can debug when it runs.
buildTypes {
release {
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
happy coding.Mark this answer up..if it helps.. :)
Few pennys for the new comers.
If even After adding debuggable true in release block, your debug points are not hit.
Remove the following code from the release block.
minifyEnabled true
shrinkResources true //remove resources
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
There's no "release mode". What you refer to is the build type which means steps taken during building (like minifying etc). Setting android:debuggable="true" will not automagically help, because when you "Run" the app instead of "Debug" you do not connect debugger to it so it will not stop for that particular reason.
So you can
set up your Debug build to be produced the same way Release
is
But is quite unclear what is the reasoning behind your need and I got a feeling you are trying to go the wrong way (i.e. debug is usually not using ProGuard, while release build is and ProGuard changes the resulting binary so your breakpoints from source will not really work anyway).
I think Marcin's argument above makes sense (much as there are situations that require debugging release builds), so here is a slight variation of the accepted answers that worked for me:
android {
...
buildTypes {
release {
shrinkResources false # this was key
minifyEnabled false # seems that it can't be set to true if shrinkResources is false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
Adapted from the official docs
NOTE:
When I set minifyEnabled true, the following crash occurred on app launch:
java.lang.RuntimeException: Unable to instantiate application co.mycompany.app.MyApp: java.lang.ClassNotFoundException: Didn't find class "co.mycompany.app.MyApp" on path: DexPathList...
In 2022, or at least in MY case
I tried many solutions but didnt work finally solution was to create a new siginig key and use it with all build types &variants.
Steps
1 - Go to AndroidStudio top menu select Build>Generate Signed Bundle /APK > (choose APK )
*for the first time create a new key (you know how to create one? or read docs )
BUT NOTE while you are creating key choose build type debug then continue
2 - Again Go to AndroidStudio top menu select Build > Generate Signed Bundle /APK > (choose APK) BUT this time choose existing key ( the one we made in previouse step)
in previouse step we chose build type debug this time choose release and continue..
3 - Repeat steps 1 & 2, with AAB (release & debug)
this is basically making sure all build types are being signed using same configs.
NOTE
maybe you need to add below code to app build.gradle
android {
...
signingConfigs { <-- Add this
config {
storeFile file('PATH_TO_KEY.jks')
storePassword 'YOUR PASSWORD'
keyAlias 'YOUR KEY ALIAS'
keyPassword 'YOUR PASSWORD'
}
}
...
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config <-- this
}
debug {
signingConfig signingConfigs.config <-- this
}
}
}

This application does not have the debuggable attribute enabled in its manifest

Cannot debug application com.domain.test on device samsung-gt_i9300-323020cfc86b804f.
This application does not have the debuggable attribute enabled in its manifest.
If you have manually set it in the manifest, then remove it and let the IDE automatically assign it.
If you are using Gradle, make sure that your current variant is debuggable.
Your comment has already hinted the answer to this post but since you have not selected an answer I'll write it down.
Change build variant from release to debug from android studio left corner.
A right solution is written in https://stackoverflow.com/a/25628789/2914140:
open build.gradle of your module, type: 'debuggable true' (an example is below):
buildTypes {
release {
signingConfig signingConfigs.release
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
applicationIdSuffix ".debug"
debuggable true
}
}
When you generate a signed APK from menu, you should edit 'release' branch changing 'debuggable true' to false in order to avoid a debuggable information.
In build.gradle
debug {
debuggable true
signingConfig signingConfigs.debug
}
for whose came here searching TS's quote, check if you set Android Application in Run/Debug configuration popup. Not Native, like in my mistake.

Categories

Resources