Gradle在Android Studio中应用插件(导航栏的安全参数)



我正在尝试学习Android studio并遵循官方教程,但在关于Gradle的部分遇到了障碍,因为指南似乎已经过时了。(指南在这里(

我被困在我们需要为android工作室中的导航栏启用保险箱的部分。所有的代码片段和放在哪里的说明似乎都过时了。这是我实际的build.gradle项目和模块文件:

项目文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}

模块文件:

plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.myfirstapplication"
minSdk 21
targetSdk 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'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

教程中的一切似乎都是正确的。

在你的gradle文件(应用程序级别,即:"模块"(中,尝试添加以下内容:

apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'androidx.navigation.safeargs.kotlin'

而不是:

plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

这应该没问题。

对于项目文件,你可以这样放:

buildscript {
dependencies {

classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.0"
//I would also add the line below
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
}
}

PS:也许这个版本不是最新的

最新更新