Android 添加到gradle后仍无法解析的引用
我决定参考以下三个课程:Android 添加到gradle后仍无法解析的引用,android,android-gradle-plugin,android-navigation,leakcanary,timber-android,Android,Android Gradle Plugin,Android Navigation,Leakcanary,Timber Android,我决定参考以下三个课程: 木材 漏嘴金丝雀 findNavController 我在gradle中添加了这些依赖项,在其他项目中也有这些依赖项,但我在这里面临这个问题 我曾尝试: 清理、重建、根据需要构建、构建 已删除.gradle、.idea、build、app/build文件夹并重建应用程序,但问题仍然存在 我还尝试了使缓存无效并重新启动它,但也没有帮助 渐变文件: apply plugin: 'com.android.application' apply plugin: 'com.
- 木材
- 漏嘴金丝雀
- findNavController
- 清理、重建、根据需要构建、构建
- 已删除.gradle、.idea、build、app/build文件夹并重建应用程序,但问题仍然存在
- 我还尝试了使缓存无效并重新启动它,但也没有帮助
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.oss.licenses.plugin'
apply plugin: 'androidx.navigation.safeargs'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
buildToolsVersion '28.0.0 rc2'
defaultConfig {
applicationId "com.nrs.sid.creditcardsecurity"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
sourceSets {
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
buildTypes {
debug {
applicationIdSuffix '.debug'
versionNameSuffix '-DEBUG'
ext.alwaysUpdateBuildId = false
}
release {
shrinkResources false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
allprojects {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-Xlint:cast" << "-Xlint:empty" << "-Xmaxerrs"
}
}
testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
androidExtensions {
experimental = true
}
kapt {
correctErrorTypes = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "androidx.core:core-ktx:1.0.0-alpha3"
implementation 'androidx.fragment:fragment-ktx:1.0.0-alpha3'
implementation 'androidx.collection:collection-ktx:1.0.0-alpha3'
implementation "androidx.appcompat:appcompat:1.0.0-alpha3"
implementation "androidx.recyclerview:recyclerview:1.0.0-alpha3"
implementation 'androidx.recyclerview:recyclerview-selection:1.0.0-alpha3'
implementation "androidx.annotation:annotation:1.0.0-alpha3"
implementation 'androidx.webkit:webkit:1.0.0-alpha3'
implementation 'com.google.android.material:material:1.0.0-alpha3'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
//implementation 'com.google.android.gms:play-services-oss-licenses:15.0.1'
implementation('com.google.android.gms:play-services-oss-licenses:15.0.1', {
exclude group: 'com.google.android.gms'
})
implementation 'androidx.browser:browser:1.0.0-alpha3'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation "io.reactivex.rxjava2:rxandroid:2.0.2"
implementation "io.reactivex.rxjava2:rxjava:2.1.12"
implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'
implementation "com.jakewharton.rxbinding2:rxbinding-kotlin:2.1.1"
implementation "com.jakewharton.rxbinding2:rxbinding-support-v4-kotlin:2.1.1"
implementation "com.jakewharton.rxbinding2:rxbinding-appcompat-v7-kotlin:2.1.1"
implementation "com.jakewharton.rxbinding2:rxbinding-design-kotlin:2.1.1"
implementation "com.jakewharton.rxbinding2:rxbinding-recyclerview-v7-kotlin:2.1.1"
implementation "com.jakewharton.timber:timber:4.7.0"
implementation 'com.google.dagger:dagger:2.16'
kapt 'com.google.dagger:dagger-compiler:2.16'
implementation 'com.google.dagger:dagger-android:2.16'
implementation 'com.google.dagger:dagger-android-support:2.16'
kapt 'com.google.dagger:dagger-android-processor:2.16'
implementation "org.greenrobot:eventbus:3.1.1"
debugImplementation "com.squareup.leakcanary:leakcanary-android:1.5.4"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:1.5.4"
implementation "com.github.markzhai:blockcanary-android:1.5.0"
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
implementation 'androidx.lifecycle:lifecycle-common-java8:2.0.0-alpha1'
implementation 'androidx.lifecycle:lifecycle-reactivestreams:2.0.0-alpha1'
testImplementation 'androidx.arch.core:core-testing:2.0.0-alpha1'
implementation 'androidx.room:room-runtime:2.0.0-alpha1'
kapt 'androidx.room:room-compiler:2.0.0-alpha1'
implementation 'androidx.room:room-rxjava2:2.0.0-alpha1'
implementation 'androidx.room:room-guava:2.0.0-alpha1'
testImplementation 'androidx.room:room-testing:2.0.0-alpha1'
implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha02'
implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-alpha02'
androidTestImplementation 'android.arch.navigation:navigation-testing-ktx:1.0.0-alpha02'
implementation "com.squareup.retrofit2:retrofit:2.4.0"
implementation "com.squareup.okhttp3:logging-interceptor:3.10.0"
implementation "com.google.code.gson:gson:2.8.2"
implementation "com.squareup.retrofit2:converter-gson:2.4.0"
implementation "com.squareup.retrofit2:adapter-rxjava2:2.4.0"
implementation "com.twitter.serial:serial:0.1.6"
testImplementation "org.mockito:mockito-core:2.16.0"
implementation "org.jetbrains:annotations:16.0.1"
testImplementation "junit:junit:4.12"
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test:rules:1.1.0-alpha3'
androidTestUtil 'androidx.test:orchestrator:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.1.0-alpha3'
implementation 'androidx.test.espresso.idling:idling-concurrent:3.1.0-alpha3'
testImplementation "org.robolectric:robolectric:3.8"
}
你有没有可能用kotlin?如果是这样,您可能需要将
-ktx
后缀添加到依赖项中,如下所述
我还缺少findNavController
,直到我添加了-ktx
,如我的build.gradle
dependencies {
def nav_version = "1.0.0-alpha02"
// Ensure to use the -ktx version below (we are using kotlin)
implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version" // use -ktx for Kotlin
implementation "android.arch.navigation:navigation-ui-ktx:$nav_version" // use -ktx for Kotlin
androidTestImplementation "android.arch.navigation:navigation-testing-ktx:$nav_version"
....
}
下面是我的活动,其中包含“findNavController”所需的导入。请注意,需要删除使用supportFragmentManager从activity Android Studio模板生成的代码,以使其正常工作
import androidx.navigation.findNavController
class NavigationActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.navigation_activity)
//TODO: This was part of the generated activity - not needed ?
// if (savedInstanceState == null) {
// supportFragmentManager.beginTransaction()
// .replace(R.id.container, NavigationFragment.newInstance())
// .commitNow()
// }
}
override fun onSupportNavigateUp() = findNavController(R.id.my_nav_host_fragment).navigateUp()
}
告诉我错误log@RutvikBhatt用错误日志更新帖子扫描你给我看完整等级dependencies@RutvikBhatt用gradle Dependenciest更新了帖子这发生在我尝试迁移到AndroidX之后。你找到解决办法了吗?
import androidx.navigation.findNavController
class NavigationActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.navigation_activity)
//TODO: This was part of the generated activity - not needed ?
// if (savedInstanceState == null) {
// supportFragmentManager.beginTransaction()
// .replace(R.id.container, NavigationFragment.newInstance())
// .commitNow()
// }
}
override fun onSupportNavigateUp() = findNavController(R.id.my_nav_host_fragment).navigateUp()
}