无法将请求的类适应单个dex文件 (#方法数:72443 > 65536)。

3

在构建过程中,我遇到了以下错误:“无法将请求的类放入单个dex文件中(#方法:72443>65536)”。我试图添加IBM聊天机器人,但是出现了这个错误。

我尝试将IBM聊天机器人加入应用程序,并试图实现gson,但仍然无法正常运行。

Gradle构建:模块

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: 项目
// 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个回答

9
您会收到此错误是因为您已经达到(并超过)Android构建架构的限制 - 单个DEX文件只能容纳大约64,000个引用。要解决此问题,您有两个选项:
  • 使用多 dex - 这意味着您将不只一个 DEX 文件,而是多个dex文件放入您的APK中。您可以按照这个教程在构建文件中设置它。这可能会影响您的min SDK版本。
  • 使用Proguard或R8 - 在其他功能中,这些工具提供代码缩小。这意味着所有未使用的代码将被删除,因此不应达到64k引用的限制。您可以按照这个教程设置代码缩小。

2
在你的 android\app\build.gradle 文件中,在 defaultConfig 中添加 multiDexEnabled true。并且加入以下代码:dependencies { implementation 'com.android.support:multidex:1.0.3' }点击这里查看更多信息:https://developer.android.com/studio/build/multidex - Richardd

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接