英文:
MyAppHiltApp: java.lang.ClassNotFoundException: Didn't find class "HiltApp" on path: DexPathList
问题
I have a problem how to fix java.lang.RuntimeException: Unable to instantiate application com.example.bettehomes.MyAppHiltApp: java.lang.ClassNotFoundException: Didn't find class "com.example.bettehomes.BetteHomesHiltApp" on path: DexPathList
. My package name is "com.example.bettehomes". I tried clean and rebuild.
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>
The logcat shows:
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)
英文:
I have a problem how to fix java.lang.RuntimeException: Unable to instantiate application com.example.bettehomes.MyAppHiltApp: java.lang.ClassNotFoundException: Didn't find class "com.example.bettehomes.BetteHomesHiltApp" on path: DexPathList
. My package name is "com.example.bettehomes". I tried clean and rebuild.
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>
The logcat shows:
> 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)
答案1
得分: 1
以下是翻译好的部分:
成功的方法是:
在 Hilt 应用中解决 ClassNotFound 问题的方法是:(当然要在应用的 build.gradle 中添加 kotlin-kapt
插件 ID 和 com.google.dagger.hilt.android
的 ID,使用 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}'
对于 Android Gradle 插件 7.4.2
、Kotlin 1.8.20
、Compose 1.4.6
。
英文:
What eventually worked was:
What worked for ClassNotFound in hilt app was: (of course added kotlin-kapt
plugin id and id com.google.dagger.hilt.android
in app's build.gradle) using 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`
答案2
得分: 0
以下是代码部分的中文翻译:
在您的项目中添加kapt
,将annotationProcessor
替换为以下代码:
项目级别的build.gradle
文件:
plugins {
...
id 'com.google.dagger.hilt.android' version '2.44' apply false
}
应用级别的build.gradle
文件:
plugins {
...
id 'kotlin-kapt'
id 'com.google.dagger.hilt.android'
}
android {
...
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KaptGenerateStubs).configureEach {
kotlinOptions {
jvmTarget = "1.8"
}
}
composeOptions {
kotlinCompilerExtensionVersion '1.4.6' // 如果使用Compose,请安装此版本
}
...
}
dependencies {
...
implementation "com.google.dagger:hilt-android:2.44"
kapt "com.google.dagger:hilt-compiler:2.44"
}
kapt {
correctErrorTypes true
}
此解决方案适用于您正在使用的AGP 8.0.0
,Kotlin 1.8.20
和Gradle 8.0
的项目版本。我已经验证了在具有指定版本的新项目中可以正常工作。
英文:
Try adding kapt
to your project by replacing annotationProcessor
with the following code:
build.gradle
project level:
plugins {
...
id 'com.google.dagger.hilt.android' version '2.44' apply false
}
build.gradle
app level:
plugins {
...
id 'kotlin-kapt'
id 'com.google.dagger.hilt.android'
}
android {
...
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KaptGenerateStubs).configureEach {
kotlinOptions {
jvmTarget = "1.8"
}
}
composeOptions {
kotlinCompilerExtensionVersion '1.4.6' // Install this version if using Compose
}
...
}
dependencies {
...
implementation "com.google.dagger:hilt-android:2.44"
kapt "com.google.dagger:hilt-compiler:2.44"
}
kapt {
correctErrorTypes true
}
This solution is for AGP 8.0.0
, Kotlin 1.8.20
and Gradle 8.0
you are using. I have verified that this works in a new project with the specified versions.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论