我正在创建一个新的 Android 项目并添加了 Dagger 2,但它失败并出现与androidx
库相关的错误。
在使用 Android Studio 中的模板后,我添加了几行代码,kotlin-kapt
以及 Dagger 2 的依赖项。
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.xxxx.yyyy"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
androidExtensions {
experimental = true
}
kapt {
generateStubs = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
implementation 'com.google.android.material:material:1.0.0-alpha1'
// Image Loading
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
// Dagger
implementation 'com.google.dagger:dagger-android:2.15'
kapt 'com.google.dagger:dagger-android-processor:2.15'
// RxJava
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.3'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
// Navigation
implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha01'
implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-alpha01'
// Pretty Logger
implementation 'com.orhanobut:logger:1.15'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha1'
}
尝试构建应用程序时,它失败并出现以下错误。
error: cannot find symbol
public final class MainActivityViewModel extends android.arch.lifecycle.ViewModel {
^
symbol: class ViewModel
location: package android.arch.lifecycle
error: cannot find symbol
private final androidx.lifecycle.MediatorLiveData
^
symbol: class MediatorLiveData
location: package androidx.lifecycle
error: cannot find symbol
private androidx.navigation.NavController navController;
^
symbol: class NavController
location: package androidx.navigation
...
我尝试过使用androidx
库和较旧的库,但都失败了。如果我删除了 Dagger 2 依赖项,它将构建并运行良好。
我目前正在使用 Android Studio 3.2 Canary 17。
知道出了什么问题吗?
谢谢。