Siloé Bezerra Bispo
Siloé Bezerra Bispo

Reputation: 2244

Error when compile and run [NoClassDefFoundError]

I'm spending so many days in a error. When I compile my project in android and run in Android < 5.0

Caused by: java.lang.NoClassDefFoundError: com.squareup.okhttp.Protocol[]

The problem is in the "NoClassDefFoundError", because I removed many parts and I receive the same error in another classes. I already cleaned my project, used the gradlew clean. I googled for many days. Please help me.

My dependencies in the gradle:

dependencies {

compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile files('libs/YouTubeAndroidPlayerApi.jar')

compile('com.facebook.android:facebook-android-sdk:[4,5)') {
    exclude group: 'com.parse.bolts',
            module: 'bolts-tasks'
    exclude group: 'com.parse.bolts',
            module: 'bolts-applinks';
}

compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.apis:google-api-services-youtube:v3-rev145-1.20.0'

compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'info.hoang8f:fbutton:1.0.5'
compile 'com.victor:lib:1.0.1'
compile 'com.melnykov:floatingactionbutton:1.3.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.github.amlcurran.showcaseview:library:5.3.0'
compile 'com.amazonaws:aws-android-sdk-mobileanalytics:2.2.5'
compile 'com.facebook.fresco:fresco:0.7.0'
compile 'com.facebook.fresco:imagepipeline-okhttp:0.7.0'
compile 'com.wang.avi:library:1.0.1'
compile 'com.balysv:material-ripple:1.0.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.github.markushi:circlebutton:1.1'
compile 'com.baoyz.pullrefreshlayout:library:1.2.0'
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.github.jd-alexander:LikeButton:0.1.8'
compile 'com.android.support:multidex:1.0.1'
}

[EDIT]

The module Gradle:

buildscript {
repositories {
    jcenter()
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

The rest of the Project gradle, I'm using flavors, and if I put here will be to long:

defaultConfig {
        applicationId "blacktoad.com.flapprototipo"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 20
        versionName "1.48"

        multiDexEnabled true
    }

    dexOptions {
        javaMaxHeapSize "4g"
        preDexLibraries = false
        jumboMode = true
    }

Upvotes: 0

Views: 310

Answers (2)

Mobile Star
Mobile Star

Reputation: 26

You missed multidex setting in AndroidManifest.xml

<application
   ...
   android:name="android.support.multidex.MultiDexApplication"
   ...
>

If you have already name property in application tag, please add following override function in that class which extends Application instead of AndroidManifest.xml.

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

Of course, you should have that code in build.gradle

android {
    defaultConfig {
        multiDexEnabled true
    }
}

Upvotes: 1

Silo&#233; Bezerra Bispo
Silo&#233; Bezerra Bispo

Reputation: 2244

I resolved!

I add in dependencies: compile 'com.android.support:multidex:1.0.1'

And in my MainActivity I add:

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

Upvotes: 1

Related Questions