How does the kotlin file run on android studio 3.0 Canary 4?

守給你的承諾、 提交于 2019-12-25 08:57:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!