Skip to content
Advertisement

Gradle migration 3.1.4 -> 3.5.1; :app module doesn’t compile; ClassNotFoundException: Didn’t find class on path: DexPathList

I have two applications where I face the same issue while trying to update project target API from 27 to 29. To do this, first I need to update Gradle plugin at least to 3.2.+.

Project is building fine with 3.1.4, but as soon as I rise Gradle plugin to: classpath 'com.android.tools.build:gradle:3.5.1 distributionUrl=https://services.gradle.org/distributions/gradle-5.4.1-all.zip (Same error with 3.2.1 and higher)

I see next RunTime exception:

Process: com.my.app, PID: 29804
java.lang.RuntimeException: Unable to instantiate application com.my.app: java.lang.ClassNotFoundException: Didn't find class "com.my.app" on path: DexPathList[[zip file "/data/app/com.my.app-Y6_GNyscecqK5BtUnp_kjQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.my.app-Y6_GNyscecqK5BtUnp_kjQ==/lib/x86, /data/app/com.my.app-Y6_GNyscecqK5BtUnp_kjQ==/base.apk!/lib/x86, /system/lib]]

A problem that :app module source code is not compiled at all (I can create manual compilation error and run will be still successful)

The same in both application. What I tired:

  • I checked generated DEX files in the APK, source code is not there;
  • I create a new project with 3.5.1 plugin – it works fine;
  • Tried to delete gradle and .idea folders;
  • Tried to to clean and invalidate cache
  • Migrated project to AndroidX;
  • Added multiDexEnabled true – it was working without it before, anyway;
  • Copied dependencies to a new Project – works fine;
  • Added: to gradle.properties android.useAndroidX=true android.enableJetifier=true

My build files:

TOP level

buildscript {
    ext.kotlin_version = '1.3.41'
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "io.realm:realm-gradle-plugin:6.0.0"
        classpath 'com.google.gms:google-services:4.3.2'
        classpath 'io.fabric.tools:gradle:1.31.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.google.com/'
        }
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

Application:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
apply plugin: 'io.fabric'
android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.my.app"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 2
        versionName "1.01"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled = true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
}
ext.anko_version='0.10.5'
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.gridlayout:gridlayout:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.preference:preference:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
    implementation 'com.facebook.fresco:fresco:1.2.0'
    implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
    implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.0'
    implementation "org.jetbrains.anko:anko-sdk21:$anko_version"
    implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
    implementation "org.jetbrains.anko:anko-constraint-layout:$anko_version"
    implementation "org.jetbrains.anko:anko-recyclerview-v7:$anko_version"
    implementation "org.jetbrains.anko:anko-recyclerview-v7-coroutines:$anko_version"
    implementation "org.jetbrains.anko:anko-cardview-v7:$anko_version"
    implementation 'com.r0adkll:slidableactivity:2.0.6'
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.1'
    releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'
    debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
    kapt "io.realm:realm-annotations-processor:5.9.0"
}
apply plugin: 'com.google.gms.google-services'

Note: another project has different set of dependencies still face the same issue

Why source code is not added to APK after migration to newer Gradle while working fine on the old one?

Update 1 Problem appear as soon as I update project to Gradle 3.2+

Update 2 Build folder doesn’t contain class folder and class files

Update 3 Source code from :app module doesn’t compile even tho it is in the settings.gradle file; I can create build error in any .java file and run will be executed successfully

Advertisement

Answer

I found an issue: One of my packages name vas cvs – seems it is after Gradle 3.2.+ it is reserved word.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement