Kotlin RC NoClassDefFoundError [英] Kotlin RC NoClassDefFoundError

查看:152
本文介绍了Kotlin RC NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将Kotlin更新为RC-1036之后,我面临一个奇怪的问题:我的代码甚至没有被编译和打包.

After updating kotlin to RC-1036 i'm facing a weird issue: my code is not even compiled and packed.

构建通过且应用启动后,我会得到ClassNotFoundException: Didn't find class "example.myapplication.MainActivity".

When build passes and the app is launched i'm getting ClassNotFoundException: Didn't find class "example.myapplication.MainActivity".

我尝试用apktool反编译apk,但未在存档中找到我的类. build/intermediates目录中也没有任何类.

I have tried to decompile apk with apktool and didn't find my classes inside the archive. There are no classes in build/intermediates dir either.

这是我的项目:

app/build.gradle:

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

buildscript {
    ext.kotlin_version = '1.0.0-rc-1036'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
repositories {
    mavenCentral()
}


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "example.myapplication"
        minSdkVersion 21
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    }
    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"
}

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest package="example.myapplication"
      xmlns:android="http://schemas.android.com/apk/res/android">

<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">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

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

MainActivity:

package example.myapplication

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

import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

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

        hello.text = "New text"
    }
}

构建工具版本为2.0.0-beta2sourseSets可能有问题,但是如果我尝试以某种方式对其进行重新配置,则无济于事.感谢任何帮助.

Build tools version is 2.0.0-beta2; Might be something wrong with sourseSets, though nothing works if i try to reconfigure it somehow. Appreciate any help.

推荐答案

您应该同时拥有这两个插件:

You should have both these plugins:

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

第一个确保Kotlin代码可编译,第二个用于UI导入.

The first makes sure the Kotlin code compiles, the second is for the UI imports.

这篇关于Kotlin RC NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆