Kotlin文件如何在android studio 3.0 Canary 4上运行? [英] How does the kotlin file run on android studio 3.0 Canary 4?

查看:68
本文介绍了Kotlin文件如何在android studio 3.0 Canary 4上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们都知道Android Studio可以直接运行java类的主函数,我想以这种方式在Android Studio kotlin语法中进行练习,我只是简单地写了一个Hello Word!结果崩溃了: 在此处输入图片描述

Android Studio也是基于IntelliJ IDEA实现的,我不能认为可用的Android Studio可以简单地编译kotlin文件,所以希望给予答复,谢谢!

以下是一些配置信息:

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()
}

在gradle.properties中设置

android.enableAapt2=false

结果如上所示,谢谢,谁能告诉我发生了什么

解决方案

我不确定这是因为您使用的是java/kotlin依赖关系而不是Android依赖关系,还是预览版本中存在问题.我仍然在一个稳定的Android Studio上,但是我可以创建一个主kt类,然后在子包中以及main/kotlin文件夹下运行它.

我的项目和你的项目之间的区别是我拥有

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

不是您的依赖项(而且我没有您的kotlin gradle依赖项)

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

解决方案

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)

这篇关于Kotlin文件如何在android studio 3.0 Canary 4上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆