代码之家  ›  专栏  ›  技术社区  ›  guni

引用Kotlin类时发生ClassNotFoundException

  •  -1
  • guni  · 技术社区  · 9 年前

    我试图开始将基于Java的多索引项目迁移到Kotlin,但每当应用程序尝试引用Kotlin类时,我都会遇到ClassNotFoundException。奇怪的是,同一个代码有时有效,有时无效。有些计算机可以生成正常工作的apk,而其他计算机则不能。有时重建就足以解决问题。

    this 线程,但没有解决方案。这件事对其他人正常工作吗?还是还没有任何多索引Kotlin项目?

    我试过AS 2.3.3和AS 3.0.0-beta6,2.3.3 android plugun,kotoin版本1.1.50, .

    buildscript {
    
        ext.kotlin_version = '1.1.50'
        ext.android_plugin_version = '2.3.3'
        ext.support_lib_version = '25.3.1'
        ext.play_services_version = '11.0.4'
    
        repositories {
            jcenter()
            maven {
                url "https://maven.google.com"
            }
        }
        dependencies {
            classpath "com.android.tools.build:gradle:$android_plugin_version"
            classpath 'me.tatarka:gradle-retrolambda:3.2.5'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath 'com.google.gms:google-services:3.0.0'
            classpath 'com.google.firebase:firebase-plugins:1.1.1'
        }
    }
    
    allprojects {
        repositories {
            jcenter()
            maven {
                url "https://maven.google.com"
            }
        }
    }
    
    
    
    apply plugin: "com.android.application"
    apply plugin: "me.tatarka.retrolambda"
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'
    apply plugin: "com.google.firebase.firebase-perf"
    
    repositories {
        mavenCentral()
        jcenter()
        maven {
            url "https://jitpack.io"
        }
    }
    
    android {
        signingConfigs {
            debug {
                ...
            }
        }
    
        compileSdkVersion 25
        buildToolsVersion "25.0.3"
        defaultConfig {
            applicationId "com.my.app"
            signingConfig signingConfigs.debug
            minSdkVersion 14
            targetSdkVersion 25
            versionCode 13
            versionName "2.0.1.b8face5"
            vectorDrawables.useSupportLibrary = true
            multiDexEnabled true
            testInstrumentationRunner "com.my.app.TestRunner"
    
        }
    
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    
        //this is because instabug uses rxjava 1 and now we have both 1 and 2 on the classpath
        packagingOptions {
            exclude "META-INF/rxjava.properties"
        }
    
    
        buildTypes {
            debug {
                applicationIdSuffix ".debug"
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
            release {
    
            }
        }
    }
    
    dependencies {
        compile fileTree(include: "*.jar", dir: "libs")
        // Force usage of support annotations in the test app, since it is internally used by the runner module.
        androidTestCompile("com.android.support.test.espresso:espresso-core:2.2.1") {
            exclude module: "support-annotations"
        }
        androidTestCompile("com.android.support.test.espresso:espresso-contrib:2.2.1") {
            // Necessary to avoid version conflicts
            exclude group: "com.android.support", module: "appcompat"
            exclude group: "com.android.support", module: "support-v4"
            exclude group: "com.android.support", module: "support-annotations"
            exclude module: "recyclerview-v7"
        }
        compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
        compile "com.android.support:appcompat-v7:$support_lib_version"
        compile "com.android.support:recyclerview-v7:$support_lib_version"
        compile "com.android.support:design:$support_lib_version"
        compile "com.android.support:cardview-v7:$support_lib_version"
        compile "com.google.android.gms:play-services-auth:$play_services_version"
        compile "com.google.android.gms:play-services-identity:$play_services_version"
        compile "com.google.android.gms:play-services-location:$play_services_version"
        compile "com.google.android.gms:play-services-maps:$play_services_version"
        compile "com.google.firebase:firebase-core:$play_services_version"
        compile "com.google.firebase:firebase-crash:$play_services_version"
        compile "com.google.firebase:firebase-perf:$play_services_version"
    
        compile "com.google.code.gson:gson:2.8.1"
        compile "com.google.maps.android:android-maps-utils:0.4"
        compile "com.squareup.retrofit2:retrofit:2.3.0"
        compile "com.squareup.retrofit2:converter-gson:2.3.0"
        compile "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
        compile "io.reactivex.rxjava2:rxandroid:2.0.1"
        compile "io.reactivex.rxjava2:rxjava:2.1.3"
        compile "com.squareup.okhttp3:okhttp-urlconnection:3.8.1"
        compile "com.facebook.stetho:stetho:1.5.0"
        compile "com.facebook.stetho:stetho-okhttp3:1.5.0"
        compile "com.squareup.picasso:picasso:2.5.2"
        compile "com.jakewharton:butterknife:8.2.1"
        compile "com.annimon:stream:1.1.8"
        compile "com.github.lawloretienne:quickreturn:0.0.1"
        compile "com.github.chrisbanes:PhotoView:1.2.6"
        compile "fr.baloomba:viewpagerindicator:2.4.2"
        compile "com.github.bluejamesbond:textjustify-android:2.1.6"
        compile "com.turingtechnologies.materialscrollbar:lib:10.1.4"
        compile "com.github.PhilJay:MPAndroidChart:v3.0.1"
        compile "com.android.support:multidex:1.0.1"
        compile "com.bugsnag:bugsnag-android:3.9.0"
        //TODO check periodically whether they upgraded to rxjava 2
        compile "com.instabug.library:instabug:4.2.11"
    
        testCompile "junit:junit:4.12"
        androidTestCompile "com.android.support:support-annotations:$support_lib_version"
        androidTestCompile "com.android.support.test:runner:0.5"
        androidTestCompile "com.android.support.test:rules:0.5"
        annotationProcessor "com.jakewharton:butterknife-compiler:8.2.1"
        compile "com.google.dagger:dagger:2.5"
        annotationProcessor "com.google.dagger:dagger-compiler:2.5"
        provided "javax.annotation:jsr250-api:1.0"
    }
    
    
    apply plugin: "com.google.gms.google-services"
    
    2 回复  |  直到 9 年前
        1
  •  0
  •   guni    9 年前

    我终于解决了这个问题!这个异常是由RetroLambda错误引起的,谢天谢地,在我更新到3.7.0之后就消失了。构建是不确定的,因为gradle clean似乎没有删除所有内容。在我手动删除应用程序和根模块中的build文件夹后,结果变得具有确定性。

        2
  •  0
  •   Bhuvanesh BS    8 年前

    如果您使用的是Java 8,那么也应该使用Kotlin jre8。

     compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"