android 无法示例化应用程序:java.lang.ClassNotFoundException:

guykilcj  于 2023-03-16  发布在  Android
关注(0)|答案(7)|浏览(184)

在以下情况下会出现此问题:

  • 我从Android Studio运行应用,应用运行正常

然后我删除了应用程序,并试图从.../app/build/outputs/apk/debug.apk安装debug.apk
我的操作系统是Ubuntu 16.04,甲骨文JDK
但在Windows 7上都能正常工作(apk可以从.../app/build/outputs/apk/debug.apk安装并正常运行)
出现此错误:

FATAL EXCEPTION: main
Process: com.example, PID: 21084
java.lang.RuntimeException: Unable to instantiate application com.example.MyApp: java.lang.ClassNotFoundException: Didn't find class "com.example.MyApp" on path: DexPathList[[zip file "/data/app/com.example-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example-1/lib/arm, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:676)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6289)
at android.app.ActivityThread.access$1800(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1860)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.MyApp" on path: DexPathList[[zip file "/data/app/com.example-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example-1/lib/arm, /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:1004)
at android.app.LoadedApk.makeApplication(LoadedApk.java:666)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6289) 
at android.app.ActivityThread.access$1800(ActivityThread.java:221) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1860) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7224) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Suppressed: java.lang.ClassNotFoundException: com.example.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)
        ... 12 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

我的等级:

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'io.fabric'
apply plugin: 'android-apt'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

defaultConfig {
    applicationId "com.example"
    minSdkVersion 19
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"

    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    jackOptions {
        enabled false
    }
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

dexOptions {
    javaMaxHeapSize "8g"
    jumboMode = true
    preDexLibraries = false
}

signingConfigs {
    //release
    release {
        storeFile file("/keys/apk_key.jks")
        storePassword "apk_key"
        keyAlias "apk_key"
        keyPassword "apk_key"
    }
}

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

dexOptions {
    javaMaxHeapSize "3G"
}

packagingOptions {
    exclude 'LICENSE.txt'
    exclude 'mockito-extensions/org.mockito.plugins.MockMaker'
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
}

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    ...
}

我还试图:

  • Invalidate Cache/Restart
  • Clean Project
  • Rebuild project
pgvzfuti

pgvzfuti1#

Thank you @Dileep Patel我也遇到了同样的问题。应用程序只有在从Android Studio安装时才能正常工作,如果通过adb命令安装则会崩溃。使缓存无效/重新启动和禁用即时运行(Android Studio-〉首选项-〉即时运行,取消选中“启用示例运行”)在我的情况下有效。

fhg3lkii

fhg3lkii2#

在应用级gradle中添加多索引

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

启用多联

defaultConfig {
 multiDexEnabled true
}

最后将此代码添加到应用程序类中

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

toe950273#

我只想说,我知道这真的很愚蠢,我知道这个问题已经得到了回答,但我更改了我的应用程序类的名称,并且忘记在清单中更改它,由于某种原因,应用程序仍然构建。无论如何,请确保在项目的清单中有正确的应用程序类名称:

<application
    android:name=".CorrectAppClassHere"
        //...
zi8p0yeb

zi8p0yeb4#

把这个加到gradle上帮了我

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
bsxbgnwa

bsxbgnwa5#

如果您有API级别20以上的测试设备,则可以将minSdkVersion更改为21,而不是添加multidex,因为API级别20及更高级别包含multidex

rslzwgfq

rslzwgfq6#

我之前尝试过一种解决方案来解决清单中的appname问题,因此我添加了以下行manifestPlaceholders = [applicationName:“com.tech.turitos”在应用程序Gradle中,它既没有修复我的问题,也没有我记得删除它,所以它创建了这个错误,只要我删除它,应用程序工作正常。

tzdcorbm

tzdcorbm7#

<application
            android:name=".App"
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">

在您的 manifest 文件中,只需将allowBackup更改为false
然后运行应用程序,你会得到一个异常。
然后将其改回true,这将完全修复它。

相关问题