:无法在共享apk时实例化应用程序和ClassNotFound

时间:2017-03-11 14:24:10

标签: android android-gradle

当我从android studio运行应用程序时,它在模拟器和设备中运行良好。

但是当我分享apk的调试/发布版本时,当用户点击应用程序图标时它就崩溃了。

跟随我在日志中看到的错误

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

已阅读很多帖子,但从早上起,对我来说没有任何作用。

在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'

我正在使用android studio 2.3因此gradle版本为gradle-3.3-all.zip

2 个答案:

答案 0 :(得分:2)

我今天遇到了同样的问题,我目前已降级我的gradle版本并且生成的调试apk工作正常,感觉它可能是gradle版本的问题,如果我发现实际问题,将更新此答案

但目前将gradle从2.3.0降级到2.2.0似乎解决了这个问题。

答案 1 :(得分:2)

我与我的某个应用程序的调试apk发生了同样的崩溃。发布版本(使用发布密钥签名)有效。 我的应用使用了multidex。

我最终在Android Studio中禁用了Instant Run(文件 - >设置 - >构建 - >即时运行),重建后调试apk也运行良好!

在此处找到此解决方案: https://codentrick.com/cant-run-app-on-device-when-it-installed-from-debug-apk-file/