Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems trying to generate Kotlin application with Android Studio

-Android Studio 1.5.1, Java 1.7.0 amd64, Ubuntu 15.10

-instaled kotlin-plugin 1.0.0

-created new project with empty activity (API level 15)

-Tools->Kotlin->Configure Kotlin in project

-Default options are selected, All modules, Kotlin plugin version 1.0.0

Generate 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

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

Error:Execution failed for task ':app:compileDebugKotlin'.

Compilation error.

Any idea what's going on?

Thanks in advance

like image 211
jjvr Avatar asked Feb 18 '16 10:02

jjvr


People also ask

Can Android Studio be used for Kotlin?

Android Studio provides full support for Kotlin, enabling you to add Kotlin files to your existing project and convert Java language code to Kotlin. You can then use all of Android Studio's existing tools with your Kotlin code, including autocomplete, lint checking, refactoring, debugging, and more.

Is Kotlin better than Android Studio?

Kotlin is the preferred language for Android development in 2021. Both Java and Kotlin can be used to build performant, useful applications, but Google's libraries, tooling, documentation, and learning resources continue to embrace a Kotlin-first approach; making it the better language for Android today.

How do I set up a Kotlin development environment?

In Android Studio, select Settings/Preferences | Plugins, search Marketplace for Kotlin Multiplatform Mobile, and then install it. The Kotlin plugin should be compatible with the Kotlin Multiplatform Mobile plugin.


1 Answers

I got the same error because i was using "kotlin.kotlindemo" as package name. Just i renamed the package and it is working fine now.

like image 125
Prakash Bala Avatar answered Oct 05 '22 03:10

Prakash Bala