其他分享
首页 > 其他分享> > 如何防止在Android Gradle中使用Multi-dex

如何防止在Android Gradle中使用Multi-dex

作者:互联网

以下是我的gradle文件.我收到了MultiDexException.我不想启用multidex,因为我的应用程序并不复杂.因此,我坚信我一定做错了什么.有人可以看看我的gradle文件,并指出可以避免该问题的方法吗?

错误:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
    at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
    at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
    at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
    at com.android.dx.command.dexer.Main.run(Main.java:277)
    at com.android.dx.command.dexer.Main.main(Main.java:245)
    at com.android.dx.command.Main.main(Main.java:106)

严重:

buildscript {

        repositories {
    
        maven { url 'https://maven.fabric.io/public' }
    
    }
    
    
    dependencies {
    
        classpath 'io.fabric.tools:gradle:1.+'

        }

    }

    apply plugin: 'com.android.application'
    
apply plugin: 'io.fabric'

    apply plugin: 'com.google.gms.google-services'
    
    
repositories {

        maven { url 'https://maven.fabric.io/public' }
    
}
    
    
    
android {

        compileSdkVersion 23
    
    buildToolsVersion "23.0.1"

    
        defaultConfig {

            applicationId "com.company.app.android"
    
        minSdkVersion 14
    
        targetSdkVersion 23

            versionCode 1

            versionName "1.0"

        }
    
    buildTypes {

            release {
    
            minifyEnabled false
    
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            }

        }

    
    
    }

    
    dependencies {

        compile project(path: ':cloud', configuration: 'android-endpoints')
    
    compile('com.twitter.sdk.android:twitter:1.8.0@aar') {

            transitive = true;

        }

    
        compile 'com.android.support:design:23.0.1'

        compile 'com.android.support:recyclerview-v7:23.0.1'

        compile 'com.android.support:cardview-v7:23.0.1'

        compile 'com.squareup.okhttp:okhttp:2.5.0'

        compile 'com.squareup.picasso:picasso:2.5.2'

        compile 'com.path:android-priority-jobqueue:1.1.2'

        compile 'com.google.android.gms:play-services-gcm:8.1.0'

        compile 'com.google.android.gms:play-services-appindexing:8.1.0'

        compile 'com.google.android.gms:play-services-location:8.1.0'

    }
    

解决方法:

I don’t want to enable multidex because my app is not that complicated

您直接依赖11个工件.您对其他人有间接的依赖关系(例如play-services-maps中的play-services-location拉动),以及可能由Fabric插件提供的依赖项.

简而言之,您的应用程序相当复杂.碰巧的是,您并没有写太多的复杂性.

what I can do to avoid the problem?

使用更少/更小的依赖性.

您已经在使用细粒度的Play Services SDK依赖项,否则,您将在相当一段时间之前达到DEX限制.

您可能会考虑使用一种可用的方法计数工具(例如this Gradle plugin)来更好地了解哪些库对您的费用有所贡献.

标签:android-gradle,android-multidex,multidex,android
来源: https://codeday.me/bug/20191027/1946917.html