我已将 kotlin 插件安装到我的 android studio 项目中。代码符合问题。当我从 java 类调用它时它也会执行。它给了我警告“附加到这个项目的一些 Kotlin 库的格式不受支持。请更新库或插件”。IDE 中也无法识别 println() 函数。
测试.kt
fun foo(){
println("ad")
}
public class iTar{
public fun printAll( vararg a: String ){
for(item in a)println(item)
}
}
构建.Gradle
buildscript
{
ext.kotlin_version = '0.8.679'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
packagingOptions {
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
defaultConfig {
applicationId "xxxxx"
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.codehaus.jackson:jackson-mapper-lgpl:1.9.13'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'org.mapsforge:svg-android:0.4.3'
compile 'com.android.support:support-v4:20.+'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
repositories {
mavenCentral()
}