Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidX on Android Studio 3.2 - VerifyError when running app

Migrated my app to AndroidX libraries on Android Studio 3.2. When running in debug, everything works as expected but if I generate a signed APK, obfuscated using Proguard - I get this error:

java.lang.VerifyError: Verifier rejected class d.a: androidx.preference.Preference d.a.a(androidx.fragment.app.k, int)
failed to verify: androidx.preference.Preference d.a.a(androidx.fragment.app.k, int): [0x8] ‘this’ argument ‘Reference:
androidx.fragment.app.k’ not instance of ‘Reference: 
androidx.preference.B’ (declaration of ‘d.a’ appears in base.apk)

I've tried excluding all AndroidX libraries:

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

But the issue continues unless I basically cancel the obfuscation using

-keep class com.myapp.package.** { *; }

Also tried looking at the mapping file for what class d.a is but it didn't hint me to the direction of the issue.

Jetifier is enabled

android.useAndroidX=true
android.enableJetifier=true

Am I missing something here? Any chance this is an issue with the androix.preference library?

  • Opened a bug on Google issue tracker.
like image 306
Lior Iluz Avatar asked Aug 26 '18 18:08

Lior Iluz


1 Answers

Solved.

Add android.enableR8=false to your project gradle.properties file and everything will work as expected.

Notice, this is not the infamous d8 error. R8 is a new tool for code shrinking and obfuscation that replaces ProGuard, and it's enabled by default on Android Studio 3.2 canary.

Option #2: (This was provided by Google)

If you want to use R8 shrinker, edit your project build.gradle like this: (notice the r8 classpath MUST be above the build tools classpath)

buildscript {
     repositories {
        jcenter()
        google()

        maven {
            url "http://storage.googleapis.com/r8-releases/raw/master"
        }
    }
    dependencies {
        classpath 'com.android.tools:r8:ff9c89416cc1c8adf83d481a1e5fd515fcb893b9'
        classpath 'com.android.tools.build:gradle:3.3.0-alpha08'
    }
}
like image 54
Lior Iluz Avatar answered Nov 15 '22 16:11

Lior Iluz