Android - MultiDexEnable = true导致Picasso崩溃

时间:2016-02-22 10:53:16

标签: android noclassdeffounderror picasso cometserver

我在gradle文件中使用了MultiDexEnable = true命令来集成cometChat sdk。但是运行正常的Picasso库正在崩溃,现在出现以下错误。你能指导解决方案吗?

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.edesign.astutesol.eyesapp"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
            multiDexEnabled true

    }
    /*repositories {
        maven {
            url 'https://repo1.maven.org/maven2/'
           // url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }
    }*/
    dexOptions {
        javaMaxHeapSize "4g"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

    /*compile('org.apache.httpcomponents:httpmime:4.3.6') {
        exclude module: 'httpclient'
    }
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5'*/
    /*compile 'com.loopj.android:android-async-http:1.4.9'*/
    /*compile 'com.loopj.android:android-async-http:1.4.9-SNAPSHOT'*/
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
    compile 'com.mcxiaoke.volley:library:1.0.15'
    compile 'com.google.android.gms:play-services-appindexing:8.1.0'
    compile 'com.google.android.gms:play-services:8.4.0'
    compile 'com.google.code.gson:gson:2.2.+'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:support-v13:23.1.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    compile 'de.hdodenhof:circleimageview:2.0.0'
}

Log Cat

Process: com.edesign.astutesol.eyesapp, PID: 29018 java.lang.NoClassDefFoundError: com.squareup.picasso.Picasso$1
                                                                               at com.squareup.picasso.Picasso.<clinit>(Picasso.java:109)
                                                                               at com.edesign.astutesol.eyesapp.BaseFragmentActivity.SetDrawer(BaseFragmentActivity.java:81)
                                                                               at com.edesign.astutesol.eyesapp.BaseFragmentActivity.onCreate(BaseFragmentActivity.java:65)
                                                                               at com.edesign.astutesol.eyesapp.MapsActivity.onCreate(MapsActivity.java:152)
                                                                               at android.app.Activity.performCreate(Activity.java:5541)
                                                                               at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
                                                                               at android.app.ActivityThread.access$900(ActivityThread.java:172)
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                               at android.os.Looper.loop(Looper.java:146)
                                                                               at android.app.ActivityThread.main(ActivityThread.java:5653)
                                                                               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:1291)
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
                                                                               at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:6)

使你的应用程序类像bellow

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

在依赖项中添加此库

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

}

答案 1 :(得分:2)

build.gradle

启用该选项后,您需要处理多个dex文件

&安培;如果您的项目中使用的是Application类而不是使用MultiDexApplication&amp;扩展它。处理attachBaseContext

中的多个dex文件

安装MultiDex.install i refer android developer link

例如

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

在AndroidManfiest文件应用程序名称中声明MyAppClass

<application
        android:name="MyAppClass"
android:icon="@drawable/ic_launcher"
        android:label="@string/app_name">
//... your other manifest declaration
</application>

更新了gradle

 apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.edesign.astutesol.eyesapp"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

    }
    /*repositories {
        maven {
            url 'https://repo1.maven.org/maven2/'
           // url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }
    }*/
    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"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:multidex:1.0.1'
    //your dependencies which you are using.
    /*compile('org.apache.httpcomponents:httpmime:4.3.6') {
        exclude module: 'httpclient'
    }
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5'*/
    /*compile 'com.loopj.android:android-async-http:1.4.9'*/
    /*compile 'com.loopj.android:android-async-http:1.4.9-SNAPSHOT'*/
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
    compile 'com.mcxiaoke.volley:library:1.0.15'
    compile 'com.google.android.gms:play-services-appindexing:8.1.0'
    compile 'com.google.android.gms:play-services:8.4.0'
    compile 'com.google.code.gson:gson:2.2.+'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:support-v13:23.1.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    compile 'de.hdodenhof:circleimageview:2.0.0'
}

<强>建议

仅使用所需的播放服务库不添加整组播放服务。 Refer this link。它会减少方法数量和数量。也没用过的图书馆。

实施例

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

使用这些行(根据play-services-fitness play-services-wearable等所需的功能添加artifactId(group):

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

参考我对其他问题的回答