Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Dagger2错误:包Android.app不存在_Android_Kotlin_Dagger 2 - Fatal编程技术网

Android Dagger2错误:包Android.app不存在

Android Dagger2错误:包Android.app不存在,android,kotlin,dagger-2,Android,Kotlin,Dagger 2,我试图将Dagger2配置为能够注入Appliaction实例,但在构建过程中,我遇到了奇怪的错误: DaggerAppComponent.java:3: error: package android.app does not exist import android.app.Application; ^ 这是我的密码: Gradle Dagger2依赖项 应用组件 我的申请 BootstrapActivity节点显示 android.app包怎么可能不存在

我试图将Dagger2配置为能够注入Appliaction实例,但在构建过程中,我遇到了奇怪的错误:

DaggerAppComponent.java:3: error: package android.app does not exist
import android.app.Application;
                  ^
这是我的密码:

Gradle Dagger2依赖项

应用组件

我的申请

BootstrapActivity节点显示


android.app包怎么可能不存在?请帮帮我,我正在为此奋斗两天:

当您使用自定义应用程序类而不是默认的android应用程序类时,您应该使用自己的应用程序类。为此,请将应用程序组件生成器更改为:

@Component.Builder
interface Builder {
    @BindsInstance
    fun application(app: MyApplication): Builder

    fun build(): AppComponent
}
另外,不要忘记在build.gradle中包含必要的依赖项:

以及注释处理器,如果您希望使用android特定的注释,我建议您执行以下操作:

kapt 'com.google.dagger:dagger-android-processor:2.28'

也许我最终解决了这个问题。我在Gradle中安装了JVM版本10,将其更改为1.8解决了我的问题

我以前尝试过这个。我再次添加了这些依赖项,并在component Builder中将类型更改为MyApplication,但这在component.applicationthis:DaggerAppComponent.java:85:error:无法访问应用程序this.Application=Premissions.checkNotNullapp;^找不到android.app.Application的类文件是否已将应用插件:kotlin kapt添加到build.gradle以使用kapt插件?是的,它已存在然后根据答案尝试annotationProcessor而不是kapt,并检查它是否解决了问题。很高兴听到这个消息!
class MyApplication : Application() {
    private lateinit var appComponent: AppComponent

    override fun onCreate() {
        super.onCreate()

        appComponent = DaggerAppComponent.builder()
            .application(this)
            .build()
    }

    fun getAppComponent() = appComponent
}
class BootstrapActivity : AppCompatActivity() {
    @Inject
    lateinit var auth: Auth

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        (applicationContext as MyApplication).getAppComponent()
            .inject(this)

        //auth.fetchCurrentUser()

        val intent: Intent = if (auth.isLoggedIn()) {
            Intent(this, HomeActivity::class.java)
        } else {
            Intent(this, LoginActivity::class.java)
        }

        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)

        startActivity(intent)

        finish()
    }
}
@Component.Builder
interface Builder {
    @BindsInstance
    fun application(app: MyApplication): Builder

    fun build(): AppComponent
}
api 'com.google.dagger:dagger-android:2.28'
api 'com.google.dagger:dagger-android-support:2.28' // you're using the support libraries
kapt 'com.google.dagger:dagger-android-processor:2.28'