无法将请求的类放入单个dex文件中(#方法:72443> 65536)

时间:2019-03-25 15:41:47

标签: android gson

我在构建中遇到此错误“无法在单个dex文件中容纳请求的类(#方法:72443> 65536)”我试图添加IBM chatbot,但出现此错误。

我正在尝试将IBM chatbot包含到该应用程序中,并且尝试实现gson,但仍无法正常工作

等级构建:模块

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'

等级:项目

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

1 个答案:

答案 0 :(得分:2)

收到此错误是因为您已经达到(并超过了)Android构建体系结构的限制-单个DEX文件只能容纳大约6.4万个引用。

要解决此问题,您有两种选择:

  • 使用multi-dex -这意味着您将在APK中拥有多个dex文件,而不仅仅是一个DEX文件。您可以按照this tutorial来在构建文件中进行设置。这可能会影响您的最低SDK版本。
  • 使用Proguard或R8 -除其他功能外,这些工具还提供代码收缩。这意味着将删除所有使用的代码,因此不应达到64k引用的限制。您可以按照this tutorial设置代码收缩。