0

Unity 2019.3.13

My project already has several sdks / libraries.. Unity IAPs, Unity push notifications, Ironsource, Gamesparks,

When I added the facebook sdk and went to build on Android I got a lot of errors

enter image description here

I found in the Unity docs here it says "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."

There are two AndroidManifest.xml files in the project. I could not find anything to do with "componentfactory" in either of them. Also I do not understand that "suggestion"

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

************ EDIT *************

In either of the AndroidManifest.xml files I replaced this line...

<application>

with this line...

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

In either case I get errors when trying to build.. If I do do it on one file I get...

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

If I do it in the other one I get these errors...

enter image description here

************** EDIT 2 *************************

I tried an application tag like this, as seen here, to one of the AndroidManifest.xml files

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

And I got these errors

enter image description here

Guye Incognito
  • 2,726
  • 6
  • 38
  • 72

2 Answers2

3

Problem detalization:

Facebook SDK for Unity has AndroidSupportLibraryResolver script which adds com.android.support dependency into gradle project. This script is compiled into FacebookSDK/Plugins/Editor/Facebook.Unity.Editor.dll so you can't edit or remove it.

com.android.support library is obsolete. Almost of all other libraries and SDK already migrated to androidx which should be used now.

If you have both dependencies in your project you will get such error. But there is a tool called jetifier which converts com.android.support dependencies into androidx. You just need to enable this tool.

Solution:

Found solution here: https://forum.unity.com/threads/androidx-corecomponentfactory-problem-on-2019-3.777584/#post-5193863

  1. In Unity go to Project Settins -> Player -> Android -> Publishing Settings
  2. Enable "Custom Main Gradle Template" and "Custom Gradle Properties Template"
  3. Run Assets -> Play Services Resolver -> Android Resolver -> Force Resolve
  4. Open Assets/Plugins/Android/mainTemplate.gradle and add
([rootProject] + (rootProject.subprojects as List)).each {
    ext {
        it.setProperty("android.useAndroidX", true)
        it.setProperty("android.enableJetifier", true)
    }
}

right under // Android Resolver Repos Start line

  1. Open Assets/Plugins/Android/gradleTemplate.properties and add
android.useAndroidX=true
android.enableJetifier=true

before **ADDITIONAL_PROPERTIES** line

d1ke
  • 76
  • 6
0

remove old sdk in "Assets\FacebookSDK\Plugins\Android\libs"

enter image description here