Unity: Cant build to Android after adding Facebook SDK -- GRADLE ERROR : colliding-attributes

Unity: Cant build to Android after adding Facebook SDK -- GRADLE ERROR : colliding-attributes

统一 2019.3.13

我的项目已经有几个sdks/库.. Unity IAP, 统一推送通知, 铁源, 游戏公园,

当我添加 facebook sdk 并在 Android 上构建时,我遇到了很多错误

我找到了 in the Unity docs here 它说 "Either remove the attribute from the library, or add a tools:replace attribute to your application tag, to indicate how the merge conflict should be resolved."

项目中有两个 AndroidManifest.xml 文件。我在其中任何一个中都找不到与 "componentfactory" 有任何关系。 我也不明白 "suggestion"

Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:3-121 to override.

************ 编辑 *************

在任一 AndroidManifest.xml 文件中,我替换了这一行...

<application>

用这条线...

<application tools:replace="android:appComponentFactory">

在任何一种情况下,我在尝试构建时都会遇到错误.. 如果我在一个文件上这样做,我会得到...

XmlException: 'tools' is an undeclared prefix. Line 4, position 16.

如果我在另一个中这样做,我会得到这些错误...

************** 编辑 2 ****************************

我尝试将这样的应用程序标记 添加到 AndroidManifest.xml 个文件

<application tools:replace="android:appComponentFactory" android:appComponentFactory="@string/app_name">

我遇到了这些错误

删除旧的 SDK 在 "Assets\FacebookSDK\Plugins\Android\libs"

enter image description here

问题细化:

Facebook SDK for Unity 具有 AndroidSupportLibraryResolver 脚本,可将 com.android.support 依赖项添加到 gradle 项目中。此脚本已编译为 FacebookSDK/Plugins/Editor/Facebook。Unity.Editor.dll 因此您无法编辑或删除它。

com.android.support 库已过时。几乎所有其他库和 SDK 都已迁移到 androidx,现在应该可以使用了。

如果你的项目中有这两个依赖项,你会得到这样的错误。 但是有一个名为 jetifier 的工具可以将 com.android.support 依赖项转换为 androidx。您只需要启用此工具即可。

解法:

在此处找到解决方案:https://forum.unity.com/threads/androidx-corecomponentfactory-problem-on-2019-3.777584/#post-5193863

  1. 在 Unity 中转到 Project Settins -> Player -> Android -> Publishing Settings
  2. 启用“自定义主 Gradle 模板”和“自定义 Gradle 属性模板”
  3. 运行 资产 -> Play 服务解析器 -> Android 解析器 -> 强制解析
  4. 打开Assets/Plugins/Android/mainTemplate.gradle并添加
([rootProject] + (rootProject.subprojects as List)).each {
    ext {
        it.setProperty("android.useAndroidX", true)
        it.setProperty("android.enableJetifier", true)
    }
}

就在 // Android Resolver Repos Start 行下方

  1. 打开 Assets/Plugins/Android/gradleTemplate.properties 并添加
android.useAndroidX=true
android.enableJetifier=true

**ADDITIONAL_PROPERTIES**行之前