Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidX build issue with ProGuard

CLOSED

We are trying to integrate android library (which is compiling android support library) in our project that has been migrated to androidX. And for unknown reason we are getting

can't find referenced method 'void addOnTabSelectedListener(com.google.android.material.tabs.TabLayout$OnTabSelectedListener)' in program class com.google.android.material.tabs.TabLayout

while trying to get a proguard enabled build.

gradle-wrapper: 4.8

gradle build tools : 3.2.0

compileSdkVersion 28

EDIT 9-Oct-2018

For some reason, it was a proguard issue, proguard was showing wrong error, after we made some changes in our sourcecode, and forgot to add some classes to proguard, it changed the errors with the classes that we forgot to add. and after adding them everything went good.

like image 647
Mohamed Zakaria El-Zoghbi Avatar asked Oct 01 '18 13:10

Mohamed Zakaria El-Zoghbi


People also ask

How do I debug a ProGuard error?

To debug Proguard/R8 configuration, navigate to app\build\outputs\mapping\release. There we can see the following files: configuration. txt – merged file with all configurations – from the app, default Android, AAPT, all the libraries, etc.

Does R8 use ProGuard?

January 11, 2022. R8 is a tool that is used to shrink, secure, and optimize Android applications. It uses proguard rules to change the behavior of application.

How do I enable R8 on my Android?

To enable R8 shrinking in your application, set the minifyEnabled to true in your app's main build. gradle file.


1 Answers

I think that you should tell to proguard to not obfuscate material classes. But this is just a workaround, you have some other issue so try to fix it.

Try to add these lines in your proguardrules.pro file:

-keep class com.google.android.material.** { *; }

-dontwarn com.google.android.material.**
-dontnote com.google.android.material.**

-dontwarn androidx.**
-keep class androidx.** { *; }
-keep interface androidx.** { *; }

Then, in your build.gradle

buildscript {
    repositories {
        maven {
            url "http://storage.googleapis.com/r8-releases/raw/master"
        }
    }

    dependencies {
        classpath 'com.android.tools:r8:ff9c89416cc1c8adf83d481a1e5fd515fcb893b9'
        classpath 'com.android.tools.build:gradle:your version'
    }
}
like image 73
Roberto Manfreda Avatar answered Oct 12 '22 06:10

Roberto Manfreda