java.lang.RuntimeException:无法在安装时实例化应用程序

时间:2017-09-21 11:10:42

标签: android classnotfoundexception runtimeexception

我面临着奇怪的问题。当我通过USB在手机上安装应用程序时,它可以工作。但是,当我转移apk并在手机上手动安装时,它会抛出错误。

java.lang.RuntimeException: Unable to instantiate application com.xx.merchant.application.MerchantApplication: java.lang.ClassNotFoundException: Didn't find class "com.xx.merchant.application.MerchantApplication" on path: DexPathList[[zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/base.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_7_apk.apk"],nativeLibraryDirectories=[/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/base.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_1_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_2_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_3_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_7_apk.apk!/lib/x86, /system/lib, /system/vendor/lib]]
                                                       at android.app.LoadedApk.makeApplication(LoadedApk.java:948)
                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5764)
                                                       at android.app.ActivityThread.-wrap1(Unknown Source:0)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
                                                       at android.os.Handler.dispatchMessage(Handler.java:105)
                                                       at android.os.Looper.loop(Looper.java:164)
                                                       at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.xx.merchant.application.MerchantApplication" on path: DexPathList[[zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/base.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_7_apk.apk"],nativeLibraryDirectories=[/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/base.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_1_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_2_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_3_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_7_apk.apk!/lib/x86, /system/lib, /system/vendor/lib]]
                                                       at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
                                                       at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                                                       at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                       at android.app.Instrumentation.newApplication(Instrumentation.java:1086)
                                                       at android.app.LoadedApk.makeApplication(LoadedApk.java:942)
                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5764) 
                                                       at android.app.ActivityThread.-wrap1(Unknown Source:0) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                       at android.os.Looper.loop(Looper.java:164) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:6540) 
                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
                                                    Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/multidex/MultiDexApplication;
                                                       at java.lang.VMClassLoader.findLoadedClass(Native Method)
                                                       at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
                                                       at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
                                                            ... 12 more
09-21 16:33:04.565 14026-14026/? E/AndroidRuntime:  Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/base.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_7_apk.apk"],nativeLibraryDirectories=[/data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/base.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_1_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_2_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_3_apk.apk!/lib/x86, /data/app/com.xx.merchant-U_VFCFO7rdRHN5OC21N8pg==/split_lib_slice_7_apk.apk!/lib/x86, /system/lib, /system/vendor/lib]]
                                                       at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
                                                       at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                                                       at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                            ... 15 more

我的gradle文件

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"

    defaultConfig {
        applicationId 'com.xx.merchant'
        minSdkVersion 17
        targetSdkVersion 26

        versionCode 7
        versionName "1.0.7"

        // Enabling multidex support.
        multiDexEnabled true
    }

    signingConfigs {
        release {
            storeFile file('../keystore/xx.keystore')
            storePassword 'xxx'
            keyAlias "xxx"
            keyPassword 'xxx'
        }
    }


    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        debug {
            signingConfig signingConfigs.release
            minifyEnabled false
        }
    }

    productFlavors {
        production {
            applicationId "com.xx.merchant"
            minSdkVersion 17
            targetSdkVersion 26
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    }

}

repositories {    
    mavenCentral()
    mavenLocal()
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:cardview-v7:26.+'
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support:support-v4:26.+'
    compile 'com.android.support:support-v13:26.+'
    compile 'com.android.support:design:26.+'
}

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

1 个答案:

答案 0 :(得分:0)

向gradle文件添加依赖项

compile 'com.android.support:multidex:1.0.1'

还在MultiDex.install班级

上添加Application
public class YouApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

}