SIMMORSAL
SIMMORSAL

Reputation: 1674

MultiDex problem with Android Studio 3.6 when implementing it the right way

I updated my Android Studio to 3.6 and In one project I have problems with MultiDex and I keep getting this error with Calligraphy and one other library:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.tivasot.book, PID: 7730
    java.lang.NoClassDefFoundError: Failed resolution of: Luk/co/chrisjenx/calligraphy/R$attr;
        at uk.co.chrisjenx.calligraphy.CalligraphyConfig$Builder.<init>(CalligraphyConfig.java:194)
        at com.tivasot.book.Book.onCreate(Book.java:33)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5926)
        at android.app.ActivityThread.access$1100(ActivityThread.java:201)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1657)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6724)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:495)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "uk.co.chrisjenx.calligraphy.R$attr" on path: DexPathList[[zip file "/data/app/com.tivasot.book-LOo7ps1gQoepvwm4tMW5tQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.tivasot.book-LOo7ps1gQoepvwm4tMW5tQ==/lib/arm64, /data/app/com.tivasot.book-LOo7ps1gQoepvwm4tMW5tQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)

What I've tried:

This is my gradle file:

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "the.app.id"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled false
        renderscriptSupportModeEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            multiDexKeepFile file('multidex-config.txt')
        }
        debug {
            multiDexKeepFile file('multidex-config.txt')
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    android.applicationVariants.all { variant ->
        variant.outputs.all {
            def appName = "Book"
            outputFileName = appName + ".apk"
        }
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.multidex:multidex:2.0.1'
    ...
}

What else can I do?

EDIT:

I think there's a bug with the new gradle version. I downgraded from 3.6.0 to 3.5.3 in project's gradle file, and in gradle-wrapper.properties, from gradle-5.6.4-all.zip to gradle-5.4.1-all.zip and it's now working fine.

Upvotes: 1

Views: 590

Answers (0)

Related Questions