问题
We all know that Android Studio can be directly run java class main function, I would like to practice in this way in Android Studio kotlin syntax, I just simply wrote a Hello Word! The result collapsed: enter image description here
Android Studio is also based on IntelliJ IDEA implementation, I can not think that available Android Studio to simply compile kotlin file, so I hope to give a reply, thank you!
Here are some configuration information:
apply plugin: 'java-library'
apply plugin: 'kotlin'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
}
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
mavenCentral()
}
Set in gradle.properties
android.enableAapt2=false
The results are shown above, who can tell me what's going on,thanks
回答1:
I'm not sure if it's because you are using java/kotlin dependencies as opposed to Android dependencies, or if there's an issue in the Preview build. I'm still on a Stable Android Studio, but I can create a main kt class and run it just fine, both in a subpackage and just below the main/kotlin folder.
The difference between my project and yours is that I have
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
Instead of your dependencies (and I don't have your kotlin gradle dependency)
来源:https://stackoverflow.com/questions/45071117/how-does-the-kotlin-file-run-on-android-studio-3-0-canary-4