【问题标题】:Ignite CLI (React Native) + Facebook SDK = Android Multidex?Ignite CLI (React Native) + Facebook SDK = Android Multidex?
【发布时间】:2020-12-07 00:18:04
【问题描述】:

好的,所以真的只是作为健全性检查发布,并确保我没有做错我的 android。从本质上讲,似乎需要使用multiDexEnabled truenot best practice,因为这意味着应用程序变得“大”,也就是臃肿。但是使用我正在使用的工具只需很少的时间就可以到达那里,我将在下面概述。

TL;DR:使用 multidex 似乎是不好的做法,有没有不同的解决方案?

从一个香草Ignite CLIBowser project开始,一个用于React Native的模板引擎,并根据官方指南添加React Native Facebook SDK,会导致android应用程序的构建错误。

ignite new TestApp

cd TestApp && yarn add react-native-fbsdk && npx react-native link react-native-fbsdk

按照Android Guide,进行相关更改 TestApp/android/app/src/main/java/com/testapp/MainApplication.javaTestApp/android/settings.gradle

然后,按照链接的 Facebook SDK 指南 (auth wall),对 TestApp/android/app/build.gradleTestApp/android/app/src/main/res/values/strings.xmlTestApp/android/app/src/main/AndroidManifest.xml 进行了相关更改

然后,运行 npx react-native run-android,会导致以下构建错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDexDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
     The number of method references in a .dex file cannot exceed 64K.
     Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

更多搜索指向在模块build.gradle 中将multiDexEnabled true 添加到defaultConfig 的修复,这确实修复了错误。问题是,这些解决方案中的大多数也导致其他人指出图书馆管理不善、导入过多等。

那么,我是不是做错了什么,或者这只是使用 Facebook SDK 和 Ignite CLI 的结果,而我对此无能为力?我只是担心,因为我希望将多个提供商的 OAuth 添加到应用程序中,但不想要一个永远不会加载的臃肿应用程序。

【问题讨论】:

    标签: android react-native fbsdk


    【解决方案1】:

    这与您项目中使用的库无关,而与使用的方法数量有关。

    When your app and the libraries it references exceed 65,536 methods, you encounter a build error that indicates your app has reached the limit of the Android build architecture 需要开启multidex才能支持更多方法。

    https://developer.android.com/studio/build/multidex

    【讨论】:

    • 我会说你引用的确实是指使用的库,而不仅仅是使用的方法。我已经说过我已经启用了 multidex,我想知道是否还有其他我没有看到的解决方案
    猜你喜欢
    • 1970-01-01
    • 2016-08-22
    • 1970-01-01
    • 2022-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-09
    • 1970-01-01
    相关资源
    最近更新 更多