I tried to proguard my app. It successfully obfuscated the apk. However, when i try to view the java code of my apk using Apk_oneclick, I am able to. I have created a release version of my apk. Still the problem persist. Any help would be much appreciated.
Thanks in advance.
build.gradle:
Proguard Rules:
Java code from the release-apk:
For enabling ProGuard configurations for your application you need to enable it in your module level gradle file. you need to set the value of minifyEnabled true.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
You can also enable shrinkResources true which will remove resources that ProGuard flaggs as unused.
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
You need to set following property
and add some rules in proguard-android
buildTypes {
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Got it working. Cleaned the project and ran the same with some changes in the Proguard rules.
Related
I have created the .aar(Android library) for ionic 6/cordova project. But unable to obfuscate the java class files, i.e, able to see the content of the file. Below is the configuration used in app level build.gradle.
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
debuggable false
}
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
It would be great if some one help on this?
I got this warning message:
This App Bundle contains Java/Kotlin code, which might be obfuscated. We recommend you upload a deobfuscation file to make your crashes and ANRs easier to analyze and debug
what does it mean? what is the shortest solution for this?
Seems like it's a warning message coming from the new play console, you can solve it just by setting your minimum api level to 29 or even better by uploading the retrace mapping file as described here.
Enable minify :
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
After building apk/app bundle you can find /app/build/outputs/mapping/release/mapping.txt file . New console will allow you to upload mapping.txt along with your apk or bundle. You can find this option from App bundles and APKs menus.(According to this)
Just changing minifyEnabled to true worked for me
You can solve this by just enabling minify in your build. gradle(app) file:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Just enable minify in your build.gradle(app) file:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
proguard-android-optimize.txt sometimes is unsupported so using the following is safer (see this):
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
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
This question might seem like a "duplicate question" but I've been looking at the same issue in S.O. and Google and I haven't found anything so before downvoting please read the question closely.
Inside my buildTypes (build.gradle) I want to enable proguard only for release mode, so I set inside debug block minifyEnabled false but if I put a breakpoint in debug mode it's skipped, otherwise if I set minifyEnabled false also inside release block all works fine.
Just tried clean, rebuild, invalidate cache. Nothing seem to works.
This is my buildTypes block:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Has someone encountered the same problem?
Thank you very much for your time and assistance in this matter.
Flag minifyEnabled stays for ProGuard, and it's turned off by default. So, in default setup both debug and release builds aren't using ProGuard, and parameter proguardFiles is effectively ignored
My android app was crashing when i build a signed apk. The crash was not seen when i did a debug build. The build.gradle file is like this:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
debuggable true
}
}
setting minifyEnabled to false is not the correct solution, that would disable proguard while building the release version
The reason why setting minifyEnabled is working is because proguard might be obfuscating jsoup.
So, you should keep minifyEnabled as true and include these rules for jsoup in your proguard-rules.txt file to prevent the app from crashing :
-keep public class org.jsoup.** {
public *;
}
What i did to prevent the app from crashing is that i have made minifyEnabled to false from true in the build.gradle file. In that file i have made the following change.
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
debuggable true
}
}
If anybody have any other answers please post it here.