gpt4 book ai didi

android - 一旦应用程序运行并出现错误 ClassNotFoundException : Didn't find class application on path: DexPathList,应用程序立即崩溃

转载 作者:行者123 更新时间:2023-12-04 23:40:53 31 4
gpt4 key购买 nike

开始一个新项目,我遇到以下错误...我尝试了其他解决方案,但似乎过时了
我尝试过的步骤:

  • 双重检查插件(如下所列)
  • 实例运行(未列出)
  • 尝试使用 kapt 代替 annotationProccessor(产生不同的错误)
  •     Process: com.example.transfer_tracker, PID: 28953
    java.lang.RuntimeException: Unable to instantiate application com.example.transfer_tracker.CoreApplication package com.example.transfer_tracker: java.lang.ClassNotFoundException: Didn't find class "com.example.transfer_tracker.CoreApplication" on path: DexPathList[[dex file "/data/data/com.example.transfer_tracker/code_cache/.overlay/base.apk/classes4.dex", zip file "/data/app/~~zfKHJdy7wnPYBA_pfwtohQ==/com.example.transfer_tracker-gXT0kIH37Cwb7XaCDmovmg==/base.apk"],nativeLibraryDirectories=[/data/app/~~zfKHJdy7wnPYBA_pfwtohQ==/com.example.transfer_tracker-gXT0kIH37Cwb7XaCDmovmg==/lib/arm64, /system/lib64, /system_ext/lib64]]
    at android.app.LoadedApk.makeApplication(LoadedApk.java:1364)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6686)
    at android.app.ActivityThread.access$1500(ActivityThread.java:247)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2053)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7839)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.transfer_tracker.CoreApplication" on path: DexPathList[[dex file "/data/data/com.example.transfer_tracker/code_cache/.overlay/base.apk/classes4.dex", zip file "/data/app/~~zfKHJdy7wnPYBA_pfwtohQ==/com.example.transfer_tracker-gXT0kIH37Cwb7XaCDmovmg==/base.apk"],nativeLibraryDirectories=[/data/app/~~zfKHJdy7wnPYBA_pfwtohQ==/com.example.transfer_tracker-gXT0kIH37Cwb7XaCDmovmg==/lib/arm64, /system/lib64, /system_ext/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
    at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
    at android.app.Instrumentation.newApplication(Instrumentation.java:1177)
    at android.app.LoadedApk.makeApplication(LoadedApk.java:1356)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6686) 
    at android.app.ActivityThread.access$1500(ActivityThread.java:247) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2053) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loopOnce(Looper.java:201) 
    at android.os.Looper.loop(Looper.java:288) 
    at android.app.ActivityThread.main(ActivityThread.java:7839) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 
    Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/transfer_tracker/Hilt_CoreApplication;
    at java.lang.VMClassLoader.findLoadedClass(Native Method)
    at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
    ... 15 more
    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.transfer_tracker.Hilt_CoreApplication" on path: DexPathList[[dex file "/data/data/com.example.transfer_tracker/code_cache/.overlay/base.apk/classes4.dex", zip file "/data/app/~~zfKHJdy7wnPYBA_pfwtohQ==/com.example.transfer_tracker-gXT0kIH37Cwb7XaCDmovmg==/base.apk"],nativeLibraryDirectories=[/data/app/~~zfKHJdy7wnPYBA_pfwtohQ==/com.example.transfer_tracker-gXT0kIH37Cwb7XaCDmovmg==/lib/arm64, /system/lib64, /system_ext/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    ... 18 more
    [CIRCULAR REFERENCE:java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/transfer_tracker/Hilt_CoreApplication;]
    安卓 list
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.transfer_tracker">

    <application
    android:name=".CoreApplication"
    android:allowBackup="true"
    android:fullBackupContent="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.TransferTracker">
    <activity
    android:name=".login.LauncherActivity"
    android:exported="true">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
    </application>

    </manifest>

    项目构建.gradle
    buildscript {
    repositories {
    google()
    mavenCentral()
    }
    dependencies {
    classpath "com.android.tools.build:gradle:7.0.4"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"
    classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.5'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    }
    }

    task clean(type: Delete) {
    delete rootProject.buildDir
    }
    模块项目.gradle
    plugins {
    id 'com.android.application'
    id 'kotlin-kapt'
    id 'kotlin-android'
    id 'dagger.hilt.android.plugin'
    }

    android {
    compileSdk 31

    defaultConfig {
    applicationId "com.example.transfer_tracker"
    minSdk 22
    targetSdk 31
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }


    buildTypes {
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
    }
    compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
    jvmTarget = '1.8'
    }
    }

    dependencies {
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation 'com.google.dagger:hilt-android:2.40.5'
    annotationProcessor 'com.google.dagger:hilt-compiler:2.40.5'
    }
    应用类
    package com.example.transfer_tracker

    import android.app.Application
    import androidx.multidex.MultiDexApplication
    import dagger.hilt.android.HiltAndroidApp

    @HiltAndroidApp
    class CoreApplication : Application()
    当使用 kapt 而不是 annotationProcessor
    public final class CoreApplication extends android.app.Application {
    ^
    Expected @HiltAndroidApp to have a value. Did you forget to apply the Gradle Plugin? (dagger.hilt.android.plugin)
    See https://dagger.dev/hilt/gradle-setup.html
    [Hilt] Processing did not complete. See error above for details.

    FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':app:kaptDebugKotlin'.
    > A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
    > java.lang.reflect.InvocationTargetException (no error message)

    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    更新
    用 Dagger2 实现的错误消失了……这可能是由于 Hilt 库中的错误

    最佳答案

    添加这些依赖项后一切正常

    implementation 'com.google.dagger:hilt-android:2.40.5'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.4.0'
    implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03'
    annotationProcessor 'androidx.hilt:hilt-compiler:1.0.0'
    annotationProcessor 'com.google.dagger:hilt-android-compiler:2.38.1'

    关于android - 一旦应用程序运行并出现错误 ClassNotFoundException : Didn't find class application on path: DexPathList,应用程序立即崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71003290/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com