Android Data Binding do not work after proguard - android

Link to project - File manager
After i'm enabling obfuscation, application crash, when i try to show fragment from library project that use data binding.
Error:
java.lang.NoClassDefFoundError: Failed resolution of: Lcorp/wmsoft/android/lib/filemanager/databinding/WmFmFileManagerViewLayoutBinding;
at corp.wmsoft.android.lib.filemanager.ui.widgets.nav.a.onCreateView(Unknown Source)
But Android Studio->Build->Analyze APK, show that i have this class inside APK:
library project proguard-rules.pro:
-dontwarn android.databinding.**
-keep class android.databinding.** { *; }
-keep class corp.wmsoft.android.lib.filemanager.databinding.** { *; }
Please help to solve this problem.

Related

Android ProGuard: Getting an error of 'Use of generics not allowed for java type at '<1>_<2>_<3>JsonAdapter' in line 43 of file ...'

I implemented a library on my gradle that uses Moshi as a dependency. When I tried to compile locally and also creating an android build through jenkins, it shows an error of
Use of generics not allowed for java type at '<1>_<2>_<3>JsonAdapter' in line 43 of file '\.gradle\caches\transforms-1\files-1.1\jetified-moshi-1.9.3.jar\76f6a6d7d5642e8be11f9d49dc24d752\META-INF\proguard\moshi.pro'
I already indicated rules on my proguard.pro file as stated on the documentation of the library I used but still errors are still encountering. I also tried the solution on the issues tab of moshi on github but I still received an error build.
Here's my proguard-rules.pro file
#ChatvisorLibrary
-keep class com.chatvisor.** {*;}
-dontwarn com.chatvisor.**
-dontwarn okhttp3.**
#Dependencies
#Protocol Buffers
-keep class com.google.**
-dontwarn com.google.**
#Moshi (https://github.com/square/moshi/blob/master/moshi/src/main/resources/META-INF/proguard/moshi.pro)
# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**
-keepclasseswithmembers class * {
#com.squareup.moshi.* <methods>;
}
-keep #com.squareup.moshi.JsonQualifier interface *
# Enum field names are used by the integrated EnumJsonAdapter.
# values() is synthesized by the Kotlin compiler and is used by EnumJsonAdapter indirectly
# Annotate enums with #JsonClass(generateAdapter = false) to use them with Moshi.
-keepclassmembers #com.squareup.moshi.JsonClass class * extends java.lang.Enum {
<fields>;
**[] values();
}
-ignorewarnings
-keep class * {
public private protected *;
}
I hope someone could help me and get resolved the issue. Thank you!
Already resolved this issue by upgrading my Proguard version
https://www.guardsquare.com/en/blog/proguard-61-released

ProGuard with AppBundle and data-binding: IllegalStateException

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 { *; }

Class 'org.apache.commons.logging.impl.LogFactoryImpl' cannot be converted to 'org.apache.commons.logging.b'

My android app uses Pushy.me Push notification service, i have built the signed apk with minifyEnabled true and when i run the app i am getting below error
org.apache.commons.logging.LogConfigurationException: The chosen LogFactory implementation does not extend LogFactory. Please check your configuration. (Caused by java.lang.ClassCastException: The application has specified that a custom LogFactory implementation should be used but Class 'org.apache.commons.logging.impl.LogFactoryImpl' cannot be converted to 'org.apache.commons.logging.b'.
i have added below lines in proguard-rules.pro file, but it shows same error
-dontwarn me.pushy.**
-keep class me.pushy.** { *; }
-dontwarn org.apache.commons.logging.**
This worked for me
-keep class org.apache.** { *; }

CrossWalk with ProGuard

I am trying to enable ProGuard on a Cordova/CrossWalk application project.
The project is using a CrossWalk v13 jar rather thank compiling.
I have tried both of the following ProGaurd config options:
https://crosswalk-project.org/documentation/about/faq.html
https://crosswalk-project.org/documentation/embedding_crosswalk.html
I keep getting an 'occasional' startup crash with the following:
Mostly on first launches.
Any suggestions ?
Thanks!
I've added the following to my crosswalk and have not been having issues.
# XWalk
-keep class org.xwalk.core.** { *; }
-keep class org.crosswalk.engine.** { *; }
-keep class org.chromium.** { *; }
-keepattributes **
-dontwarn android.view.**
-dontwarn android.media.**
-dontwarn org.chromium.**
I'm including crosswalk not as a jar but as a gradle dependency by first adding the repo in the repository block:
maven { url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2' }
And then adding the dependency
compile 'org.xwalk:xwalk_core_library_beta:18.48.477.2'

How to make Proguard ignore external libraries?

I want to use Proguard mainly for obfuscation reasons.
My problem is that I have three libraries, Twitter4J and two signpost libraries. These libraries caused errors when I tried to create an signed APK. To get over this I put the following in the proguard.config file...
-dontwarn org.apache.commons.codec.binary.**
-dontwarn org.slf4j.**
-dontwarn com.sun.syndication.io.**
-dontwarn com.sun.syndication.feed.synd.*
While this got rid of the errors in the console, when i loaded my signed APK onto my mobile phone it instantly crashed. The DDMS said this was due to a class not found in Twitter4J.
Getting rid of the "dontwarns" above did not help. Neither did adding dontshrink dontoptimise.
I would like Proguard to completely ignore the libraries (as they are open source anyway). Is this possible?
Try this:
-keep class javax.** { *; }
-keep class org.** { *; }
-keep class twitter4j.** { *; }
Cf post from #CaspNZ:
Android Proguard with external jar
You should be able to add to the proguard.cfg the following lines to exclude all classes within a package (and subpackages)
-keep class org.apache.commons.codec.binary.**
-keep interface org.apache.commons.codec.binary.**
-keep enum org.apache.commons.codec.binary.**
-keep class org.slf4j.**
-keep interface org.slf4j.**
-keep enum org.slf4j.**
-keep class com.sun.syndication.io.**
-keep interface com.sun.syndication.io.**
-keep enum com.sun.syndication.io.**
-keep class com.sun.syndication.feed.synd.**
-keep interface com.sun.syndication.feed.synd.**
-keep enum com.sun.syndication.feed.synd.**
I'd like to add that you should sync your project with Gradle files after adding proguard rules, otherwise they may not work.

Categories

Resources