Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity 2019.3+ Android with FB and AdMob or Firebase

Discussion in 'Editor & General Support' started by rtrypuchuuuge, Apr 15, 2020.

  1. rtrypuchuuuge

    rtrypuchuuuge

    Joined:
    May 14, 2019
    Posts:
    9
    Hi,

    I have problem when I am trying to build project on Unity 2019.3 - 2020.1
    I have in my project newest versions of SDKs:
    - Facebook
    - AdMob
    - Firebase

    I did some test and it turn out that google SDKs are using Android X and FB not.
    When I am trying to make a build 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:18-91
    After adding suggested:
    tools:replace="android:appComponentFactory" android:appComponentFactory="whateverString"
    I am getting
    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:28.0.0)
    And more ...

    Is there a way to fore Android X libs ? I am using External Dependency Manage to resolve dependencies, I can not export project to android studio or force someone to not use mainTemplate.gradle. I am from company that is supporting multiple project and such solutions are not for me.

    My mainTemplate.gradle looks like this:

    Code (JavaScript):
    1. // GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
    2.  
    3. // Android Resolver Repos Start
    4. ([rootProject] + (rootProject.subprojects as List)).each {
    5.     ext {
    6.         it.setProperty("android.useAndroidX", true)
    7.         it.setProperty("android.enableJetifier", true)
    8.     }
    9. }
    10. ([rootProject] + (rootProject.subprojects as List)).each { project ->
    11.     project.repositories {
    12.         def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\\", "/")
    13.         maven {
    14.             url "https://maven.google.com"
    15.         }
    16.         maven {
    17.             url "https://maven.google.com/" // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7
    18.         }
    19.         mavenLocal()
    20.         jcenter()
    21.         mavenCentral()
    22.     }
    23. }
    24. // Android Resolver Repos End
    25. apply plugin: 'com.android.library'
    26. **APPLY_PLUGINS**
    27.  
    28. dependencies {
    29.     implementation 'androidx.multidex:multidex:2.0.0'
    30.     implementation fileTree(dir: 'libs', include: ['*.jar'])
    31.     implementation 'androidx.appcompat:appcompat:1.0.0'
    32.     implementation 'androidx.cardview:cardview:1.0.0'
    33.     implementation 'androidx.cardview:cardview:1.0.0'
    34.     implementation 'androidx.browser:browser:1.0.0'
    35.     implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    36. // Android Resolver Dependencies Start
    37.     implementation 'com.facebook.android:facebook-applinks:[6.2.0, 7)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:6
    38.     implementation 'com.facebook.android:facebook-core:[6.2.0, 7)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:5
    39.     implementation 'com.facebook.android:facebook-gamingservices:[6.2.0, 7)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:9
    40.     implementation 'com.facebook.android:facebook-login:[6.2.0, 7)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:7
    41.     implementation 'com.facebook.android:facebook-share:[6.2.0, 7)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:8
    42.     implementation 'com.google.android.gms:play-services-ads:19.0.0' // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7
    43.     implementation 'com.parse.bolts:bolts-android:1.4.0' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:4
    44. // Android Resolver Dependencies End
    45. **DEPS**}
    46.  
    47. // Android Resolver Exclusions Start
    48. android {
    49.   packagingOptions {
    50.       exclude ('/lib/arm64-v8a/*' + '*')
    51.       exclude ('/lib/armeabi/*' + '*')
    52.       exclude ('/lib/mips/*' + '*')
    53.       exclude ('/lib/mips64/*' + '*')
    54.       exclude ('/lib/x86/*' + '*')
    55.       exclude ('/lib/x86_64/*' + '*')
    56.   }
    57. }
    58. // Android Resolver Exclusions End
    59. android {
    60.     compileSdkVersion **APIVERSION**
    61.     buildToolsVersion '**BUILDTOOLS**'
    62.  
    63.     compileOptions {
    64.         sourceCompatibility JavaVersion.VERSION_1_8
    65.         targetCompatibility JavaVersion.VERSION_1_8
    66.     }
    67.  
    68.     defaultConfig {
    69.         minSdkVersion **MINSDKVERSION**
    70.         targetSdkVersion **TARGETSDKVERSION**
    71.         ndk {
    72.             abiFilters **ABIFILTERS**
    73.         }
    74.         versionCode **VERSIONCODE**
    75.         versionName '**VERSIONNAME**'
    76.         consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD**
    77.     }
    78.  
    79.     lintOptions {
    80.         abortOnError false
    81.     }
    82.  
    83.     aaptOptions {
    84.         ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
    85.     }**PACKAGING_OPTIONS**
    86. }**REPOSITORIES**
    87. **IL_CPP_BUILD_SETUP**
    88. **SOURCE_BUILD_SETUP**
    89. **EXTERNAL_SOURCES**
    90.  
     
    thantieuhodo91 and alex_roboto like this.
  2. alex_roboto

    alex_roboto

    Joined:
    Nov 11, 2019
    Posts:
    24
    After spending forever on this, I discovered that Unity's Jetifier can't Jetify the Facebook SDK for some reason. Who knows why. However, Android Studio CAN jetify it... so the only solution for me was to export the project and run from Android Studio.

    1) Install the Facebook SDK if you haven't already. https://developers.facebook.com/docs/unity/. In Unity, Assets > Import Package > Custom Package facebook-unity-sdk-XXXX.unitypackage . Import.
    2) In a text editor, open: Assets/FacebookSDK/Plugins/Editor/Dependencies.xml and remove anything that starts with:
    <androidPackage spec="com.android.support
    This step may not be necessary.
    3) Assets > Player Services Resolver (this name changes with different versions) > Android Resolver > Force Resolve
    4) Make sure File > Build Settings > Export Project is checked. Hit Export button. Choose a directory.
    5) Install Android Studio: https://developer.android.com/studio
    6) In Android Studio, open the directory you exported. If it offers to choose a gradle wrapper for you, accept.
    7) Open gradle.properties in the export directory and add these lines:
    android.useAndroidX=true
    android.enableJetifier=true
    8) Make a build by pressing the "play" arraow. If it offers to refactor your minSDKVersion let it.

    Hopefully this helps. It sucks that Unity's Jetifier doesn't work with the Facebook SDK. Hopefully they will fix it in the future.

    EDIT: Google own the Jetifier that runs in Unity. I have filed this bug: https://github.com/googlesamples/unity-jar-resolver/issues/360
     
    Last edited: Apr 16, 2020
  3. RobertTry

    RobertTry

    Joined:
    Jan 25, 2015
    Posts:
    8
  4. guneyozsan

    guneyozsan

    Joined:
    Feb 1, 2012
    Posts:
    99
    I was getting a similar error with Unity 2019.4.32f1 and Firebase Auth 8.5.0. The solution from the suggested topic resolved it.

    "The attribute application@appComponentFactory=android.support.v4.app.CoreComponentFactory in androidx.corr:core:1.2.0 collides with another value (See the Console for details)"

    Here is the exact link to the solution from the topic:
    https://forum.unity.com/threads/androidx-corecomponentfactory-problem-on-2019-3.777584/#post-5869315

    Particularly, you need to add these lines to the "Project Settings/Android/Publishing Settings/Build/Custom Gradle Properties" in Unity.

    Code (JavaScript):
    1. android.useAndroidX=true
    2. android.enableJetifier=true
    There are other additional steps to do if this does not help, but I didn't need it.