Stop Pro-Guard from adding "compiled from:" to the classes - android

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.

Related

My app crashes when using proguard with Hyperledger Iroha

When i try to do minify enabled true in my build.gradle file using below code application is crashed :
Code
buildTypes {
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug{
debuggable true
minifyEnabled true
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
when I did: minifyEnabled true after building release apk: app-release.apk, the app crashed.
when I did: minifyEnabled false after building release apk: app-release.apk, the build is okay.
enter image description here
As indicated ref resource, minifyEnabled will remove unused codes. In your situation, there might be methods which is used with JNI or else and compiler did not known it's used. Again according to ref, you can specify which files to keep from examination of built-in minify (same as proguard).
The answer is here
As given in the error message the classloader was not able to find the class org.apache.xerces.datatype.DatatypeFactoryImpl
Proguard is changing the class name to stop this from happening you can add
-keep class org.apache.**{ *; }
in your progurad-rules.pro file
Add this to proguard
-keep public class jp.co.soramitsu.iroha.android.** {
public protected *;
public private *;
}

Code shrinking on debug

Before I release the app, I am trying to test whether there will be any changes(methods, variables removed) if I code shrink with Instant run the app. I am following this Enable code shrinking with Instant Run but it does not show any signs in my code that was removed or changed.
android {
buildTypes {
debug {
minifyEnabled true
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
Is there any way to check if there are changes made?
You should use Shrinking options -printUsage and it will tell you dead code, which eventually will be removed during shrinking.
-printusage [filename]
Specifies to list dead code of the input class files. The list is printed to the standard output or to the given file. For example, you can list the unused code of an application. Only applicable when shrinking.
android {
...
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}

Can't find proguad mapping file

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

Using proguard with espresso/androidTest

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'

Proguard not obfuscating in Android Studio

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.

Categories

Resources