2017-09-26 173 views
-2

我嘗試開始遷移基於Java multidexed項目科特林但我得到的ClassNotFoundException每當應用程序試圖引用一個科特林類。奇怪的是,有時候相同的代碼有時不起作用。有計算機產生工作apk和其他人沒有。有時重建足以解決問題。ClassNotFoundException的引用科特林類時

我試圖谷歌,但我只找到this線程,但沒有解決。這個東西是否適用於其他人或者沒有任何多指標Kotlin項目?

我試着AS 2.3.3和3.0.0 AS-beta6,2.3.3安卓plugun,kotoin版本1.1.50,沒有proguard的

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" 
+0

需要更多信息。比如哪個類發生了ClassNotFoundException? – Krish

+0

任何職業轉換爲Kotlin。第一次引用這樣的類時會發生崩潰。例如,當我轉換我的SplashActivity時,應用程序甚至無法啓動。 – guni

回答

0

最後我終於解決了這個問題!這個異常是由一個RetroLambda錯誤引起的,在我更新到3.7.0後很幸運地消失了。該構建是非確定性的,因爲它看起來像gradle clean並不會刪除所有內容。在手動刪除應用程序和根模塊中的構建文件夾之後,結果變得確定。

0

如果您使用的是Java 8,那麼您還應該使用Kotlin jre8。

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

不錯的觀察,但它不會編譯。我試過用org.jetbrains.kotlin:kotlin-stdlib,但結果與jre7相同。 – guni