I want to build my first kotlin project in Android studio 3.0.1 . but i got these 2 errors :
Only the Kotlin standard library is allowed to use the 'kotlin' package .
Error:Execution failed for task ':app:compileDebugKotlin'.
how can i use or add the Kotlin standard library?
manifest:
<?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>
gradle:
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'
}
You set your package name to kotlin.
Change all package kotlin statements in your .kt files to something like package mykotlintest
It's possible to work around this issue by adding the -Xallow-kotlin-package argument when kotlinc is invoked, that's what Kotlin does to build itself. But changing the package name is a cleaner solution.
As error says :
Only the Kotlin standard library is allowed to use the 'kotlin' package
You can not use 'kotlin' for your package name and your Package (applicationId) is :
kotlin.amirreza.mykotlinproject
So you must change it to something else with renaming or creating new applicaton with another package name
As @EmmanuelBourg correctly mentioned, below there is some code to do this
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions.freeCompilerArgs += ["-Xallow-kotlin-package"]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With