Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

: Unable to instantiate application and ClassNotFound while sharing apk

when i run the app from android studio it runs fine in simulator and device.

but when i share the debug / release version of apk it got crashed when user taps on a app icon.

following the error that i can see in logs

03-11 09:16:12.654 25384-25384/com.microtechnicianapp E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.microtechnicianapp, PID: 25384
      java.lang.RuntimeException: Unable to instantiate application com.microtechnicianapp.App: java.lang.ClassNotFoundException: Didn't find class "com.microtechnicianapp.App" on path: DexPathList[[zip file "/data/app/com.microtechnicianapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.microtechnicianapp-1/lib/x86, /vendor/lib, /system/lib]]
          at android.app.LoadedApk.makeApplication(LoadedApk.java:563)
          at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4491)
          at android.app.ActivityThread.access$1500(ActivityThread.java:144)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:135)
          at android.app.ActivityThread.main(ActivityThread.java:5221)
          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:899)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
       Caused by: java.lang.ClassNotFoundException: Didn't find class "com.microtechnicianapp.App" on path: DexPathList[[zip file "/data/app/com.microtechnicianapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.microtechnicianapp-1/lib/x86, /vendor/lib, /system/lib]]
          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:979)
          at android.app.LoadedApk.makeApplication(LoadedApk.java:558)
          at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4491) 
          at android.app.ActivityThread.access$1500(ActivityThread.java:144) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339) 
          at android.os.Handler.dispatchMessage(Handler.java:102) 
          at android.os.Looper.loop(Looper.java:135) 
          at android.app.ActivityThread.main(ActivityThread.java:5221) 
          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:899) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
        Suppressed: java.lang.ClassNotFoundException: com.microtechnicianapp.App
          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

have read lot of threads but nothing works for me since morning.

have tried lot of things in gradle

apply plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt' apply plugin: 'realm-android' android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'
    defaultConfig {
        applicationId "com.microtechnicianapp"
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 1
        versionName "1.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dexOptions {
        preDexLibraries false
    } } repositories {
    maven {
        url  "http://dl.bintray.com/lukaville/maven"
    } }




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:design:25.0.0'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.bluelinelabs:logansquare:1.3.6'
    compile 'com.github.aurae.retrofit2:converter-logansquare:1.4.1'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'com.google.firebase:firebase-messaging:9.8.0'
    compile 'com.google.android.gms:play-services-maps:9.8.0'
    compile 'com.google.android.gms:play-services-location:9.8.0'
    compile 'com.github.gcacace:signature-pad:1.2.0'
    compile 'com.github.davidpizarro:autolabelui:1.0.1'
    compile 'com.nbsp:library:1.1'
    compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
    compile 'com.google.zxing:core:3.2.1'
    testCompile 'junit:junit:4.12'
    apt 'com.bluelinelabs:logansquare-compiler:1.3.6'
    compile 'com.google.android.gms:play-services-appindexing:9.8.0'
    compile 'com.mikhaellopez:circularprogressbar:1.1.1'
    compile 'com.android.support:multidex:1.0.0'


}


apply plugin: 'com.google.gms.google-services'

I am using android studio 2.3 hence gradle version is gradle-3.3-all.zip

like image 341
Hunt Avatar asked Mar 11 '17 14:03

Hunt


2 Answers

I faced the same issue today, I have currently downgraded my gradle version and the generated debug apk works just fine, Feel like it might be an issue with the gradle version, will Update on this answer if i find with the actual issue.

But currently downgrading gradle from 2.3.0 to 2.2.0 seems to fix the issue.

like image 156
Ajay Avatar answered Oct 08 '22 09:10

Ajay


I had the same crash with the debug apk of one of my apps. The release version (signed with release key) worked. My app uses multidex.

I ended up disabling Instant Run in Android Studio (File -> Settings -> Build -> Instant Run) and after a rebuild the debug apk worked as well!

Found this solution here: https://codentrick.com/cant-run-app-on-device-when-it-installed-from-debug-apk-file/

like image 32
threesn Avatar answered Oct 08 '22 09:10

threesn