Dan*_*lla 6 java android dagger-hilt
我在我的项目中使用 Dagger Hilt,但它无法编译。检查了清单和项目文件中的所有内容,但不知道发生了什么:/
error: annotation @AggregatedRoot is missing a default value for the element 'originatingRoot'
@AggregatedRoot(
^warning: File for type 'com.example.mikebamb.EquipmentsApplication_HiltComponents' created in the last round
will not be subject to annotation processing.warning: File for type 'dagger.hilt.internal.processedrootsentinel.codegen._com_example_mikebamb_EquipmentsApplication'
created in the last round will not be subject to annotation processing.
> Task :app:kaptDebugKotlin FAILED
Run Code Online (Sandbox Code Playgroud)
设备应用案例
@HiltAndroidApp
class EquipmentsApplication : Application()
Run Code Online (Sandbox Code Playgroud)
主要活动
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
Run Code Online (Sandbox Code Playgroud)
清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mikebamb">
<application
android:name="com.example.mikebamb.EquipmentsApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MikeBamb">
<activity android:name=".presenter.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
Dan*_*lla 20
由于某种原因,我的实现版本不匹配
旧版
implementation 'com.google.dagger:hilt-android:2.36'
kapt 'com.google.dagger:hilt-compiler:2.35.1'
Run Code Online (Sandbox Code Playgroud)
回滚至
implementation 'com.google.dagger:hilt-android:2.35'
kapt 'com.google.dagger:hilt-compiler:2.35'
Run Code Online (Sandbox Code Playgroud)
确保所有依赖项版本都匹配。
项目的build.gradle
classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"
和模块的 build.gradle 的
implementation "com.google.dagger:hilt-android:2.42"
kapt "com.google.dagger:hilt-android-compiler:2.42"
必须全部使用同一版本。我最初在更新所有 Dagger-Hilt 依赖项后收到此错误,但错误地忘记更新 kapt 编译器的依赖项,因为 IDE 没有警告我它已过时,将所有三个依赖项更新到同一版本修复了它。
小智 6
检查构建(项目)和构建(模块)中的依赖项版本,它们必须是相同的版本
项目中
plugins { //hilt id 'com.google.dagger.hilt.android' version '2.42' apply false }
模块内
plugins {
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
composeOptions {
kotlinCompilerExtensionVersion = "1.2.0-beta03"
}
dependencies {
implementation 'com.google.dagger:hilt-android:2.42'
implementation 'androidx.hilt:hilt-work:1.0.0'
kapt "com.google.dagger:hilt-compiler:2.42"
kapt 'androidx.hilt:hilt-compiler:1.0.0'
implementation 'androidx.hilt:hilt-navigation-fragment:1.0.0'
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7284 次 |
| 最近记录: |