Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Didn't find .MyApp class on path: DexPathList. Only if running debug apk directly

I've searched around for the solution and there are several related to ClassNotFoundException threads like this on SO. But I tried solutions provided there and nothing helped. So in my case when deploying app to a device directly from Android Studio it runs normally, although it crashes when installing from file: adb install app-debug.apk.

03-08 16:45:59.303 32233-32233/us.kostenko.glagol.debug E/AndroidRuntime: FATAL EXCEPTION: main
                                                                          Process: us.kostenko.glagol.debug, PID: 32233
                                                                          java.lang.RuntimeException: Unable to instantiate application us.kostenko.glagol.di.application.MyApp: java.lang.ClassNotFoundException: Didn't find class "us.kostenko.glagol.di.application.MyApp" on path: DexPathList[[zip file "/data/app/us.kostenko.glagol.debug-1/base.apk"],nativeLibraryDirectories=[/data/app/us.kostenko.glagol.debug-1/lib/arm64, /vendor/lib64, /system/lib64]]
                                                                              at android.app.LoadedApk.makeApplication(LoadedApk.java:565)
                                                                              at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4561)
                                                                              at android.app.ActivityThread.access$1500(ActivityThread.java:154)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                              at android.os.Looper.loop(Looper.java:135)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5298)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at java.lang.reflect.Method.invoke(Method.java:372)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:913)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:708)
                                                                           Caused by: java.lang.ClassNotFoundException: Didn't find class "us.kostenko.glagol.di.application.MyApp" on path: DexPathList[[zip file "/data/app/us.kostenko.glagol.debug-1/base.apk"],nativeLibraryDirectories=[/data/app/us.kostenko.glagol.debug-1/lib/arm64, /vendor/lib64, /system/lib64]]
                                                                              at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                              at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                                                              at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                                                                              at android.app.Instrumentation.newApplication(Instrumentation.java:980)
                                                                              at android.app.LoadedApk.makeApplication(LoadedApk.java:560)
                                                                              at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4561) 
                                                                              at android.app.ActivityThread.access$1500(ActivityThread.java:154) 
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380) 
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                              at android.os.Looper.loop(Looper.java:135) 
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5298) 
                                                                              at java.lang.reflect.Method.invoke(Native Method) 
                                                                              at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:913) 
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:708) 
                                                                            Suppressed: java.lang.ClassNotFoundException: us.kostenko.glagol.di.application.MyApp
                                                                              at java.lang.Class.classForName(Native Method)
                                                                              at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
                                                                              at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
                                                                              at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                                                                                    ... 13 more
                                                                           Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

AndroidManifest.xml

  <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="us.kostenko.glagol">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<!-- For download manager -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
    android:name=".di.application.MyApp"
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".SplashActivity"
        android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label=""
        android:theme="@style/AppTheme.NoActionBar"
        android:screenOrientation="portrait"
        android:launchMode="singleTop">
    </activity>
    <activity
        android:name=".personal.SignInActivity"
        android:label="@string/title_activity_sign_in"
        android:theme="@style/AppTheme.NoActionBar"
        android:screenOrientation="portrait"/>
    <activity
        android:name=".payment.PaymentActivity"
        android:label="@string/title_activity_payment"
        android:theme="@style/AppTheme.NoActionBar"
        android:screenOrientation="portrait">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity" />
    </activity>
    <service
        android:name=".catalog.service.BookFilesService"
        android:exported="false"
        android:description="@string/about_detail_book_service"/>
    <service
        android:name=".player.PlayerService"
        android:exported="false"
        android:description="@string/about_play_book_service"/>
</application>

and build.gradle:

    apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def superpowered_sdk_path = properties.getProperty('superpowered.dir')

android {
    signingConfigs {
        config {
           ...
        }
    }
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion
    defaultConfig {
        applicationId "us.kostenko.glagol"
        minSdkVersion rootProject.minSdkVersion
        targetSdkVersion rootProject.targetSdkVersion
        versionCode 2
        versionName "1.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
            // these platforms cover 99% percent of all Android devices
        }

        externalNativeBuild {
            cmake {
                arguments '-DANDROID_PLATFORM=android-16', '-DANDROID_TOOLCHAIN=clang', '-DANDROID_ARM_NEON=TRUE', '-DANDROID_STL=gnustl_static', "-DPATH_TO_SUPERPOWERED:STRING=${superpowered_sdk_path}"
                cFlags '-O3', '-fsigned-char' // full optimization, char data type is signed
                cppFlags '-fsigned-char', "-I${superpowered_sdk_path}"
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            applicationIdSuffix ".debug"
        }
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
        main {
            jniLibs.srcDirs = ['src/main/jni']
        }
    }
    externalNativeBuild {
        cmake {
            path 'src/main/jni/CMakeLists.txt'
        }
    }
}

kapt {
    generateStubs = true
}

repositories {
//    maven { url 'https://github.com/linchaolong/stetho-realm/raw/master/maven-repo' }
    mavenCentral()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion"
    compile "com.android.support:design:$rootProject.ext.supportLibraryVersion"
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'


    testCompile 'junit:junit:4.12'
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    /* Rx - reactive extensions
                https://github.com/ReactiveX/RxAndroid */
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'io.reactivex:rxjava:1.1.6'
    /* Retrofit - networking
                * http://square.github.io/retrofit/ */
    compile "com.squareup.retrofit2:retrofit:$rootProject.ext.retrofit2Version"
    compile "com.squareup.retrofit2:converter-gson:$rootProject.ext.retrofit2Version"
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
    /* Gson - json parsing
                * https://github.com/google/gson */
    compile 'com.google.code.gson:gson:2.7'
    /* OkHttp3 - http client
                * http://square.github.io/okhttp/ */
    compile "com.squareup.okhttp3:okhttp:$rootProject.ext.okhttpVersion"
    compile "com.squareup.okhttp3:logging-interceptor:$rootProject.ext.okhttpVersion"
    /* Dagger 2 - DI
                https://github.com/codepath/android_guides/wiki/Dependency-Injection-with-Dagger-2*/
    compile 'com.google.dagger:dagger:2.8'
    kapt "com.google.dagger:dagger-compiler:2.4"
    provided 'org.glassfish:javax.annotation:10.0-b28'

    /* Glide - image loading lib
                 https://github.com/bumptech/glide */
    compile 'com.github.bumptech.glide:glide:3.7.0'integration:1.4.0@aar'
    compile "com.android.support:support-v4:$rootProject.ext.supportLibraryVersion"
    /* Realm */
    compile 'io.realm:android-adapters:1.3.0'

    compile 'de.cketti.mailto:email-intent-builder:1.0.0'
    compile 'com.roughike:bottom-bar:2.1.1'
}
repositories {
    mavenCentral()
}

I do have that class MyApp in the project. That log doesn't make anything clear for me. I've noticed the problem after updating Android Studio to 2.3 and updating some dependencies in the project. Before it worked fine.

I will appreciate any help in solving this issue.

Edit: After some trials I've found out that the way I create a build makes difference. If I build my project with Build/Build APK and adb install app-debug.apk it won't throw an exception. But every time I use Run/Run 'app' option to deploy the app to the device, installing apk created this way through terminal results in a crash with mentioned exception. Is it intended behaviour or a bug?

Also worth noticing that Build/Clean project fixes the problem for the next build.

like image 951
AlexKost Avatar asked Oct 29 '22 11:10

AlexKost


1 Answers

It is an intended behaviour. If Instant run feature is enabled, AS would build a special kind of an apk, only with recent changes. So, in order to build an apk that is able to run with adb install app-debug.apk command one should build an apk with Build/Build APK.

like image 142
AlexKost Avatar answered Nov 02 '22 22:11

AlexKost