3

im encountering this error in the build " Cannot fit requested classes in a single dex file (# methods: 72443 > 65536) " I was trying to add IBM chatbot but i'm getting this error.

Im trying to include IBM chatbot to the app and I tried to implement gson but it isnt still working

Gradle build: Module

apply plugin: 'com.android.application'


ext {
    bintrayRepo = 'maven'
    bintrayName = 'chat-message-view'

    publishedGroupId = 'me.himanshusoni.chatmessageview'
    libraryName = 'chat-message-view'
    artifact = 'chat-message-view'

    libraryDescription = 'Android library to create chat message view easily'

    siteUrl = 'https://github.com/himanshu-soni/ChatMessageView'
    gitUrl = 'https://github.com/himanshu-soni/ChatMessageView.git'

    libraryVersion = '1.0.7'

    developerId = 'himanshu-soni'
    developerName = 'Himanshu Soni'
    developerEmail = 'himanshusoni.me@gmail.com'

    licenseName = 'The Apache Software License, Version 2.0'
    licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
    allLicenses = ["Apache-2.0"]
}

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.lrtapp.ardentmap"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.google.android.gms:play-services-base:15.0.1'
    implementation 'com.google.android.gms:play-services-auth:16.0.0'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-messaging:17.3.1'
    implementation 'com.google.firebase:firebase-storage:11.8.0'
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    implementation 'com.google.maps.android:android-maps-utils:0.5+'
    testImplementation 'junit:junit:4.12'
    implementation 'com.google.firebase:firebase-core:16.0.3'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'me.biubiubiu.justifytext:library:1.1'
    implementation 'com.github.cpiz:BubbleView:1.0.3'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.squareup.okhttp3:okhttp:3.11.0'
    //implementation 'com.google.code.gson:gson:2.8.5'
    //implementation 'com.cpiz.bubbleview:bubbleview:{X.Y.Z}'
    //Google Play Services
    implementation 'com.google.android.gms:play-services-gcm:15.0.1'
    //implementation 'com.google.android.gms:play-services:11.4.0'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation 'com.google.android.gms:play-services-places:15.0.1'
    implementation 'com.github.kittinunf.fuel:fuel-android:1.9.0'
    implementation files('libs/Ab.jar')
    implementation 'me.himanshusoni.chatmessageview:chat-message-view:1.0.3'
    implementation 'com.ibm.watson.developer_cloud:java-sdk:3.7.2'
}
apply plugin: 'com.google.gms.google-services'

Gradle: Project

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }


    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.1.0'



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

}

allprojects {
    repositories {
        google()
        jcenter()
        maven{
            url "https://maven.google.com"
        }
        maven{
            url "https://jitpack.io"
        }
        configurations {
            all*.exclude group: 'com.google.code.gson'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Zoe
  • 27,060
  • 21
  • 118
  • 148
Zeke
  • 107
  • 1
  • 8

1 Answers1

9

You are getting this error because you've reached (and went over) the limit of the android build architecture - a single DEX file can hold only around 64 thousand references.

To fix this issue you have two options:

  • Use multi-dex - this means instead of having just one DEX file, you will have multiple dex files in your APK. You can follow this tutorial to set it in your build files. This might affect your min SDK version.
  • Use Proguard or R8 - among other features, these tools provide code shrinking. This means all of the code that is not used will be removed, and therefore the limit of 64k references should not be reached. You can follow this tutorial to set code shrinking up.
Izabela Orlowska
  • 7,431
  • 2
  • 20
  • 33
  • 2
    in your android\app\build.gradle add multiDexEnabled true to the defaultConfig. And add the following : dependencies { implementation 'com.android.support:multidex:1.0.3' } Read more here: https://developer.android.com/studio/build/multidex – Richardd Aug 06 '19 at 08:54