I my using LibGdx based android game, I have used the below Gradle, proguard-rules.pro. In the crash report, I do not see source file and its line number. Anything I am missing ?
Gradle
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt', 'proguard-rules.pro'
}
}
'proguard-rules.pro
-keep class com.google.firebase.provider.FirebaseInitProvider
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
Crash Report - Android Developer console
java.lang.NullPointerException:
at com.a.b.g.a (g.java:110)
at com.b.b.a (b.java:11)
at com.a.b.d.g (d.java:492)
at com.a.b.d.a (d.java:485)
at com.badlogic.gdx.backends.android.k.a (k.java:356)
at com.badlogic.gdx.backends.android.j.onDrawFrame (j.java:457)
at android.opengl.GLSurfaceView$GLThread.guardedRun (GLSurfaceView.java:1522)
at android.opengl.GLSurfaceView$GLThread.run (GLSurfaceView.java:1239)
You need setup your proguard rules according official article. In my case rules not required:
-dontwarn android.support.**
-dontwarn com.badlogic.gdx.backends.android.AndroidFragmentApplication
Make sure that file proguard-project.txt stored in android module, not in project root.
Related
I am using ESRI maps in my android app. I want to Shrink, obfuscate, and optimize my app for that I enabled R8 in my application in gradle.properties file by adding this line:
android.enableR8 = true
along with this, I enabled these by adding the following lines in app-level build.gradle
debug {
minifyEnabled true
shrinkResources true
zipAlignEnabled true
}
release {
minifyEnabled true
shrinkResources true
zipAlignEnabled true
}
I have tried to add the following things in progaurd-rules.pro file to keep these at run time.
Reference: https://stackoverflow.com/a/34807601/2462531
-keep class com.esri.** { *; }
-keep interface com.esri.** { *; }
-keep class org.codehaus.jackson.** { *; }
-dontwarn org.codehaus.jackson.map.ext.**
-dontwarn jcifs.http.**
But still am facing the same issue when I run the app getting crashed with the following error message:
JNI DETECTED ERROR IN APPLICATION: JNI FindClass called with pending exception java.lang.ClassNotFoundException: Didn't find class "com.esri.arcgisruntime.ArcGISRuntimeEnvironment" on path: DexPathList
Need any link or suggestion to ESRI progaurd rules would be appreciated.
The problem got resolved by
Uninstall and reinstall
;)
It took a while after significant revenue loss to find out that Android R8 code shrinker prevents Amazon In-App Purchasing (IAP) 2.0 from working. Android Studio uses R8 by default now. Fortunately, the following in gradle.properties seems to be able to stop R8:
android.enableR8=false
I fear R8 will be mandated in the future, and it will be a disaster. I am trying to find a way to make them compatible.
Someone posted a similar question on Amazon's forum that is supposed to be the best place for such questions, but I have a feeling that Amazon has stopped supporting the forum because my recent two questions there have received no response from Amazon.
I have the following in proguard-project.txt that is used by R8
#amazon
-dontwarn com.amazon.**
-keep class com.amazon.** {*;}
-keepattributes *Annotation*
-optimizations !code/allocation/variable
-optimizationpasses 1
As my understanding, R8 ignores optimizationpasses. I suspect that is the cause.
Edit(2019-05-30)
The aforementioned script for proguard-project.txt is from Amazon's document for In-App Purchasing
The app's build.gradle has the following:
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
signingConfig signingConfigs.Release
}
proguard-android.txt uses -dontoptimize, so it shouldn't be optimizing at all with ProGuard or R8, regardless of the number of -optimizationpasses specified. If you are interested, you can see the available default ProGuard files under build/intermediates/proguard-files/. proguard-android-optimize.txt is the one that would allow optimization.
At this point, given that R8's optimization doesn't seem to be on, I'm not sure if there's much of a workaround. I'd recommend that you file an issue with Google's Issue Tracker, giving as much detail as you can to help them reproduce the issue. They are generally pretty responsive to issues like this.
Should work now with R8, add this to your main build.gradle dependencies:
buildscript {
repositories {
maven {
url 'http://storage.googleapis.com/r8-releases/raw'
}
}
dependencies {
classpath 'com.android.tools:r8:1.6.42' //Must be before the Gradle Plugin for Android. - Or any other version
classpath 'com.android.tools.build:gradle:...'
}
}
build.gradle
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
proguard-rules.pro
-dontwarn com.amazon.**
-keep class com.amazon.** {*;}
-keepattributes *Annotation*
-dontoptimize
gradle.properties
# Disables R8 for Android Library modules only.
android.enableR8.libraries = false
# Disables R8 for all modules.
android.enableR8 = false
This works for me.
I have a payment application with payumoney integration. It was working fine until i added the proguard. Recently I have added Proguard to my build.gradle file (Module: app)
` buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}`
After this App gets closed when i proceed to payment. It is working fine when i Changed minifyEnabled to false.
Following is my Module:PayuMoneySdk Build.gradle File
`buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}`
How can I solve this issue? I can't disable proguard.
Can I enable proguard to only Module:app? And will it solve the issue?
I am new to programming. Please help!!
The solution is to look up for the methods and classess that needs to be exempted and add them to the proguard rules as follows..
-keep class com.mm.** {*;}
-keep class com.company.** {*;}
-keepclassmembers class com.mm.** {*;}
-keepclassmembers class com.company.** {*;}
add below lines in proguard-rule.pro file
-dontwarn okio.**
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
-keep class com.** { *; }
when i try to set the minifyEnabled to true and try to sync gradle file i receive the follwoing error:
Error:Cause: com/android/build/gradle/tasks/AndroidProGuardTask
why i am receiving this error and how to solve it, I cant enable proGaurd in Android Studio.
build.gradle:
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
are you using any external library files in your project? If yes, the you need to add -keep in the proguard-rules.pro file.
I have added the following code to the file:
-keep public class org.jsoup.** {
public *;
}
my proguard-rules.profile can be found here.
You can also make sure the error is because of this by disabling the minifyEnabled to false in the proguard-rules.pro file.
add this to your proguard
-dontwarn package name of you library.**
in your case use package name of Jama
for example
-dontwarn org.slf4j.**
-dontwarn org.apache.log4j.**
-dontwarn org.apache.commons.logging.**
if you can paste more error or stacktrace I will try to help more
This is my first project in Android Studio, and the code of my apps are not obfuscated.
Im using this configuration in build.gradle file:
I'm using the Build > Generate Signed APK... with the Run Proguard checked.
And, when I have tested using the Apk_OneClick.v4.2, my code is completly easy to read:
Please, help-me. :(
You're probably not actually signing the release build of the APK via the signing wizard. You can either build the release APK from the command line with the command:
./gradlew assembleRelease
or you can choose the release variant from the Build Variants view and build it from the GUI:
You can configure your build.gradle file for proguard implementation. It can be at module level or the project level.
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
The configuration shown is for debug level but you can write you own build flavors like shown below inside buildTypes:
myproductionbuild{
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
Better to have your debug with minifyEnabled false and productionbuild and other builds as minifyEnabled true.
Copy your proguard-rules.txt file in the root of your module or project folder like
$YOUR_PROJECT_DIR\YoutProject\yourmodule\proguard-rules.txt
You can change the name of your file as you want. After configuration use one of the three options available to generate your build as per the buildType
Go to gradle task in right panel and search for assembleRelease/assemble(#your_defined_buildtype) under module tasks
Go to Build Variant in Left Panel and select the build from drop down
Go to project root directory in File Explorer and open cmd/terminal and run
Linux ./gradlew assembleRelease or assemble(#your_defined_buildtype)
Windows gradlew assembleRelease or assemble(#your_defined_buildtype)
You can find apk in your module/build directory.
More about the configuration and proguard files location is available at the link
http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Running-ProGuard
NB.: Now instead of
runProguard false
you'll need to use
minifyEnabled false
Here is Some of Most Common Proguard Rules that you need to add in proguard-rules.pro file in Android Sutdio.
ButterKnife
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
#butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
#butterknife.* <methods>;
}
Retrofit
-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepattributes Signature
-keepattributes Exceptions
OkHttp3
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Gson
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
Code obfuscation
-keepclassmembers class com.yourname.models** { <fields>; }
Try renaming your 'proguard-rules.txt' file to 'proguard-android.txt' and remove the reference to 'proguard-rules.txt' in your gradle file. The getDefaultProguardFile(...) call references a different default proguard file, one provided by Google and not that in your project. So remove this as well, so that here the gradle file reads:
buildTypes {
release {
runProguard true
proguardFile 'proguard-android.txt'
}
}
The other answers here are great references on using proguard. However, I haven't seen an issue discussed that I ran into that was a mind bender. After you generate a signed release .apk, it's put in the /release folder in your app but my app had an apk that wasn't in the /release folder. Hence, I spent hours decompiling the wrong apk wondering why my proguard changes were having no affect. Hope this helps someone!
Enable ProGuard
[ProGuard flow]
android {
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard-rules.pro'
}
}
}
[ProGuard artefact]