gpt4 book ai didi

android - Android Gradle Kotlin Dsl 中 Unresolved reference 问题

转载 作者:行者123 更新时间:2023-12-04 23:57:30 24 4
gpt4 key购买 nike

我将我的 gradle 文件从 groovy 迁移到 kotlin dsl。一切正常,但是从另一个 kotlin 文件导入值到 gradle 存在问题。我可以导入变量并且自动完成功能正常,但是当我构建项目时,它会给我Unresolved reference 错误。感谢任何帮助。

Gradle 版本:7.1.1

Android 工作室:北极狐

我在 buildSrc 下创建的 build.gradle.kts:

plugins {
`java-gradle-plugin`
`kotlin-dsl`
`kotlin-dsl-precompiled-script-plugins`
}

repositories {
mavenCentral()
}

我从 buildSrc/src/main/java/Dependencies 中导入的文件:

object Versions {
const val compose_version = "1.0.0"
}

object Dependencies {
const val compose_ui = "androidx.compose.ui:ui:${Versions.compose_version}"
const val compose_material = "androidx.compose.material:material:${Versions.compose_version}"
const val compose_ui_tooling_preview = "androidx.compose.ui:ui-tooling-preview:${Versions.compose_version}"
const val compose_ui_tooling = "androidx.compose.ui:ui-tooling:${Versions.compose_version}"
const val compose_ui_test = "androidx.compose.ui:ui-test-junit4:${Versions.compose_version}"
}

应用程序 build.gradle.kts 文件:

plugins {
id("com.android.application")
kotlin("android")
}

android {
compileSdk = 30
defaultConfig {
applicationId = "com.example.compose"
minSdk = 21
targetSdk = 30
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
debug {
isMinifyEnabled = false
isDebuggable = true
}
release {
isMinifyEnabled = true
isDebuggable = 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 {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.0.0"
}
packagingOptions {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}

dependencies {
implementation("androidx.core:core-ktx:1.6.0")
implementation("androidx.appcompat:appcompat:1.3.1")
implementation("com.google.android.material:material:1.4.0")

// Jetpack Compose
implementation(Dependencies.compose_ui)
implementation(Dependencies.compose_material)
implementation(Dependencies.compose_ui_tooling_preview)
debugImplementation(Dependencies.compose_ui_tooling)
androidTestImplementation(Dependencies.compose_ui_test)

implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.3.1")
implementation("androidx.activity:activity-compose:1.3.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
}

最佳答案

你说你的其他文件在 buildSrc/src/main/java/Dependencies 下。因为这是一个 Kotlin 文件,所以它应该是 buildSrc/src/main/kotlin/Dependencies

关于android - Android Gradle Kotlin Dsl 中 Unresolved reference 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68610161/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com