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

Android java.lang.RuntimeException:无法在安装时实例化应用程序,android,classnotfoundexception,runtimeexception,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.a

我面临着一个奇怪的问题。当我在手机上通过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'
compile 'com.android.support:multidex:1.0.1'

将依赖项添加到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'
compile 'com.android.support:multidex:1.0.1'
同时在
应用程序
类上添加
MultiDex.install

public class YouApplication extends Application {

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

}

将依赖项添加到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'
compile 'com.android.support:multidex:1.0.1'
同时在
应用程序
类上添加
MultiDex.install

public class YouApplication extends Application {

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

}

显示你的gradle应用程序file@NileshRathod请参阅添加的GradleId,您可以将通过USB在Phone上安装应用程序的apk传输到我上传到驱动器上并从中下载there@VVB我认为这实际上是因为Android Studio的即时运行。你应该淡化它。显示你的gradle应用程序file@NileshRathod请参阅添加的GradleId,您可以将通过USB在Phone上安装应用程序的apk传输到我上传到驱动器上并从中下载there@VVB我认为这实际上是因为Android Studio的即时运行。我扩展了MultiDex应用程序类,并尝试了这个,但没有luck@VVB解决这个问题运气好吗?@Estevex已经在上面发表了评论。这里仍然值得注意的是,这是因为Android Studio的即时运行。您应该禁用它。我扩展了MultiDex应用程序类,并尝试了它,但没有luck@VVB解决这个问题运气好吗?@Estevex已经在上面发表了评论。这里仍然值得注意的是,这是因为Android Studio的即时运行。你应该禁用它。