2016-01-22 118 views
2

我已經使用parse.com jar創建了一個示例應用程序。在這個項目Buid版本SDK是22(它運行良好)。但是在23之後,我在編譯應用程序時遇到了一些問題。我試圖清理項目,使緩存失效。重建項目等,但我面臨同樣的問題錯誤是:NoClassDefFoundError:com.parse.ParseRequest。 Android解析異常

FATAL EXCEPTION: main 
java.lang.NoClassDefFoundError: com.parse.ParseRequest 
at com.parse.Parse.initialize(Parse.java:184)
我無法找到確切的解決方案。我已經檢查過libs文件夾有jar。我也嘗試了最新的 gradle代碼,但面臨同樣的錯誤。刪除解析jar後,我可以編譯我的項目。我的依賴是

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile files('libs/org.apache.http.legacy.jar') 
    compile 'com.android.support:appcompat-v7:23.1.1' 
    compile 'com.android.support:design:23.1.1' 
    compile 'com.android.support:cardview-v7:23.1.1' 
    compile 'com.google.android.gms:play-services:8.1.0' 
    compile 'de.hdodenhof:circleimageview:1.3.0' 
    compile project(':MaterialShowcaseView') 
    compile files('libs/Parse-1.9.2.jar') 
    compile files('libs/bolts-android-1.2.0.jar') 
    compile files('libs/universal-image-loader-1.9.4.jar') 

} 

如果我改變這種依賴

compile 'com.parse.bolts:bolts-android:1.4.0' 
compile 'com.parse:parse-android:1.12.0'
然後錯誤是不同的。錯誤是:
java.lang.NoClassDefFoundError: com.parse.ParsePlugins$1 
at com.parse.ParsePlugins.restClient(ParsePlugins.java:92) 
at com.parse.Parse.initializeParseHttpClientsWithParseNetworkInterceptors(Parse.java:762) 
at com.parse.Parse.initialize(Parse.java:365) 
at com.parse.Parse.initialize(Parse.java:344)
請建議我,這種依賴關係有什麼問題。在此先感謝

+0

我認爲你必須檢查Export是否被檢查過你的庫:右鍵點擊你的項目 - >「Module settings」 - > Dependencies,然後檢查Export是否被選中... – Opiatefuchs

+0

@ Opiatefuchs我檢查了它的依賴關係我可以看到,這是鏈接http://screencast.com/t/fUynUfMqZ –

+0

@Opiatefuchs是否有任何其他設置,我需要改變?我已經檢查了另外一個罐子正在正常工作,這個依賴 –

回答

3

問題不是解析class.In錯誤的,因爲你,因爲mulitdex沒有處理&動初始化解析的是在應用程序啓動時這就是爲什麼它會給找不到類錯誤錯誤。

以下行添加到build.gradle處理多DEX

要解決的問題是什麼我給我的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() 

} 
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. 

} 

隨着幫助android developer multidex guide MultiDexApplication class

要安裝MultiDex.install我指android developer link

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

建議

Selectively compiling APIs into your executable

不要使用谷歌整個遊戲服務使用時才需要library.From 6.5版,您可以而是選擇性地將Google Play服務API編譯到您的應用中。例如,只包括谷歌飛度和Android穿戴的API,替換下面的行中您的build.gradle文件:

compile 'com.google.android.gms:play-services:8.4.0' 

這些行:

compile 'com.google.android.gms:play-services-fitness:8.4.0' 
compile 'com.google.android.gms:play-services-wearable:8.4.0' 

讓我知道,如果有的話。

+0

@bhavin用建議檢查更新後的答案。通過使用所需的播放服務庫可以解決您的問題,而無需添加multidex。 – user1140237

+1

我還沒有嘗試過你的完整代碼,但「建議」爲我工作。刪除了未使用的播放服務爲我個人的工作不需要multi-dex感謝您的幫助。 –

+0

@bhavinchauhan建議工作thn錯誤是多dex只,所以我的代碼也將工作.. :) – user1140237