我试图在我的项目中添加导航,但它的显示未能添加导航依赖,
当我点击窗口中的'ok'添加这些时,它显示添加依赖项失败,并且我的导航XML编辑器不可见
build gradle project:
// Top-level build file where you can add configuration options common
到所有子项目/模块。buildscript {
ext {
version_navigation = "2.3.0"
kotlin_version = "1.4.32"
}
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}}
allprojects {
repositories {
google()
jcenter()
}}
task clean(type: Delete) {
delete rootProject.buildDir}
build gradle module:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 32
buildToolsVersion "30.0.3"
buildFeatures{
dataBinding true
viewBinding true
}
defaultConfig {
applicationId "com.example.exampleko"
minSdkVersion 19
targetSdkVersion 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-
rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//navigation
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
}
你要做的是:
在build.gradle
(项目版本)中,找到ext { }
的位置并将其放入:
navigationVersion = "2.3.0"
然后,在build.gradle
(模块)中,在dependencies { }
中,您必须放置这两个依赖项:
implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"
最后,同步项目与gradle文件和这是为了确保一切都好。
你可以把navigationVersion改成你在项目gradle中使用的版本。
如果遇到一些额外的问题,请遵循此代码库。