我正在 Kotlin 中开发一个具有 Android 模块的多平台项目。
在我的一个文件中,我有代码:
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
得到以下编译器错误:
Unresolved reference: MATCH_PARENT
所有对超出 Android API 级别 1 的任何内容的引用都会出现类似的编译器错误,但没有任何在 Android API 级别 1 中可用的引用。
Android Studio 可以识别所有的引用,并且代码完成对它们工作得很好。只有当我编译时,这些错误才会出现。
我的 gradle 文件如下所示:
buildscript {
repositories {
mavenCentral()
jcenter()
maven {
url "https://maven.google.com"
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "digital.wup:android-maven-publish:3.1.1"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.kotlinVersion}"
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:${rootProject.dokkaVersion}"
}
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-platform-android'
apply plugin: 'org.jetbrains.dokka-android'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
warning('InvalidPackage', 'NewApi')
}
}
repositories {
google()
mavenLocal()
mavenCentral()
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
def compatVersion = '27.1.1'
androidTestImplementation "com.android.support:support-annotations:${compatVersion}"
// androidTestCompile 'com.android.support.test:runner:1.0.2'
testImplementation 'junit:junit:4.12'
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:${rootProject.kotlinVersion}"
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "com.lightningkite.kotlinx:jvm:${rootProject.libraryVersion}"
implementation "com.github.bigfishcat.android:svg-android:2.0.8"
expectedBy project(':common')
implementation "com.android.support:appcompat-v7:${compatVersion}"
implementation "com.android.support:cardview-v7:${compatVersion}"
implementation "com.android.support:gridlayout-v7:${compatVersion}"
implementation "com.android.support:recyclerview-v7:${compatVersion}"
implementation "com.android.support:design:${compatVersion}"
}