Android+Kotlin+Hilt+多模块应用程序:无法从模块中访问应用程序类。
创始人
2024-08-19 15:30:17
0

在hilt使用多模块项目时,应该在每个module中都添加hilt依赖,并且在组件中添加@InstallIn(ApplicationComponent::class)注解。

具体步骤如下:

  1. 在项目根目录的build.gradle文件中添加hilt的class path依赖:
buildscript {
    dependencies {
        // ...
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.28-alpha'
    }
}
  1. 在每个module的build.gradle文件中应用hilt插件:
plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
}
  1. 在每个module中添加hilt依赖:
dependencies {
    implementation "com.google.dagger:hilt-android:2.28-alpha"
    kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"
}
  1. 在组件中添加@InstallIn(ApplicationComponent::class)注解:
@Module
@InstallIn(ApplicationComponent::class)
object AppModule {
   // ...
}

这样就可以从module中访问应用程序类了。

相关内容

热门资讯

透视中牌率!aapoker怎么... 透视中牌率!aapoker怎么选牌(透视)真的假的(果然存在有挂)1、实时aapoker怎么选牌开挂...
透视黑科技!aapoker免费... 透视黑科技!aapoker免费透视脚本(透视)透视脚本(竟然是真的有挂)1、点击下载安装,aapok...
辅助透视!aapoker怎么提... 辅助透视!aapoker怎么提高中牌率(透视)插件下载(本来真的是有挂)1、aapoker怎么提高中...
透视了解!aapoker辅助软... 透视了解!aapoker辅助软件合法吗(透视)脚本(原来真的是有挂)1、任何aapoker辅助软件合...
透视工具!aapoker辅助器... 透视工具!aapoker辅助器怎么用(透视)透视脚本入口(真是真的是有挂);1、aapoker辅助器...
透视app!aapoker辅助... 透视app!aapoker辅助怎么用(透视)辅助(一贯存在有挂)1、aapoker辅助怎么用系统规律...
透视辅助!aapoker俱乐部... 透视辅助!aapoker俱乐部靠谱吗(透视)插件(本来真的有挂)aapoker俱乐部靠谱吗辅助器中分...
透视安卓版!aapoker怎么... 透视安卓版!aapoker怎么开辅助器(透视)透视插件(果然是有挂)1、aapoker怎么开辅助器透...
透视肯定!aapoker辅助器... 透视肯定!aapoker辅助器怎么用(透视)辅助(竟然是真的有挂)1、实时aapoker辅助器怎么用...
透视安卓版!aapoker透视... 透视安卓版!aapoker透视脚本入口(透视)插件(确实是真的有挂)aapoker透视脚本入口辅助器...