當我想在我的專案中使用 @AndroidEntryPoint 這是 hilt 的一個屬性時,我收到以下警告。
Expected @AndroidEntryPoint to have a value. Did you forget to apply the Gradle Plugin? (dagger.hilt.android.plugin)
當我嘗試將 id 'dagger.hilt.android.plugin' 添加到我專案的模塊級 build.gradle 檔案時,出現以下錯誤。
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'dagger.hilt.android.plugin'] was not found in any of the following sources:
我嘗試將其添加到專案模塊級別的 build.gradle 檔案中,如下所示。他們都給出了錯誤。
![插件 [id: 'dagger.hilt.android.plugin'] 未在以下任何來源中找到](https://img.uj5u.com/2021/10/13/ea0c432dd4e0472cac166ebe23d9e053.png)
我試圖將它作為類路徑添加到專案級別的 build.gradle 檔案中,在這種情況下我仍然收到錯誤訊息。
![插件 [id: 'dagger.hilt.android.plugin'] 未在以下任何來源中找到](https://img.uj5u.com/2021/10/13/925224a86b20434fb27cc0b6f40ed535.png)
當我創建默認專案時,創建了一個 settings.gradle 結構,如下所示。這是我第一次使用這個版本。我的Android Studio Android Studio 版本- Bumblebee | 2021.1.1 金絲雀 13
![插件 [id: 'dagger.hilt.android.plugin'] 未在以下任何來源中找到](https://img.uj5u.com/2021/10/13/cb979cd03d644cf79dfca7206e6d499f.png)
uj5u.com熱心網友回復:
用于添加dagger hilt到您的專案中。按著這些次序
將hilt依賴項添加到模塊的build.gradle. 我假設你正在使用Kotlin,否則,您必須使用annotationProcessorinsted的的kapt插件。
dependencies {
//..
implementation 'com.google.dagger:hilt-android:2.39.1'
kapt 'com.google.dagger:hilt-compiler:2.39.1'
//..
}
添加hilt gradle plugin到專案的build.gradle.
dependencies {
//..
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.39.1'
}
應用kotlin-kapt和hilt插件到模塊build.gradle
plugins {
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
uj5u.com熱心網友回復:
經過長時間的斗爭,我解決了以下問題;
我在settings.gradle 中添加了一個resolutionStrategy,如下所示。
pluginManagement {
repositories {...}
plugins { ...}
resolutionStrategy {
eachPlugin {
if( requested.id.id == 'dagger.hilt.android.plugin') {
useModule("com.google.dagger:hilt-android-gradle-plugin:2.39.1")
}
}
}
}
然后,當我將如下所示的刀柄插件添加到模塊級build.gradle檔案時,它已正確更新。
plugins{
...
id 'dagger.hilt.android.plugin'
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/311268.html
標籤:安卓 安卓工作室 等级 gradle-kotlin-dsl 匕首柄
