今天,Android Studio刚刚发布3.0版。在我更新了所有依赖项之后,即使IDE没有在代码中显示任何错误,我也无法构建我的项目。 (Gradle Sync很好。)
build.gradle(项目)
buildscript {
ext.kotlin_version = "1.1.51"
repositories {
jcenter()
google()
}
dependencies {
classpath "com.android.tools.build:gradle:3.0.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(App)
apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
apply plugin: "kotlin-kapt"
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 12
versionName "1.1.2"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
flavorDimensions "build"
productFlavors {
UAT {
resValue "string", "app_name", "UAT"
dimension "build"
}
SIS {
resValue "string", "app_name", "SIS"
dimension "build"
}
PROD {
resValue "string", "app_name", "PROD"
dimension "build"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
}
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "com.android.support:appcompat-v7:26.1.0"
compile "com.android.support:support-v13:26.1.0"
compile "com.android.support:design:26.1.0"
compile "com.android.support.constraint:constraint-layout:1.0.2"
// Skip
testCompile "junit:junit:4.12"
androidTestCompile "com.android.support.test.espresso:espresso-core:3.0.1"
kapt "android.arch.persistence.room:compiler:1.0.0-rc1"
kapt "com.google.dagger:dagger-compiler:2.11"
}
我已经尝试过api,实现和编译。
错误
e: C:\Users\user\AndroidStudioProjects\project\app\src\main\java\com\example\ContextExtension.kt: (47, 34): Unresolved reference: LOLLIPOP
e: C:\Users\user\AndroidStudioProjects\project\app\src\main\java\com\example\ContextExtension.kt: (104, 58): Unresolved reference: LOLLIPOP
e: C:\Users\user\AndroidStudioProjects\project\app\src\main\java\com\example\ContextExtension.kt: (173, 58): Unresolved reference: LOLLIPOP
...
但是在更新之前这条线很好,Android Studio不会将其突出显示为红色。
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
供您参考,错误显示在:app:compilePRODDebugKotlin
。
编辑:我找到了原因。我误解了implementation
并遗漏了exclude
。添加回排除修复了问题。