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

标签 android gson

<分区>

我在构建中遇到此错误“无法在单个 dex 文件中放入请求的类(# methods: 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
}

最佳答案

您收到此错误是因为您已达到(并超过)android 构建架构的限制 - 单个 DEX 文件只能包含大约 64,000 个引用。

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

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

关于android - 无法将请求的类放入单个 dex 文件中(# methods : 72443 > 65536),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55341484/

相关文章:

android - 使用gson解析json文件

java - 无法使用 Gson 反序列化 List 对象

java - POJO 属性的 GSON 映射空值

Java android room 对象来映射

XML中的Android位图图像大小

android - 在android布局中创建水平虚线

android - 为什么我的相对布局不占用整个屏幕高度

Android KitKat multidex 应用程序崩溃

java - 从数据库加载数据时的德语字符编码问题

android - Google Gson 2.4 minifyEnable 真正的问题