android - MyAppHiltApp : java. lang.ClassNotFoundException:在路径上找不到类 "HiltApp":DexPathList

标签 android kotlin dagger-hilt

我有一个如何修复java.lang.RuntimeException的问题:无法实例化应用程序com.example.bettehomes.MyAppHiltApp:java.lang.ClassNotFoundException:找不到类“com.example.bettehomes.BetteHomesHiltApp “在路径上:DexPathList。我的包名称是“com.example.bettehomes”。我尝试清理并重建。

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.bettehomes">

    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.BetteHomes"
        android:name=".BetteHomesHiltApp"
        >
        <activity
            android:name=".BetteHomesActivity"
            android:exported="true"
            android:theme="@style/Theme.BetteHomes.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@mipmap/ic_launcher" />
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/dark_orange" />
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_channel_id"
            android:value="@string/default_notification_channel_id" />
        <meta-data
            android:name="firebase_performance_logcat_enabled"
            android:value="true" />
    </application>

logcat 显示:

FATAL EXCEPTION: main Process: com.example.bettehomes, PID: 27056
java.lang.RuntimeException: Unable to instantiate application com.example.bettehomes.BetteHomesHiltApp: java.lang.ClassNotFoundException: Didn't find class "com.example.bettehomes.BetteHomesHiltApp" on path: DexPathList[[zip file "/data/app/com.example.bettehomes-KuesyOEkKsRDfOrSY8aeXA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.bettehomes-KuesyOEkKsRDfOrSY8aeXA==/lib/arm64, /system/lib64, /system/product/lib64, /system/vendor/lib64]] at android.app.LoadedApk.makeApplication(LoadedApk.java:1090) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6140) at android.app.ActivityThread.access$1100(ActivityThread.java:208) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:205) at android.app.ActivityThread.main(ActivityThread.java:6991) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:884)

最佳答案

最终起作用的是: 在 hilt 应用程序中对 ClassNotFound 有效的是:(当然在应用程序的 build.gradle 中添加了 kotlin-kapt 插件 id 和 id com.google.dagger.hilt.android) JAVA 18。

`implementation "com.google.dagger:hilt-android:${hilt_version}" (2.46)
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'
kapt 'androidx.hilt:hilt-compiler:1.0.0'
kapt 'com.google.dagger:hilt-android-compiler:${hilt_version}'`

For android gradle plugin`7.4.2` kotlin `1.8.20` compose `1.4.6`

关于android - MyAppHiltApp : java. lang.ClassNotFoundException:在路径上找不到类 "HiltApp":DexPathList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76190626/

相关文章:

java - 在 Android 上调用方法的成本

reflection - 在 Kotlin 中对具有默认参数的函数使用 callBy 时出错

android - 使用 Hilt 进行依赖注入(inject)时,如何将运行时参数传递给 ViewModel 的构造函数?

android - SurfaceView.lockCanvas() 没有正确清除位图缓冲区

android - 通过 ACTION_OPEN_DOCUMENT 的 takePersistableUriPermission 在自定义文档提供程序上失败但仅适用于 API < 26

使用 FileOutputStream 使用进度条下载 Android ION

recursion - Kotlin尾递归函数导致堆栈溢出

kotlin - 当 "when"语句未涵盖所有实现时,强制编译器发出错误

android - 编译项目时出现 Dagger 错误

Android HILT SingletonComponent vs GoF Singleton 实例设计模式