I am configuring proguard for my project, but getting errors for anonymous classes like:
Warning:mypackage.editor.EditorCard$createView$1$1$2$2: can't find referenced class mypackage.editor.EditorCard$createView$1$1$2
I tried several methods like keeping everything in class, but nothing works.
-keep class mypackage.editor.EditorCard.** { *; }
EditorCard extends AnkoComponent.
How can I fix the error?
Managed to solve it by
removing empty lambda blocks in the given class
changing signing version to v1 (Jar signature)
adding rule
-keepclasseswithmembers class mypackage.editor.EditorCard { *; }
-keep class * extends org.jetbrains.anko.AnkoComponent
You can add this line to your proguard-rules.pro
-keep com.alkymia.** { *; }
Related
When creating a APK with proguard enabled, the following exception is thrown when using the FirebaseRecyclerAdapter from the Firebase-UI library (com.firebaseui:firebase-ui:0.3.0):
java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.view.View]
at com.firebase.ui.FirebaseRecyclerAdapter.onCreateViewHolder(FirebaseRecyclerAdapter.java:168)
The debug version (without proguard) works fine. Who has a working proguard config for Firebase-UI?
My current proguard config looks like this (only the Firebase related parts):
-optimizationpasses 5
-keepattributes SourceFile,LineNumberTable,Exceptions, Signature, InnerClasses,*Annotation*
-keepnames class ** { *; }
-keep class com.firebase.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
Solved this by moving the ViewHolder classes that are used by the FirebaseRecyclerAdapter to a dedicated package (e.g. com.mypackage.myapp.viewholders) and adding a rule within the proguard configuration to prevent that classes within this package become obfuscated by proguard:
-keep class com.mypackage.myapp.viewholders.** { *; }
Well, I had my ViewHolder inside relative FirebaseRecyclerAdapter as an inner class and gave me this error. Making the inner class has solved the problem.
Also https://github.com/firebase/FirebaseUI-Android/issues/46#issuecomment-167373575 states same thing with an addition.
Inner class ViewHolder must be public and static so that it could be initiated via reflection.
When I am trying to use the sealedSubClasses attribute of a reified class in Kotlin, it only works in my debug and not in my release build. I guess this is a problem with ProGuard, but I don't know how to fix this. I already tried keeping all classes in the module where the sealed class is, but I am having no luck with this. The sealedSubClasses property always returns an empty list.
Found two ways to fix this issue:
Add rule to your proguard-rules.pro file:
-keep class com.example.ClassName { *; }
-keep class com.example.ClassName$* { *; }
Use #Keep annotation:
#Keep
sealed class ClassName{
#Keep
object A : ClassName()
#Keep
object B : ClassName()
}
This one didn't work for me:
-keep class kotlin.Metadata { *; }
Also there is a bug https://issuetracker.google.com/issues/169264693 that could be the part of your problem.
You can try
-keep class kotlin.Metadata { *; }
to get missing attributes from your class
Add an additional rule to your proguard file:
-keepnames class com.fully.qualified.ClassName* {
*;
}
Notice the asterisk character.
I have a multi-module project (I use Android App Bundles) with data-binding, ViewModel. But when I enable Proguard the app crashes with the following error :
java.lang.RuntimeException: Unable to start activity ComponentInfo{...MyActivity}: java.lang.IllegalStateException: DataBindingUtil.setConte… R.layout.my_activity) must not be null
Caused by: java.lang.IllegalStateException: DataBindingUtil.setConte… R.layout.my_activity) must not be null
at MyActivity.onCreate(MyActivity.kt:38)
When I remove modules and create one app module, everything works. When I disable Proguard, it also works fine.
Here is part of my proguard-rules.pro:
-dontwarn android.databinding.**
-keep class android.databinding.** { *; }
-keep class com.example.module1.databinding.** { *; }
-keep class com.example.module2.databinding.** { *; }
In build.gradle:
minifyEnabled true
useProguard true
So the error points to this line of code:
val binding: com.example.module1.databinding.MyActivityBinding =
DataBindingUtil.setContentView(this, R.layout.my_activity)
Maybe any ideas how to fix?
Only need to add this to your proguard-rules.pro, where module1 and module2 are Dynamic Feature Modules with databinding enabled.
-keep class com.example.module1.DataBinderMapperImpl { *; }
-keep class com.example.module2.DataBinderMapperImpl { *; }
I don't really know why but for me, the following combination worked:
-dontwarn androidx.databinding.**
-keep class androidx.databinding.** { *; }
-keep class * extends androidx.databinding.DataBinderMapper
I tried using just -keep class * extends androidx.databinding.DataBinderMapper but it didn't work.
Also I tried using
-dontwarn androidx.databinding.**
-keep class androidx.databinding.** { *; }
but that didn't work either.
What worked was a combination of the three.
if you enable to view merged proguard file using
-printconfiguration proguard-merged-config.txt
You will see something like this is there to keep DataBinderMapperImp
# instant apps load these via reflection so we need to keep them.
-keep public class * extends android.databinding.DataBinderMapper
I think what is missung is androidx version
I added this line it working fine now
-keep class * extends androidx.databinding.DataBinderMapper { *; }
This worked for me
-keep class * extends androidx.databinding.DataBinderMapper { *; }
When creating a APK with proguard enabled, the following exception is thrown when using the FirebaseRecyclerAdapter from the Firebase-UI library (com.firebaseui:firebase-ui:0.3.0):
java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.view.View]
at com.firebase.ui.FirebaseRecyclerAdapter.onCreateViewHolder(FirebaseRecyclerAdapter.java:168)
The debug version (without proguard) works fine. Who has a working proguard config for Firebase-UI?
My current proguard config looks like this (only the Firebase related parts):
-optimizationpasses 5
-keepattributes SourceFile,LineNumberTable,Exceptions, Signature, InnerClasses,*Annotation*
-keepnames class ** { *; }
-keep class com.firebase.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
Solved this by moving the ViewHolder classes that are used by the FirebaseRecyclerAdapter to a dedicated package (e.g. com.mypackage.myapp.viewholders) and adding a rule within the proguard configuration to prevent that classes within this package become obfuscated by proguard:
-keep class com.mypackage.myapp.viewholders.** { *; }
Well, I had my ViewHolder inside relative FirebaseRecyclerAdapter as an inner class and gave me this error. Making the inner class has solved the problem.
Also https://github.com/firebase/FirebaseUI-Android/issues/46#issuecomment-167373575 states same thing with an addition.
Inner class ViewHolder must be public and static so that it could be initiated via reflection.
I'm trying to configure Proguard, but I can't manage to get it working.
This is the error:
I've tried things like:
-keep class com.android.auth.TwitterHandle.** { *; }
-keep class oauth.** { *; }
Without any luck.
Anyways, I don't really think ignoring is the answer. Because that might mean something is broken.
Any tips?
Thanks!
The warnings indicate that the AndroidQuery library depends on the OAuth library. Apparently, you're using the former library in your project, but the latter library is missing. You could add the missing library, but if your application is working fine without it in debug mode, you can just tell ProGuard to ignore the missing dependency. In this case:
-dontwarn com.androidquery.auth.**
or, to the same effect:
-dontwarn oauth.signpost.**
See the ProGuard manual > Troubleshooting > Warning: can't find referenced class
(I am the developer of ProGuard)
Add these lines to your proguard file.
-dontwarn oauth.**
-dontwarn com.android.auth.TwitterHandle.**
-keep class oauth.** { *; }
-keep class com.android.auth.TwitterHandle.** { *; }
Edit:
Anyways, I don't really think ignoring is the answer. Because that
might mean something is broken.
If you want to use Proguard and you are having some errors such as class not found, then you must disable/ignore their obfuscation. Because Proguard renames names, fields and methods of classes while obfuscating. This becomes a big problem if reflection is used for that classes. So you have to say proguard to ignore(not obfuscate) some classes to prevent this problem.
Please try this post https://stackoverflow.com/a/15477898/1665964
Insert to skip obfuscated in ProGuard your libs, jars, Classes and Subclasses with this example
-optimizationpasses 5
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-allowaccessmodification
-repackageclasses ''
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.MapActivity
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-libraryjars libs/commons-io-2.2.jar
-libraryjars libs/gson-2.2.2.jar
-keep public class org.apache.commons.io.**
-keep public class com.google.gson.**
-keep public class com.google.gson.** {public private protected *;}
##---------------Begin: proguard configuration for Gson ----------
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.mypackage.ActivityMonitor.ClassMultiPoints.** { *; }
-keep public class com.mypackage.ActivityMonitor$ClassMultiPoints { public protected *; }
-keep public class com.mypackage.ActivityMonitor$ClassMultiPoints$ClassPoints { public protected *; }
-keep public class com.mypackage.ActivityMonitor$ClassMultiPoints$ClassPoints$ClassPoint { public protected *; }
##---------------End: proguard configuration for Gson ----------
The reason for error must be that you might be using an external jar file (in libs folder).
If this is the case, adding the following line before -keep class ... lines should solve your problem.
-libraryjars libs/<jar_filename>
If u are unfamiliar with proguard cmd tool then you can try proguard gui located at tools/proguard/lib/proguardgui of your android SDK folder.
open proguardgui and load your configuration file.
then in Input / output section add your input and output jar as well as add your android lib used in your project.
***** your main problem is that you havent added your library (Aquery.jar and others) jar that is used in your project , so that proguard can't find the required Classes.***