编译遇到的bug集合
-
Gradle 8.0
-
AGP 7.2.0
-
依赖方式
dependencies { implementation("androidx.core:core-ktx:1.10.1") implementation("androidx.appcompat:appcompat:1.6.1") implementation("com.google.android.material:material:1.11.0") implementation(projects.lib) }假如想以
implementation(projects.lib)这样的方式来依赖本地库,则需要在settings.gradle.kts文件中添加如下代码enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")//主要的配置 include( "app", "lib"//自己项目中创建的Android Library的名字 ) -
在
lib库中写的kotlin类/接口文件,在主程中也能引用到,但是一编译就报错Unresolved reference: xxx此时需要检查
lib库是否添加了kotlinplugins { id("com.android.library") kotlin("android")//把这行加上就可以了 } -
'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.这个错误是需要统一
compileDebugJavaWithJavac和compileDebugKotlin使用的jdk版本compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } //看看是不是这个忘了加了 kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() }