Unresolved reference in Kotlin 1.0 release


#1

Here’s the build.gradle file.

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

android {
compileSdkVersion 23
buildToolsVersion “23.0.2”

defaultConfig {
    applicationId "com.example.myapplication"
    minSdkVersion 8
    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(include: [’*.jar’], dir: ‘libs’)
compile 'com.android.support:appcompat-v7:23.1.1’
compile 'com.android.support:design:23.1.1’
compile 'org.jetbrains.kotlin:kotlin-stdlib:1.0.0’
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"
classpath “org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version”
}
}
repositories {
mavenCentral()
}


#2

Which reference is unresolved? Could you please add a piece of code with this reference?


#4

Please enable Kotlin Android Extensions in Gradle:

apply plugin: 'kotlin-android-extensions'

(classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" is not needed anymore).


#5

Thanks,it works。
But i when i build the apk and run on my Phone。
It’s crashed then print the error message :
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.jun.myapplication/com.example.myapplication.MainActivity}: java.lang.ClassNotFoundException: Didn’t find class “com.example.myapplication.MainActivity” on path: DexPathList

My manifest file already register it:

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>