gpt4 book ai didi

android - 使用标志 -Dagger.hilt.disableModulesHaveInstallInCheck=true 从 Dagger 迁移到 Hilt 时抑制 @InstallIn 检查时出错

转载 作者:行者123 更新时间:2023-12-03 16:10:44 29 4
gpt4 key购买 nike

我最近一直在尝试将我的 Android 应用程序从 Dagger 迁移到 Hilt。
我想分阶段进行整个迁移,因此试图抑制不使用 @InstallIn 模块的 Hilt 警告。
一直遵循此处给出的迁移指南:https://dagger.dev/hilt/migration-guide.html
还在这里找到了禁用@InstallIn 检查的标志:https://dagger.dev/hilt/compiler-options.html#disable-install-in-check
但是,我一直在努力让这个标志发挥作用。
为了更好地理解这个问题,我尝试将 Dagger Codelab (https://codelabs.developers.google.com/codelabs/android-dagger/#0) 迁移到 Hilt。
即使在那里也没有找到成功。
有人可以指出错误吗?我附上了 build.gradle 文件和下面生成的错误。
项目级别 build.gradle 文件

buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.28-alpha"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
应用级别 构建等级文件
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

apply plugin: 'dagger.hilt.android.plugin'

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.android.dagger"
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.example.android.dagger.MyCustomTestRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets {
String sharedTestDir = 'src/sharedTest/java'
test {
java.srcDir sharedTestDir
}
androidTest {
java.srcDir sharedTestDir
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}

tasks.withType(JavaCompile) {
configure(options) {
options.compilerArgs << "-Adagger.hilt.disableModulesHaveInstallInCheck=true"
}
}
}

dependencies {
def dagger_version = "2.27"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.core:core-ktx:1.2.0"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-livedata:2.2.0'

implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:3.3.1'
testImplementation 'android.arch.core:core-testing:1.1.1'

def androidx_test_version = "1.2.0"
androidTestImplementation "androidx.test:runner:$androidx_test_version"
androidTestImplementation "androidx.test:core-ktx:$androidx_test_version"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

kaptAndroidTest "com.google.dagger:dagger-compiler:$dagger_version"

implementation "com.google.dagger:hilt-android:2.28-alpha"
kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"
}
生成的警告和错误 :
e: D:\androidLearn\dagger\android-dagger\app\build\tmp\kapt3\stubs\debug\com\example\android\dagger\di\AppSubcomponents.java:7: error: [Hilt]
public final class AppSubcomponents {
^
com.example.android.dagger.di.AppSubcomponents must also be annotated with @InstallIn.
[Hilt] Processing did not complete. See error above for details.
e: D:\androidLearn\dagger\android-dagger\app\build\tmp\kapt3\stubs\debug\com\example\android\dagger\di\StorageModule.java:7: error: [Hilt]
public abstract class StorageModule {
^
com.example.android.dagger.di.StorageModule must also be annotated with @InstallIn.
[Hilt] Processing did not complete. See error above for details.
w: warning: The following options were not recognized by any processor: '[dagger.hilt.android.internal.disableAndroidSuperclassValidation, kapt.kotlin.generated]'

最佳答案

您可以将编译器选项添加到 android -> defaultConfig block 中的 app/build.gradle 文件中,如下所示:

android {
...
defaultConfig {
...
//TODO: remove this after migration to Hilt
javaCompileOptions.annotationProcessorOptions.arguments['dagger.hilt.disableModulesHaveInstallInCheck'] = 'true'
}
}

关于android - 使用标志 -Dagger.hilt.disableModulesHaveInstallInCheck=true 从 Dagger 迁移到 Hilt 时抑制 @InstallIn 检查时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63226722/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com