Android MultiDex:永恒的救赎势在必行 [英] Android MultiDex: an all time salvation is imperative

查看:116
本文介绍了Android MultiDex:永恒的救赎势在必行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是连续四天痛苦的旅程的后果,这是连续不断的尝试来克服appDebugAssemble失败构建的过程.我已经阅读了很多有关Google的主题/文章,其中包括"multidex"一词,但无济于事.

This question is the aftermath of a four day long and painful journey of consecutive attempts to overcome a appDebugAssemble failed build. I've read a super considerable amount of topics/articles that google threw at me by looking up anything with the term "multidex" but to no avail.

最近,我开始使用Android Studio 3.0 Beta 4,并相应地将SDK版本更新为Android O build版本.除此之外,我还将AS3b4与Gradle 4.1-all一起使用,到目前为止,我一直在享受新的更新.

Recently I've started using Android Studio 3.0 Beta 4 and updated the SDK versions accordingly to Android O build release. Alongside this, I'm using AS3b4 with Gradle 4.1-all, and up to now, I was enjoying the new updates immensely.

四天前,我决定将Firebase Analytics和Messaging添加到我的项目中,这就是它的发展方向.为简洁起见,我已经从建议(以及SO上公认的答案)中尝试了30多种方法,以了解如何配置MultiDex,并且由于所有方法都无法通过构建,因此我进入了一种开始的状态相信我身上充满了魔咒,尤其是在我即将将自己的应用发布到Play商店的那段时间.我也已经阅读并重新阅读过 https://developer.android.com/studio/build/multidex.html

Four days ago I decided to add Firebase Analytics and Messaging to my project and that's where it went south. For brevity, I've tried more than 30+ approaches from the suggestions (and accepted answers on SO) on how MultiDex should be configured, and since all did not make the build pass, I'm reaching a state where I'm starting to believe that there's a spell cast upon me, particularly around the time I'm about to release my app to Play Store. I've read and reread this too https://developer.android.com/studio/build/multidex.html

不用说,但是您在这里的共同智慧将不胜感激,如果有潜在的解决方案出现,我非常肯定,它将防止许多开发人员变得胆大妄为,或使头脑不稳.现在就可以了,这是我的配置详细信息

It goes without saying, but your shared wisdom here will be much appreciated and if a potential solution comes up, I'm very positive it'll prevent a lot of developers from going bold, or heads being banged against the wall. With that off my chest now, here's my configuration details

app.gradle

apply plugin: 'com.android.application'
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
    minSdkVersion 19
    targetSdkVersion 26
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.config
    }
    debug {
        minifyEnabled false
        debuggable true
        useProguard false
    }
}
dexOptions {
    javaMaxHeapSize "4g"
    preDexLibraries = false
}

dependencies {
    ...
    implementation 'com.android.support:multidex:1.0.2'
}
apply plugin: 'com.google.gms.google-services'

自定义MyApp类

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

期待这个丰富的人才社区将使我和其他遭受同一流行病困扰的人们变得更加富有.谢谢!

Looking forward to what this plentiful community of talents will have to enrich me and other fellow folks suffering from this same epidemic disease. Thank you!

完全忘记粘贴错误日志.这就是我所面临的:

Totally forgot to paste the error log. This is what I'm faced with:

出了什么问题

What went wrong:

任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败.

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

> java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex

> java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

推荐答案

好吧,我想我的研究可以忍受更长的时间,但是我几乎感到绝望了.我终于设法解决了这个问题,因此我仍然将其发布以供将来参考,因为我意识到实际上我们当中很多人都在努力在应用程序中启用MultiDexing.

Ok, I guess I could endure a little longer with my research, but I almost felt hopeless. I finally managed to resolve the issue, so I'm posting it for future reference nevertheless, since I realize there's a lot of us who actually struggle with enabling MultiDexing in our apps.

我的实际问题是 Google Play服务库的重复版本.我使用的是Facebook Audience Network SDK,它依赖于com.google.android.gms:play-services-ads:10.0.4,而我的Firebase实现依赖于11.2.2.

My actual problem was duplicate versions of Google Play Service libraries. I'm using Facebook Audience Network SDK and it relies on com.google.android.gms:play-services-ads:10.0.4, whilst my Firebase implementation depends on 11.2.2.

问题是,除非您提醒自己仔细查看库所依赖的依赖项,否则您真的无法弄清楚这一点,因为就像@AlexLipov在上面所说的那样,错误日志太笼统了".我的灯泡从GitHub上的

The thing is that unless you remind yourself to look in detail for what dependencies your libraries depend on, you really have no way to figure this out because just like @AlexLipov said above "the error log is too generic". My bulb lightened up from this comment on GitHub.

最后,基本上遵循官方 MultiDex指南,如果类似问题弹出,给出一个峰值以识别潜在的依赖冲突,然后执行以下操作以强迫他们相应地使用最新版本.

To conclude, basically follow the official MultiDex guide, then if similar problem pop up, give a peak to identify potential dependency conflicts and then do the following to force them use the recent version accordingly.

implementation('com.facebook.android:audience-network-sdk:4.25.0') {
    exclude group: 'com.google.android.gms'
}

值得一提的最后一点是,运行gradle --stacktrace可以大大缩小问题的范围. 这可能也会派上用场.

A final note worthy of mention, running gradle --stacktrace helps narrow down problems quite a bit. This might come in handy too.

P.S.感谢和Alex的配合.

P.S. Thanks and Alex for chiming in.

这篇关于Android MultiDex:永恒的救赎势在必行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆