【问题标题】:Unable to instantiate application dagger android无法实例化应用程序匕首android
【发布时间】:2021-12-29 01:05:59
【问题描述】:

我正在我的应用程序中集成 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)

这是应用程序类 - 也已在清单中声明

@HiltAndroidApp
class ParseApplication: Application()

应用级分级

plugins {
id 'com.android.application'
id 'kotlin-android'
id 'androidx.navigation.safeargs.kotlin'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'

} 应用插件:'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()
}

【问题讨论】:

  • 我在 2.40.1 版本中也遇到了这个错误
  • @Denny 检查我的答案是否适合你
  • 我实际上纠正了我的问题。我没有将域模块包含到主应用程序模块中

标签: android gradle dagger-hilt


【解决方案1】:

我的问题是匕首依赖的关键字错误 因为编译器必须使用 kapt 而不是实现

改变了

implementation "com.google.dagger:hilt-android-compiler:2.39.1"

kapt "com.google.dagger:hilt-android-compiler:2.39.1"

【讨论】:

  • 救我一命。我还使用了implementation "com.google.dagger:hilt-android-compiler:2.39.1" 而不是kapt "com.google.dagger:hilt-android-compiler:2.39.1"。值得一提的是,官方文档根本不清楚需要哪些依赖项和插件
猜你喜欢
  • 2011-08-17
  • 2016-03-02
  • 2012-05-05
  • 2014-03-30
  • 2020-10-30
  • 1970-01-01
  • 2020-02-24
  • 2013-07-31
  • 2012-04-26
相关资源
最近更新 更多