AndroidX CoreComponentFactory problem on 2019.3

My project is building fine on Unity 2018.4 - 2019.2 when i switch to Unity 2019.3.0b7 - 2019.3.0b10 - 2020.1
I am getting error:

Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:1
is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:3-121 to override.

if i add tools:replace="android:appComponentFactory it start to show:

java.lang.RuntimeException: Duplicate class android.support.customtabs.ICustomTabsCallback found in modules classes.jar (androidx.browser:browser:1.0.0) and classes.jar (com.android.support:customtabs:27.0.2)
  Duplicate class android.support.customtabs.ICustomTabsCallback$Stub found in modules classes.jar (androidx.browser:browser:1.0.0) and classes.jar (com.android.support:customtabs:27.0.2)
  Duplicate class android.support.customtabs.ICustomTabsCallback$Stub$Proxy found in modules classes.jar (androidx.browser:browser:1.0.0) and classes.jar (com.android.support:customtabs:27.0.2)
  Duplicate class android.support.customtabs.ICustomTabsService found in modules classes.jar (androidx.browser:browser:1.0.0) and classes.jar (com.android.support:customtabs:27.0.2)
  Duplicate class android.support.customtabs.ICustomTabsService$Stub found in modules classes.jar (androidx.browser:browser:1.0.0) and classes.jar (com.android.support:customtabs:27.0.2)
  Duplicate class android.support.customtabs.ICustomTabsService$Stub$Proxy found in modules classes.jar (androidx.browser:browser:1.0.0) and classes.jar (com.android.support:customtabs:27.0.2)
  Duplicate class android.support.customtabs.IPostMessageService found in modules classes.jar (androidx.browser:browser:1.0.0) and classes.jar (com.android.support:customtabs:27.0.2)
  Duplicate class android.support.customtabs.IPostMessageService$Stub found in modules classes.jar (androidx.browser:browser:1.0.0) and classes.jar (com.android.support:customtabs:27.0.2)
  Duplicate class android.support.customtabs.IPostMessageService$Stub$Proxy found in modules classes.jar (androidx.browser:browser:1.0.0) and classes.jar (com.android.support:customtabs:27.0.2)
  Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
  Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
  Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
  Duplicate class android.support.v4.graphics.drawable.IconCompatParcelizer found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
  Duplicate class android.support.v4.os.IResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
  Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
  Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
  Duplicate class android.support.v4.os.ResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
  Duplicate class android.support.v4.os.ResultReceiver$1 found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
  Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
  Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
  Duplicate class androidx.core.graphics.drawable.IconCompatParcelizer found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
  Duplicate class androidx.core.internal.package-info found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
  Duplicate class androidx.versionedparcelable.CustomVersionedParcelable found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
  Duplicate class androidx.versionedparcelable.NonParcelField found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
  Duplicate class androidx.versionedparcelable.ParcelField found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
...

everything is related with classes.jar with is Unity jar

I have view SDK like Facebook, Firebase, Mopub Mediation with start to requer to use AndroidX. Is there a way to resolve it ? Or it is a Unity Bug?

5174993--513629--2019-11-14 15_30_24-huf_tests2 - Untitled - Android - Unity 2019.3.0b7 Trial Version DX11.png

Hey, could you submit a bug report and post the number here? Please make sure you include your project, or at least the piece that reproduces the issue.

Hey @VaidasM I submit a bug report: Case 1199775

1 Like

I am seeing this same error when upgrading from 2018 to 2019.3

I have this problem. Unity 2019.2.15 build okey.

I filed a bug report with Unity. Hopefully they’ll get this sorted soon. Will post here if I find anything out.

Sounds like the issues you’re experiencing could be the same as this one that is currently being investigated by the devs: Unity Issue Tracker - [Android] Gradle build fails with AndroidX libraries

It’s certainly possible. But the issue I’ve been encountering only appeared in 2019.3. That bug you linked has reproducibility since 2018.2.

Might be related : https://forum.unity.com/posts/5472081/

Is it because it changed from apply plugin: 'com.android.application' to apply plugin: 'com.android.library' ?

I found solution for Unity 2019.3
Add file in Plugins/Android/gradleTemplate.properties - using unity settings

org.gradle.jvmargs=-XmxJVM_HEAP_SIZEM
org.gradle.parallel=true
android.useAndroidX=true
android.enableJetifier=true
ADDITIONAL_PROPERTIES

If You wan to enable multidex on android <= 4.4
Add file in Plugins/Android/launcherTemplate.gradle - using unity settings
and add:

// Android Resolver Repos Start
([rootProject] + (rootProject.subprojects as List)).each {
ext {
it.setProperty(“android.useAndroidX”, true)
it.setProperty(“android.enableJetifier”, true)
}
}

dependencies {
implementation project(‘:unityLibrary’)
implementation ‘androidx.multidex:multidex:2.0.1’
}

8 Likes

Nicely done, @RobertTry and thank you for sharing! A couple of quick notes:

  1. I also needed to explicitly enable multidex in the launcherTemplate, like so (added last line):
minSdkVersion **MINSDKVERSION**
targetSdkVersion **TARGETSDKVERSION**
applicationId '**APPLICATIONID**'
ndk {
abiFilters **ABIFILTERS**
}
versionCode **VERSIONCODE**
versionName '**VERSIONNAME**'
multiDexEnabled true
}```

2) In your picture, you have the bottom arrow pointing at "Custom Proguard Template", when it should be pointing to "Custom Gradle Properties Template". That said, the written instructions were correct so all good.

Thanks again!
4 Likes

Really helpful @RobertTry

Thank you, works like a charm

Hello guys, can someone help me please to fix this

Im fighting this error for like 5 days already, still can resolve it. Already tried to put in my project.properties file this two lines of code
android.enableJetifier=false
android.useAndroidX=true

Also tried to follow the suggestion of Unity tools:replace=“android:appComponentFactory” , still nothing and tools underlined in red

Hope someone know how to fix it. Thanks in advance

I was seeing this error while trying to upgrade my Unity project to support newer Android dependencies (in my case Mopub 5.17 and Admob).

After updating the custom gradle template to use gradle version 3.4.3 (to solve the previous error “AAPT: error: unexpected element found in ”), I started facing this issue.

This was the only post on the internet that really worked, needed to do the multidex part as well.