简体   繁体   English

尝试使用Android Studio生成Kotlin应用程序时出现问题

[英]Problems trying to generate Kotlin application with Android Studio

-Android Studio 1.5.1, Java 1.7.0 amd64, Ubuntu 15.10 -Android Studio 1.5.1,Java 1.7.0 amd64,Ubuntu 15.10

-instaled kotlin-plugin 1.0.0 -instaled kotlin-plugin 1.0.0

-created new project with empty activity (API level 15) 创建空活动的新项目(API级别15)

-Tools->Kotlin->Configure Kotlin in project -Tools-> Kotlin->在项目中配置Kotlin

-Default options are selected, All modules, Kotlin plugin version 1.0.0 -Default选项被选中,所有模块,Kotlin插件版本1.0.0

Generate build.gradle 生成build.gradle

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

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "kotlin.org.jjvr.kotlinapplication"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),    'proguard-rules.pro'
    }
}
sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
buildscript {
ext.kotlin_version = '1.0.0'
repositories {
    mavenCentral()
}
dependencies {
    classpath "org.jetbrains.kotlin:kotlin-gradle-    plugin:$kotlin_version"
}
}
repositories {
mavenCentral()
}

-open in editor MainActivity.java and convert to Kotlin: - kotlin Code->Convert Java File to Kotlin File - 在编辑器MainActivity.java中打开并转换为Kotlin: - kotlin Code->将Java文件转换为Kotlin文件

import android.support.v7.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
}
}

-while building these errors are listed - 列出构建这些错误

Error: Only the Kotlin standard library is allowed to use the 'kotlin' package 错误:只允许Kotlin标准库使用'kotlin'包

Error:Execution failed for task ':app:compileDebugKotlin'. 错误:任务':app:compileDebugKotlin'的执行失败。

Compilation error. 编译错误。

Any idea what's going on? 知道发生了什么事吗?

Thanks in advance 提前致谢

I got the same error because i was using "kotlin.kotlindemo" as package name. 我得到了同样的错误,因为我使用“kotlin.kotlindemo”作为包名。 Just i renamed the package and it is working fine now. 我刚刚重命名了包,现在工作正常。

As error says : 正如错误所说:

Only the Kotlin standard library is allowed to use the 'kotlin' package 只允许Kotlin标准库使用'kotlin'包

You can not use 'kotlin' for your package name and your Package (applicationId) is : 你不能使用'kotlin'作为你的包名,你的包(applicationId)是:

kotlin.org.jjvr.kotlinapplication kotlin.org.jjvr.kotlinapplication

So you must change it to something else with renaming or creating new applicaton with another package name 因此,您必须通过重命名或使用其他包名创建新应用程序将其更改为其他内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM