WIS*_*SHY 4 android gradle dagger-hilt
我正在将 dagger 集成到我的应用程序中,并在运行应用程序时遇到这个问题
java.lang.RuntimeException: Unable to instantiate application com.mine.parsexml.ParseApplication: java.lang.ClassNotFoundException: Didn't find class "com.mine.parsexml.ParseApplication" on path: DexPathList[[zip file "/data/app/com.mine.parsexml-4NxKMOI9esXH_ar6UHYk5w==/base.apk"],nativeLibraryDirectories=[/data/app/com.mine.parsexml-4NxKMOI9esXH_ar6UHYk5w==/lib/x86, /system/lib, /system/product/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:1226)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6431)
at android.app.ActivityThread.access$1300(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
Run Code Online (Sandbox Code Playgroud)
这是应用程序类 - 也已在清单中声明
@HiltAndroidApp
class ParseApplication: Application()
Run Code Online (Sandbox Code Playgroud)
应用程序级别等级
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'androidx.navigation.safeargs.kotlin'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
Run Code Online (Sandbox Code Playgroud)
应用插件:'kotlin-android'
android {
compileSdk 31
defaultConfig {
applicationId "com.mine.parsexml"
minSdk 23
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildFeatures {
viewBinding true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
kotlinOptions {
jvmTarget = '1.8'
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/AL2.0'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/gradle/incremental.annotation.processors'
exclude("META-INF/*.kotlin_module")
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation "com.google.android.exoplayer:exoplayer:2.16.0"
implementation "com.google.dagger:hilt-android:2.39.1"
implementation "com.google.dagger:hilt-android-compiler:2.39.1"
implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}
Run Code Online (Sandbox Code Playgroud)
我的问题是 dagger 依赖项的关键字错误,编译器必须使用 kapt 而不是实现
改变了
implementation "com.google.dagger:hilt-android-compiler:2.39.1"
Run Code Online (Sandbox Code Playgroud)
到
kapt "com.google.dagger:hilt-android-compiler:2.39.1"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2357 次 |
| 最近记录: |