I have enable proguard, but for tracking bugs I need a mapping file to upload to Google Play.
Here is my gradle configuration of proguard:
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
try to find the mapping file at build/outputs/proguard/release/mapping.txt in your application module's directory.
if you have -dontobfuscate in your proguard. please remove it
rebuild and rerun.. Then it should able to see the mapping file in proguard directory
Related
I add aar library to my project, that has following in proguard rules:
-obfuscationdictionary build/obfuscation-dictionary.txt
-classobfuscationdictionary build/class-dictionary.txt
I got error, when build with
isMinifyEnabled = true
java.nio.file.NoSuchFileException: C:\Users....gradle\caches\transforms-3\07478cf30c50e6fe3820e9cff7b7aab9\transformed...\build\obfuscation-dictionary.txt
java.nio.file.NoSuchFileException: C:\Users....gradle\caches\transforms-3\07478cf30c50e6fe3820e9cff7b7aab9\transformed...\build\class-dictionary.txt
I tried add next to my project, but it didn't help
release {
minifyEnabled true
debuggable false
// automatically add your proguard rules into your library user
consumerProguardFiles 'proguard-rules.pro'
proguardFiles 'proguard-rules-dic.pro', 'proguard-rules.pro'
}
So iv'e been enabling Pro-Guard to a project and after building the apk i decompiled it to make sure Pro-Guard did he's job and notices that it adds, for example, to the BaseAdapter class -
/* compiled from: BaseAdapter */
See picture -
Now I'm asking, doesn't it lose the point of the Pro-Guard if it says what class that was?
Is there any way to tell the Pro-Guard not to add this info line at all the classes?
My code where i added Pro-Guard -
buildTypes {
debug {
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
shrinkResources true
}
release {
signingConfig signingConfigs.somethingsomething
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
shrinkResources true
}
}
Thanks.
Proguard is not adding this line.
/* compiled from: BaseAdapter */
The decompiler is doing mapping of obfuscated name with original name. You are seeing it as you might be using jadx or online service like this
You can try using dex2jar and jd-gui to look at decompiled code. This line will not be present there.
Make sure that 'proguard-rules.pro' file does not have following attributes in it.
-keepattributes SourceFile
If you add this statement no decompiler will be able make this mapping.
I'm trying to configure proguard to use it with my espresso UI test flavor. The thing is Proguard tends to ignore my debug proguard config.
This is how the config looks:
buildTypes {
debug {
minifyEnabled true
proguardFiles 'proguard-debug.pro'
testProguardFile 'proguard-debug.pro'
signingConfig signingConfigs.release
}
}
I added testProguardFile but it doesn't seem to work on androidTest. I'm running mockDebug flavor variant. When I just run the app it works fine, but when I try to run test which is located in adnroidTest it won't run due to proguard warnings, like the proguard file wasn't processed at all and the file is pretty straight forward:
proguard-debug.pro
-dontobfuscate
-dontoptimize
-dontwarn
Before someone starts to advise me turning off proguard for debug builds: I need to have it enabled because of multidex.
If you want your test build as close as possible from the real deal, try this one:
# build.gradle
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
testProguardFile 'proguard-test.pro'
}
and
# proguard-test.pro:
-include proguard-rules.pro
-keepattributes SourceFile,LineNumberTable
On other hand, if you need it only because multidex, if your are using minSdkVersion < 21, ProGuard is tied to multidex flag and run automatically.
You also need to add the default proguard rules:
proguardFiles getDefaultProguardFile('proguard-android.txt')
This line can be removed, as it is a duplicate:
testProguardFile 'proguard-debug.pro'
Android libraries, per the AAR file spec, includes a 'proguard.txt' file.
My understanding is that this file declares how the library correctly can be obfuscated and minified. In my case I need to preserve some API-classes.
How can I declare the library's proguard.txt file in the library's build.gradle? And will this file be automatically read when creating an application (APK) that uses my library?
I didn't find this information in Android's Gradle Plugin User Guide.
In your Gradle file's default configuration closure, specify your Proguard file with consumerProguardFiles instead of proguardFiles. For example:
defaultConfig {
consumerProguardFiles 'proguard.txt'
}
ProGuard artefact
[ProGuard workflow]
Artefact not minified, Consumer solve it
Library is open-sourced but as a library developer you can provide a ProGuard file which will be take into account by consumer(app) by demand(minifyEnabled true in consumer). consumerProguardFiles in you library build.gradle. It adds proguard.txt file(is the same as .pro) in an artefact
For example your library is open-source and application developer wants to minify all
android {
defaultConfig {
//consumerProguardFiles '<file_path>'
consumerProguardFiles 'proguard-rules.pro'
}
buildTypes {
release {
minifyEnabled false
}
}
//...
}
Artefact is minified
Library is closed-source - you are able to use the next possibility:
android {
buildTypes {
release {
minifyEnabled true
//proguardFiles project(':<project_name>').file('<file_path>')
proguardFiles 'proguard-rules.pro'
}
}
//...
}
*Please note that:
minifyEnabled true and proguardFiles project both should be set.
If you use single minifyEnabled true or <file_path> is wrong - classes.jar is empty.
If single proguardFiles project - no effect
As for build process on the example of library - application - all .class files will be merged into single archive with .dex extension
I am trying to export signed apk, obfuscated with proguard. But after process, I can see my code and my class names in decompiler tool. Spent 1 day , but can't understand what I missed.
In my gradle file I specified :
buildTypes {
release {
apply plugin: 'maven'
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
proguard-rules.pro is empty.
Should I specify anything else to enable proguarding ? After decompilation
Change minifyEnabled to true to enable proguard in your build configuration.