2016-01-13 24 views
9

,這並不總是可見,但看到特定的API 14和19RoboGuice 3.0 NoClassDefFoundError的:roboguice.inject.ContextScopedRoboInjector

下面是堆棧跟蹤

java.lang.NoClassDefFoundError: roboguice.inject.ContextScopedRoboInjector 
    at roboguice.RoboGuice.getInjector(RoboGuice.java:197) 
    at roboguice.activity.RoboActivity.onCreate(RoboActivity.java:90) 
    at com.bnmcombines.galleryflavors.Launcher.onCreate(Launcher.java:71) 
    at android.app.Activity.performCreate(Activity.java:5343) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441) 
    at android.app.ActivityThread.access$900(ActivityThread.java:151) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
    at android.os.Handler.dispatchMessage(Handler.java:110) 
    at android.os.Looper.loop(Looper.java:193) 
    at android.app.ActivityThread.main(ActivityThread.java:5345) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:515) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644) 
    at dalvik.system.NativeStart.main(Native Method) 

已經一個問題被記錄與RoboGuice 3.0: https://github.com/roboguice/roboguice/issues/328

但沒有迴應,我們目前被封鎖。

解決的問題

我更仔細地提到MultiDex Document這個時間和更新我的AndroidManifest.xml下面,我已經錯過了

<application 
     ... 
     android:name="android.support.multidex.MultiDexApplication"> 
     ... 
    </application> 
</manifest> 
+0

你在你的build.gradle中使用proguard嗎? –

+0

它用於發佈構建類型,而不是在調試,我得到這個錯誤,而調試運行本身 – rsakhale

+0

似乎multidex問題。你在使用multidex進行調試版本嗎? –

回答

1

我建議做如下 -

  1. 檢查這是一個65k方法的限制(multidex)問題,試圖通過Proguard運行發佈版本去除未使用的函數並減少函數在dex中。

  2. 當靜態變量/對象初始化期間拋出異常時,也會導致java.lang.NoClassDefFoundError。檢查您是使用從RoboGuice類繼承的/ /還是使用具有靜態對象或代碼塊的初始化代碼。問題可能來自那裏。

而且,看看RoboGuice 3.0 NoClassDefFoundError: AnnotationDatabaseImpl,它可以幫助你(儘管用戶得到的錯誤是關於另一個階級,他們的初始化是靜態的對象)。

祝你好運。

+0

也沒有其他的運氣。 – rsakhale

+0

比我想說的是現在是時候在RoboGuice回購協議中的GitHub上打開一個問題了...... – FunkSoulBrother

3

從中你在回答

張貼獲取有關API等級14和API等級19設備此錯誤git的鏈接。 在嘗試搜索Class時,我發現這個類是可用的,但仍然得到了奇怪的NoClassDefFoundException。這只是在特定情況下發生的並不總是

這個錯誤會因爲MultiDexApplication。我有面對這種問題,與其他一些庫不相同的庫,但其他一些library.It會把RoboGuice庫的錯誤,因爲它啓動應用程序啓動,其中dex(其中您的RoboGuice庫代碼轉換爲dex)文件不能設置(安裝)。

要解決您需要處理多個Dex文件。與應用程序了build.gradle & Application class

的幫助改變下面這是在build.gradle文件

dexOptions { 
     incremental true 
     // here heap size give 4g i got this thing from https://groups.google.com/forum/#!topic/adt-dev/P_TLBTyFWVY 

     javaMaxHeapSize "4g" 
    } 


dependencies { 
    compile 'com.android.support:multidex:1.0.1' 
    // your dependencies which you are using. 

} 

整個build.gradle

apply plugin: 'com.android.application' 
repositories { 
    mavenCentral()// for new android studio version it can be jcenter() 

} 
configurations { 
// all*.exclude group: 'com.android.support', module: 'recyclerview-v7' 
} 

android { 
    signingConfigs { 
     /* 
     releasebuild { 
      keyAlias 'hellotest' 
      keyPassword 'hellotest' 
      storeFile file('path to keystore') 
      storePassword 'hellotest' 
     } 
     */ 
    } 
    compileSdkVersion 'Google Inc.:Google APIs:22' 
    buildToolsVersion '23.0.0' 
    /* if you got error regarding duplicate file of META-INF/LICENSE.txt from jar file 
    packagingOptions { 
     exclude 'META-INF/LICENSE.txt' 
    } 
    */ 
    dexOptions { 
     jumboMode = true 
     incremental true 
     // here heap size give 4g i got this thing from https://groups.google.com/forum/#!topic/adt-dev/P_TLBTyFWVY 

     javaMaxHeapSize "4g" 
    } 
    defaultConfig { 
     multiDexEnabled true 
     applicationId "com.myapp.packagenme" 
     minSdkVersion 17 
     targetSdkVersion 22 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
      signingConfig signingConfigs.releasebuild 
     } 
     debug { 
      signingConfig signingConfigs.releasebuild 
     } 
    } 
} 

dependencies { 
    compile 'com.android.support:multidex:1.0.1' 
    // your dependencies which you are using. 

} 

如果應用程序使用擴展Applicationclass,您可以覆蓋attachBaseContext要求()方法並調用MultiDex。安裝(this)以啓用multidex。install multipledex file context使用它應該擴展應用程序了類MultiDexApplication

public class MyAppClass extends MultiDexApplication{ 
@Override 
    protected void attachBaseContext(Context newBase) { 
     MultiDex.install(newBase); 
     super.attachBaseContext(newBase); 
    } 
} 

讓我知道,如果有的話。

+0

我試過這個,但由於空間問題沒有幫助,因爲它聲明無法用給定的配置創建Java虛擬機。 – rsakhale

+0

你正在使用哪個IDE ..?如果是工作室,你可以發佈你的build.gradle。 – user1140237

+0

我正在使用Android Studio 1.5.1,我的問題剛剛通過在AndroidManifest.xml中將'android:name =「android.support.multidex.MultiDexApplication」''添加到' rsakhale