[英]Jetpack Navigation - How to handle dependency warning when adding nav_graph.xml?
I want to use the new navigation library of android jetpack. 我想使用android jetpack的新导航库。 As I wanted to add a navigation XML to my project I got an error saying: 由于我想在我的项目中添加导航XML,因此出现错误消息:
This operation requires the libraries android.arch.navigation:navigation-fragment:+, android.arch.navigation:navigation-ui:+. 此操作需要库android.arch.navigation:navigation-fragment:+,android.arch.navigation:navigation-ui:+。
Problem: Inconsistencies in the existing project dependencies found. 问题:发现现有项目依赖项不一致。 Version incompatibility between: - android.arch.persistence.room:runtime:1.1.1 and: - com.android.support:appcompat-v7:27.1.1 版本不兼容: - android.arch.persistence.room:runtime:1.1.1和: - com.android.support:appcompat-v7:27.1.1
With the dependency: - com.android.support:support-annotations:26.1.0 versus: - com.android.support:support-annotations:27.1.1 依赖: - com.android.support:support-annotations:26.1.0与: - com.android.support:support-annotations:27.1.1
The project may not compile after adding these libraries. 添加这些库后,项目可能无法编译。 Would you like to add them anyway? 你还想添加它们吗?
I hit "cancel" since I didn't know what the consequences for my little project would be. 我点击“取消”,因为我不知道对我的小项目会有什么后果。 Why is that happening? 为什么会这样? Is room not compatible with the navigation library? 房间与导航库不兼容吗? Do I risk that my project will not compile after adding those? 我冒这个风险,我的项目在添加之后不会编译吗? Should I save the gradle file and just try? 我应该保存gradle文件并尝试一下吗?
I would be very grateful for clarification. 我将非常感谢澄清。 Thank you:) 谢谢:)
My gradle file: 我的gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "de.test"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:27.1.1'
// Room components
implementation "android.arch.persistence.room:runtime:$rootProject.roomVersion"
annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"
androidTestImplementation "android.arch.persistence.room:testing:$rootProject.roomVersion"
// Lifecycle components
implementation "android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion"
annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archLifecycleVersion"
}
There's two parts to this: 这有两个部分:
1) The dialog is incorrect. 1)对话框不正确。 The current Android Studio looks at test dependencies, which are included in the POM files, but don't affect your app (the test dependencies are only used internally for the tests testing the libraries themselves). 当前的Android Studio会查看测试依赖项,这些依赖项包含在POM文件中,但不会影响您的应用程序(测试依赖项仅在内部用于测试库本身的测试)。 This is partially fixed in Android Studio 3.5 Beta 1. 这在Android Studio 3.5 Beta 1中已部分修复。
2) Your app would not compile when you add the Navigation dependencies because you use compileSdkVersion 27
and the android.arch.navigation
dependencies depends on version 28.0.0 of the Support Library, which requires that you compile with API 28. 2)当您添加导航依赖项时,您的应用程序将无法编译,因为您使用compileSdkVersion 27
并且android.arch.navigation
依赖项依赖于支持库的版本28.0.0,这需要您使用API 28进行编译。
If you fix your app to use compileSdkVersion 28
, then you can safely ignore warning of the dialog and add Navigation to your project. 如果您修复应用程序以使用compileSdkVersion 28
,则可以安全地忽略对话框的警告并将Navigation添加到项目中。 You can, of course, upgrade your Support Library to 28.0.0 prior to adding Navigation, which will ensure that there's no other unrelated to Navigation behavior changes caused by upgrading from 27.1.1 to 28.0.0. 当然,您可以在添加导航之前将支持库升级到28.0.0,这将确保从27.1.1升级到28.0.0不会导致与导航行为更改无关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.