error while generating signed apk task app:packageRelease - android

Error:A problem was found with the configuration of task ':app:packageRelease'.
File '/Volumes/Data/Android apps/NammaKarnataka-master/app/build/intermediates/res/resources-release-stripped.ap_' specified for property 'resourceFile' does not exist.
The following error message occurred while I tried to generate signed apk on Android studio 2.2.
What additional information is required in order to solve this issue?

Add shrinkResources, set to false, to the release clause:
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled false
shrinkResources false //ADD THIS
zipAlignEnabled true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

Command flutter clean helps me.

Related

DexGuard error while trying to enable minifying in ProGuard

I am trying to enable minifying in an Android app using ProGuard.
When I set minifyEnabled to false it builds but as soon as I set it to true:
buildTypes {
debug {
minifyEnabled false
jniDebuggable true
versionNameSuffix '_DEBUG'
zipAlignEnabled true
}
release {
minifyEnabled true
proguardFile getDefaultDexGuardFile('dexguard-release.pro')
proguardFile 'dexguard-project.txt'
jniDebuggable false
signingConfig signingConfigs.release
}
I get a gradle syncing error:
ERROR: minifyEnabled is set to 'true' for variant <name of the variant>.
And stacktrace states:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':MainApp'
Caused by: org.gradle.api.GradleException: Errors occurred during DexGuard plugin configuration.
What does DexGuard have to do here?
Dexguard's documentation says:
DexGuard expects its inputs to be unobfuscated, so make sure none of the variants you specify here have the minifyEnabled options set to true.
You can't use both Dexugard and Proguard in the same library. You have to either disable Dexguard or Proguard.
Dexguard is an improved (and paid) version of Progurad. I don't see any reason for using Proguard when you have Dexguard.

Removing unused resources requires unused code shrinking to be turned on

I am preparing to release an App to production. So, I generated signed apk. After generating signed apk, I was getting a problem. My apk file size is a little large and I tried ways to shrink the apk size. I already tried
app --> Refactor --> Remove Unused Resources
and it is not too reduce. So, I added shrinkResources true in my build.gradle(app)
buildTypes {
release {
minifyEnabled false
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
After adding shrinkResources true and I got below error when I rebuild. My question is how should I turn on unused Code shrinking first? Thanks and appreciating.
Resource shrinking works only in conjunction with code shrinking. After the code shrinker removes all unused code, the resource shrinker can identify which resources the app still uses. This is especially true when you add code libraries that include resources—you must remove unused library code so the library resources become unreferenced and, thus, removable by the resource shrinker
To enable resource shrinking, set the shrinkResources property to true in your build.gradle file (alongside minifyEnabled for code shrinking). For example:
android {
...
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
reference
Maybe you set by mistake minifyEnabled = false and shrinkResources = true in your buildTypes.debug, so, maybe, it is a root of a problem, not your buildTypes.release
android {
buildTypes {
release {
minifyEnabled true
shrinkResources true
}
}
}
You might want to refer to the Android Documentation to shrink your code and resources:
Shrink your code and resources
Like a comment already pointed out, resource shrinking only works when you have used the code shrinker. To enable shrinkResources in your build.gradle file you must have first set minifyEnabled to true
Simple just open the build.gradle file on App level i.e. android/app/build.gradle and implement this:
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
useProguard true
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
In order to use resource shrinking, you also need to enable code shrinking as they both works in conjunction.
So to do so, set shrinkResources true along with minifyEnabled true.
You can follow the official site for the same.
make sure to add it into proper part of gradle
signingConfigs {
buildTypes {
debug {
buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" + System.currentTimeMillis() + "L)"
}
release {
buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" + System.currentTimeMillis() + "L)"
}
}
}
buildTypes {
release {
minifyEnabled false
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
If you have added shrinkResources true make sure it comes after minifyEnabled true the order matters so https://stackoverflow.com/a/56426634/10355668 is correct thanks

Release apk won't run

I'm building release APK with flutter run --release but I'm getting this exception
Failed to register native method io.flutter.view.FlutterNativeView.nativeRunBundleAndSource(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V in /data/app/com.example.myapp-1/base.apk
However, debug variant runs normally so if I run the app just with flutter run everything is fine.
By the way, I'm executing flutter clean before avery build.
What is the cause of this?
Found the solution on my own, but I'm posting this answer for people who are having the same problem.
Turns out that build.gradle was causing exception
shrinkResources true // for this to work minifyEnabled must be set to true
minifyEnabled true // if set to true apk will not build
Solved it by using only proGuard so snippet below is working buildTypes section of app-level build.gradle
buildTypes {
release {
debuggable false
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}

connectedAndroidTest and release build type

I'm using gradle:1.2.3
I would like to run my androidConntectTests (instrumentation tests) on release (signed, minified) configuration, but I cannot.
My build types:
buildTypes {
debug {
minifyEnabled false
debuggable true
}
robotium {
debuggable true
minifyEnabled true
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
debuggable false
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
I have read, that those tests can only be run on debbugable configurations, so I made "robotium" build type (see above), but it still does not work.
When I try calling "gradle tasks" it shows only connectedAndroidTest-Flavour-Debug, and calling "connectedAndroidTest-Flavour-Release/Robobium" simply fails with "task XXX not found in root project".
Is there any way to make instrumentation tests run on diffrent build type?
The android gradle plugin will create test variants for all your flavors. To switch the build type used you can do this, as stated in the documentation
Currently only one Build Type is tested. By default it is the debug Build Type, but this can be reconfigured with:
android {
...
testBuildType "staging"
}

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

Categories

Resources