我想在Android Studio 3.0.1中构建我的第一个kotlin项目。但是我遇到了这两个错误:
仅允许Kotlin标准库使用'kotlin'软件包。
错误:任务':app:compileDebugKotlin'的执行失败。
我如何使用或添加Kotlin标准库?
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kotlin.amirreza.mykotlinproject">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
等级:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
defaultConfig {
applicationId "kotlin.amirreza.mykotlinproject"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
}
答案 0 :(得分:8)
您将包裹名称设置为kotlin
。
将package kotlin
文件中的所有.kt
语句更改为package mykotlintest
答案 1 :(得分:2)
错误提示:
仅允许Kotlin标准库使用'kotlin'软件包
您不能使用'kotlin'作为您的软件包名称,并且您的软件包(applicationId)为:
kotlin.amirreza.mykotlinproject
因此,您必须通过重命名或使用其他软件包名称创建新的应用程序来将其更改为其他内容
答案 2 :(得分:0)
可以通过在调用kotlinc时添加-Xallow-kotlin-package
参数来解决此问题,这是Kotlin自己构建的目的。但是更改软件包名称是一种更清洁的解决方案。