[英]How to configure Kotlin jvmTarget in a Multiplatform Android module?
[英]Kotlin Multiplatform Android module only has access to Android API 1
我正在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}"
}
事實證明,無論內部存在什么問題,它實際上都是由我的build.gradle
文件中的此庫觸發的:
implementation "com.github.bigfishcat.android:svg-android:2.0.8"
我不知道圖書館是如何造成這種情況的。 現在一切都很好。
應用插件:“ com.android.application”
應用插件:“ kotlin-android”
應用插件:“ kotlin-android-extensions”
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.admin.myapplication"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
依賴項{
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:26.1.0'
}
我的Android Studio版本是3.1.1正常
從gradle中刪除所有kotlin庫並放入
實現“ org.jetbrains.kotlin:kotlin-stdlib-jre7:$ kotlin_version”
應用插件:“ kotlin-android”
套用外掛程式:'kotlin-android-extensions
並在頂級gradle bulid.gradle(your_app_name)中放
buildscript {
ext.kotlin_version = '1.2.30'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.