我正在尝试学习 Android studio 并遵循官方教程,但在有关 Gradle 的部分遇到了障碍,因为该指南似乎已经过时了。 (指南是here https://developer.android.com/codelabs/build-your-first-android-app-kotlin#8)
我被困在我们需要为 android studio 中的导航栏启用 safeargs 的部分。所有代码片段和放置它们的方向似乎都已经过时了。这是我实际的 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:可能版本不是最新的
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)