facebook-sdk-for-unity icon indicating copy to clipboard operation
facebook-sdk-for-unity copied to clipboard

Failing to build in Unity 2019.3.0f6 - Conflict with Firebase SDK - Duplicate dependencies

Open AAulicino opened this issue 5 years ago • 40 comments

Checklist

Environment

  • Unity Editor Version: 2019.3.0f6
  • Unity SDK Version: 7.18.0 and 7.18.1
  • Installation Platform & Version: [Android] version any
  • Firebase SDK Version: 6.10.0
  • Unity Jar Resolver Version: 1.2.135

Goals

Build the project

Expected Results

Project is successfully built

Actual Results

Project is failing to build with the following output:

CommandInvokationFailure: Gradle build failed. 
/Applications/Unity/Hub/Editor/2019.3.0f6/PlaybackEngines/AndroidPlayer/OpenJDK/bin/java -classpath "/Applications/Unity/Hub/Editor/2019.3.0f6/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-6.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

stderr[

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':launcher:checkReleaseDuplicateClasses'.
> 1 exception was raised by workers:
  java.lang.RuntimeException: 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:27.0.2)
  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:27.0.2)
  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:27.0.2)
  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:27.0.2)
  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:27.0.2)
  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:27.0.2)
  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:27.0.2)
  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:27.0.2)
  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:27.0.2)
  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:27.0.2)
  
  Go to the documentation to learn how to Fix dependency resolution errors.

Steps to Reproduce

  1. Create new unity 2019.3.0f6 project
  2. Set project build target to Android.
  3. Import Facebook SDK 7.18.0
  4. Import the latest Firebase Analytics SDK 6.10.0 into the project.
  5. Import Unity Jar Resolver v1.2.135 into the project.
  6. Enable mainTemplate.gradle (Player settings -> publishing settings -> check custom gradle template)
  7. Click Assets/Play Services Resolver/Android Resolver/Resolve
  8. Enable Jetifier when prompted
  9. Build the project

OR

  1. Download and open the repro project I made.
  2. Change build target to Android
  3. Build the project

Code Samples & Details

If I build with just Facebook SDK, it works. If I build with just Firebase SDK, it works. If I build with both Facebook SDK and Firebase SDK, it fails.

I made a Repro project following the steps I mentioned before. https://drive.google.com/file/d/1ngzavtEftODND1EpRyNchq3qClpyXl0C/view?usp=sharing

AAulicino avatar Feb 03 '20 20:02 AAulicino

HI @KylinChang , are there any updates on this?

We are not able to build the project on Unity 2019.3. On Android because of this issue, and on iOS, because of #359.

mcrvaz avatar Feb 05 '20 17:02 mcrvaz

Hey @mcrvaz , can you try v7.18.1?

KylinChang avatar Feb 05 '20 22:02 KylinChang

Facing same issue with Facebook SDK v7.18.1 as well.

kashiftasneempro avatar Feb 06 '20 05:02 kashiftasneempro

Facing the same issue with Facebook SDK v7.18.1. Our game can't build right now. Firebase or Facebook temporary disable.

GunLengend avatar Feb 11 '20 12:02 GunLengend

@kashiftasneempro did you delete the old plugin first?

hex avatar Feb 13 '20 13:02 hex

@kashiftasneempro did you delete the old plugin first?

Yes, I did.

kashiftasneempro avatar Feb 14 '20 04:02 kashiftasneempro

I am running into the same problem, has anyone make any progress on this? Seems like a androidx vs support library conflict?

ncinoadam avatar Feb 18 '20 00:02 ncinoadam

Actually: I haven't test this fully yet, but removing

implementation(name: 'com.android.support.support-compat-27.0.2', ext:'aar')

From build.gradle gets me building apk's again. Gonna do some testing to see if anything is broken though.

Update 1: Looks like things are working on my end, Facebook still works and i'm getting Firebase push token initialization correctly.

Update 2: I forgot to mention I also have to remove a line in the Firebase AndroidManifest file the one that is uses-sdk ... 14 When removing those two lines, everything is working great. i've been able to test everything related to my use cases. Hopefully this helps others.

ncinoadam avatar Feb 18 '20 00:02 ncinoadam

Actually: I haven't test this fully yet, but removing

implementation(name: 'com.android.support.support-compat-27.0.2', ext:'aar')

From build.gradle gets me building apk's again. Gonna do some testing to see if anything is broken though.

Update 1: Looks like things are working on my end, Facebook still works and i'm getting Firebase push token initialization correctly.

Update 2: I forgot to mention I also have to remove a line in the Firebase AndroidManifest file the one that is uses-sdk ... 14 When removing those two lines, everything is working great. i've been able to test everything related to my use cases. Hopefully this helps others.

Are you working in Unity?

Unity has mainTemplate.gradle not build.gradle.

kashiftasneempro avatar Feb 19 '20 04:02 kashiftasneempro

Yes this is Unity, instead of building the apk/aab from the editor, I export to Android Studio so I can work through dependencies. It helps a lot when debugging things like this.

ncinoadam avatar Feb 19 '20 12:02 ncinoadam

Hi @ncinoadam , which Firebase modules are you using? Just push notifications?

mcrvaz avatar Feb 19 '20 14:02 mcrvaz

@ncinoadam @kashiftasneempro I managed to solve this by enabling Jetifier and modifying the mainTemplate.gradle file like this:

dependencies {
    implementation 'androidx.multidex:multidex:2.0.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    // Android Resolver Dependencies Start
    implementation 'androidx.appcompat:appcompat:1.0.0'
    // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
    implementation 'androidx.cardview:cardview:1.0.0'
    // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
    implementation 'androidx.cardview:cardview:1.0.0'
    // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
    implementation 'androidx.browser:browser:1.0.0'
    // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:6
...

hex avatar Feb 19 '20 14:02 hex

Hi @ncinoadam , which Firebase modules are you using? Just push notifications?

I'm currently just using the Messaging module, but it wouldn't be hard to figure out the conflicts and fix them for others as well.

ncinoadam avatar Feb 19 '20 18:02 ncinoadam

The problem can be solved by exporting project and build with Android Studio, then migrate with AndroidX by replacing almost old dependencies following @hex mentioned. But that it's not the way it supposed to be, the conflicts now go around package still using old dependencies while AndroidX is enabled after Force Resolve, so hope there is a fix available or official way to build without Exporting project.

GunLengend avatar Feb 20 '20 04:02 GunLengend

Actually: I haven't test this fully yet, but removing

implementation(name: 'com.android.support.support-compat-27.0.2', ext:'aar')

From build.gradle gets me building apk's again. Gonna do some testing to see if anything is broken though.

Update 1: Looks like things are working on my end, Facebook still works and i'm getting Firebase push token initialization correctly.

Update 2: I forgot to mention I also have to remove a line in the Firebase AndroidManifest file the one that is uses-sdk ... 14 When removing those two lines, everything is working great. i've been able to test everything related to my use cases. Hopefully this helps others.

Thanks @ncinoadam, this worked for me using the analytics module.

I agree with @GunLengend, it is a hack to have to mess with files in Android Studio and it should be handled inside Unity without the need to export every time you want build

EDIT: I also want to mention that this problem had nothing to do with the Facebook SDK as I don't have it in my project. I opened an issue here (https://github.com/firebase/quickstart-unity/issues/607) because I had pretty much the same Unity logs output and fixed the issue with what @ncinoadam mentioned, so this seems to be more of a Firebase thing

highpockets avatar Mar 11 '20 08:03 highpockets

What I'm considering right now it's not only Facebook and Firebase issue, but also it can belong to Unity itself. Because enableJetifier and useAndroidX were enabled in Unity mainTemplate.gradle file but when Unity starts the build process, the Jetifier doesn't do its job, it should be migrating all old dependencies to force use AndroidX, but it isn't, and Android Studio can do that trick.

GunLengend avatar Mar 16 '20 03:03 GunLengend

What I'm considering right now it's not only Facebook and Firebase issue, but also it can belong to Unity itself. Because enableJetifier and useAndroidX were enabled in Unity mainTemplate.gradle file but when Unity starts the build process, the Jetifier doesn't do its job, it should be migrating all old dependencies to force use AndroidX, but it isn't, and Android Studio can do that trick.

After upgrading to the newest version of Unity, Facebook SDK, Firebase SDK all Android build issues have gone away. Now I'm battling with iOS in Xcode, but it is unrelated to this SDK.

EDIT: This could be because I had Firebase Analytics enabled previously and now I do not. I wasn't using Facebook SDK when I first got the issue, it was an issue with Mapbox SDK which and it seems they redistribute java libraries instead of updating to Android resolver. I got rid of Mapbox and started using Google maps, so good there, but then I introduced an older version of the Facebook SDK because the documentation of one of my assets requests the older version and I had multiple duplicate classes when introducing it. So I got the new Facebook SDK and I had to adjust the code in the asset that required the older version. Currently I just have Firebase Authentication working, but it still seems to be utilizing androidx.core.core-1.0.0 and that was where most of the duplicate classes were for me. Hopefully this helps

highpockets avatar Mar 16 '20 07:03 highpockets

I have same conflict when adding FB to my project where I have AdMob

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 ... I have newest versions of all SDKs and Unity.

JabluszkoPL avatar Apr 15 '20 08:04 JabluszkoPL

I don't know why you gave me a thumbs down and furthermore why I want to help you after doing so, but I suggest that you delete the com.android.support:customtabs:28.0.0, usually stored at Assets/Plugins/Android/ and see if that fixes your problem.

highpockets avatar Apr 15 '20 08:04 highpockets

Problem is that I am using mainTemplate.gradle instead of having tons of libs in Assets/Plugins/Android/ folder. (have limited space in repository). I did remove all implementation 'com.android.support.XXXX' from it and still have the same problem.

You got thumbs down because Your solution is not for me, When Admin is reading such post like yours, He can close this issue because he will assume that everything is done, when it is NOT. I am supporting lot of projects and solutions like: Export to Android Studio or remove library with is not existing in my project is not a solution.

JabluszkoPL avatar Apr 15 '20 09:04 JabluszkoPL

Good luck bud

highpockets avatar Apr 15 '20 09:04 highpockets

What I'm considering right now it's not only Facebook and Firebase issue, but also it can belong to Unity itself. Because enableJetifier and useAndroidX were enabled in Unity mainTemplate.gradle file but when Unity starts the build process, the Jetifier doesn't do its job, it should be migrating all old dependencies to force use AndroidX, but it isn't, and Android Studio can do that trick.

The problem is both a Google/Unity problem and a Facebook problem. Facebook needs to upgrade their SDK to use AndroidX, pure and simple and this problem goes away. Google/Unity have developed their own version of Jetifier that runs within Unity to patch the problem until companies like Facebook fix it, but Unity's Jetifier doesn't work with the Facebook SDK!

Luckily, Android Studio's Jetifier works fine... and that's literally the only solution to running a Unity game with Facebook SDK and any other library that uses AndroidX.

doom-goober avatar Apr 16 '20 06:04 doom-goober

I had the same issue and switch to v7.19.2 from V7.16 which fixed the issue for me.

LunarInteractiveArts avatar Apr 17 '20 13:04 LunarInteractiveArts

@LunarInteractiveArts I tried 7.19.2 but it didn't work, sadly. However, there's a solution posted on this bug: https://github.com/googlesamples/unity-jar-resolver/issues/360 that does work!

doom-goober avatar Apr 22 '20 18:04 doom-goober

@doom-goober I did try this and it not working or me. Code looks similar to this what Google dependencies resolver is generating: image

JabluszkoPL avatar Apr 23 '20 09:04 JabluszkoPL

Looks like I've found the fix in OneSignal help section. Fix is for Unity ofc. https://documentation.onesignal.com/docs/troubleshooting-unity#section-android-x-compatibility image

gromilQaaaa avatar Apr 23 '20 09:04 gromilQaaaa

I solved it in two steps for Unity 2019.3.11f1:

  1. Go to Edit->Project Settings->Player->Publishing settings->Tick Custom Properties Gradle Template
  2. Go to the newly generated gradleTemplate.properties and add these lines to the top:
android.useAndroidX=true
android.enableJetifier=true

ruslanmamonov avatar Apr 27 '20 12:04 ruslanmamonov

In Unity 2019.2.21, the duplicate class errors are still there even with jetfiier enabled like below

([rootProject] + (rootProject.subprojects as List)).each { ext { it.setProperty("android.useAndroidX", true) it.setProperty("android.enableJetifier", true) } }

jackatfp avatar May 02 '20 11:05 jackatfp

@jackatfp Did you try @gromilQaaaa 's solution? Here's a direct link to the section of the document that got my build working from Unity again: https://documentation.onesignal.com/docs/troubleshooting-unity#unity-20193-or-newer

It's the section where you have to add a file called Assets/Plugins/Android/settingsTemplate.gradle.

This problem frustrated me to no end and I was about resolve myself to building from Android Studio. Only this solution worked consistently for me (I thought the previous one worked but it stopped working for me when I added some other plugins back into my project.) And logically it made some sense: The gradle system was clearly not picking up the jetifier from Unity's post processor and settings but clearly the jetifier was working because it worked in Android Studio which uses gradle. So, a solution that's gradle based seems to make sense.

Anyways it worked for me and I was so annoyed and delighted to find a solution I hope it works for you. Please give it a try! Good luck.

doom-goober avatar May 03 '20 00:05 doom-goober

You're right that it wasn't picking up the jetifier in that case, but you don't need to use the OneSignal solution anymore.

Using newest 2019.3 official version (mine is 2019.3.12f1 atm) you can just use Custom Gradle Properties Template on top of the Main Gradle Template, and add: android.useAndroidX=true android.enableJetifier=true to the newly generated gradleTemplate.properties file.

I have been exporting to Android studio to build with all the SDKs my publisher wants and working through the miseries of Android build errors ever since, as a junior dev I think I encountered every issue, but now I can finally build from within Unity. Jetifier wasn't working with Facebook SDK properly except in Android studio, so if you used enough AndroidX migrated plugins it would be hard to build from within Unity without some hacky changes.

I also usually have to change Plugins/Android/AndroidManifest.xml to have this in application tag: tools:replace="android:appComponentFactory" android:appComponentFactory="leavemealone" also xmlns:tools="http://schemas.android.com/tools" in manifest tag

Yes, it's a random string as I'm not sure what the purpose of this is but it works and fixes my manifest merger build error, oh well.

I can now build with Ironsource (many adapters with it), Facebook SDK, GameAnalytics, Adjust, Firebase, whatever else. Basically just get latest Unity Jar Resolver, check settings remove auto resolve, remove resolve on build, set patch maintemplate and use jetifier to true, force resolve, add any extra dependencies/repos you want, do the gradleproperties trick, build within Unity, done.

mohamad-al-amaary avatar May 04 '20 10:05 mohamad-al-amaary

@doom-goober yes, we tried everything include the solution you mentioned but still doesn't work

jackatfp avatar May 21 '20 11:05 jackatfp

@doom-goober yes, we tried everything include the solution you mentioned but still doesn't work

Did you try the @ruslanmamonov option?

GunLengend avatar Jun 02 '20 10:06 GunLengend

This is also happening to me. I have tried all of the solutions above with no success. Facebook SDK is injecting old dependencies that clash with androidX and EDM4U is not able to solve them.

Example below: implementation 'com.android.support:appcompat-v7:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency implementation 'com.android.support:cardview-v7:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency implementation 'com.android.support:cardview-v7:26.0.2' // Assets/Packages/XXX.CustomerSupport/Helpshift/Editor/HelpshiftDependencies.xml:9

Facebook added cardview and another local plugin added it also. Jetifier seems to do nothing. The fix suggested by OneSignal also doesn't solve this issue.

lucasmontec avatar Jul 08 '20 23:07 lucasmontec

Yeah I've resorted to making my own custom version of the Facebook.Unity.Editor.dll so that it doesn't inject the conflicting implementations. But wow, it was not easy to build the facebook SDK... but worked out in the end :)

killerloader avatar Jul 17 '20 09:07 killerloader

I'm struggling with the same issue, however duplicated class is different:

java.lang.RuntimeException: Duplicate class androidx.vectordrawable.graphics.drawable.Animatable2Compat found in modules classes.jar (:vectordrawable-animated-1.0.0:) and classes.jar (androidx.vectordrawable:vectordrawable-animated:1.1.0)

Facebook doesn't seem to be importing this library.

I've tried jetifier tricks, I've tried creating mainTemplate.gradle, including androidx counterparts of legacy libraries, even including vectordrawable library, yet still I'm always getting the same error.

mainTemplate.gradle looks like this:

// Android Resolver Repos Start
([rootProject] + (rootProject.subprojects as List)).each {
    ext {
        it.setProperty("android.useAndroidX", true)
        it.setProperty("android.enableJetifier", true)
    }
}
([rootProject] + (rootProject.subprojects as List)).each { project ->
    project.repositories {
        def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\\", "/")
        maven {
            url "https://maven.google.com"
        }
        maven {
            url (unityProjectPath + "/Assets/GeneratedLocalRepo/Firebase/m2repository") // Assets/Firebase/Editor/AnalyticsDependencies.xml:18, Assets/Firebase/Editor/AppDependencies.xml:22, Assets/Firebase/Editor/AuthDependencies.xml:20, Assets/Firebase/Editor/MessagingDependencies.xml:20
        }
        mavenLocal()
        jcenter()
        mavenCentral()
    }
}
// Android Resolver Repos End
apply plugin: 'com.android.library'
**APPLY_PLUGINS**
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
// Android Resolver Dependencies Start
    //implementation 'com.android.support:appcompat-v7:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
    //implementation 'com.android.support:cardview-v7:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
    //implementation 'com.android.support:customtabs:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
    //implementation 'com.android.support:support-v4:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency
    //implementation 'com.android.support:support-v4:27.1+' // Assets/Editor/VoxelBusters/NativePlugins/NPDependencies.xml:6

    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.browser:browser:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.vectordrawable:vectordrawable-animated:1.0.0'

    implementation 'com.facebook.android:facebook-applinks:[8.0, 9)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:6
    implementation 'com.facebook.android:facebook-core:[8.0, 9)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:5
    implementation 'com.facebook.android:facebook-gamingservices:[8.0, 9)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:9
    implementation 'com.facebook.android:facebook-login:[8.0, 9)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:7
    implementation 'com.facebook.android:facebook-share:[8.0, 9)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:8
    implementation 'com.google.android.gms:play-services-base:17.4.0' // Assets/Firebase/Editor/AppDependencies.xml:17
    implementation 'com.google.firebase:firebase-analytics:17.5.0' // Assets/Firebase/Editor/MessagingDependencies.xml:15
    implementation 'com.google.firebase:firebase-analytics-unity:6.16.0' // Assets/Firebase/Editor/AnalyticsDependencies.xml:18
    implementation 'com.google.firebase:firebase-app-unity:6.16.0' // Assets/Firebase/Editor/AppDependencies.xml:22
    implementation 'com.google.firebase:firebase-auth:19.3.2' // Assets/Firebase/Editor/AuthDependencies.xml:13
    implementation 'com.google.firebase:firebase-auth-unity:6.16.0' // Assets/Firebase/Editor/AuthDependencies.xml:20
    implementation 'com.google.firebase:firebase-common:19.3.1' // Assets/Firebase/Editor/AppDependencies.xml:13
    implementation 'com.google.firebase:firebase-messaging:20.2.4' // Assets/Firebase/Editor/MessagingDependencies.xml:13
    implementation 'com.google.firebase:firebase-messaging-unity:6.16.0' // Assets/Firebase/Editor/MessagingDependencies.xml:20
    implementation 'com.parse.bolts:bolts-android:1.4.0' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:4
// Android Resolver Dependencies End
**DEPS**}

// Android Resolver Exclusions Start
android {
  packagingOptions {
      exclude ('/lib/armeabi/*' + '*')
      exclude ('/lib/mips/*' + '*')
      exclude ('/lib/mips64/*' + '*')
      exclude ('/lib/x86/*' + '*')
      exclude ('/lib/x86_64/*' + '*')
  }
}
// Android Resolver Exclusions End
android {
    compileSdkVersion **APIVERSION**
    buildToolsVersion '**BUILDTOOLS**'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion **MINSDKVERSION**
        targetSdkVersion **TARGETSDKVERSION**
        ndk {
            abiFilters **ABIFILTERS**
        }
        versionCode **VERSIONCODE**
        versionName '**VERSIONNAME**'
        consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD**
    }

    lintOptions {
        abortOnError false
    }

    aaptOptions {
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
    }**PACKAGING_OPTIONS**
}**REPOSITORIES****SOURCE_BUILD_SETUP**
**EXTERNAL_SOURCES**

Other ideas what can be done? I've basically just added facebook sdk to my project and got this error right from the start.

I have latest jar resolver, facebook sdk and firebase sdk.

piotrros avatar Oct 06 '20 13:10 piotrros

I'm still using same method I suggested above (god bless gradle properties) and never had issues since, only things that have changed is that I stopped using Unity's Android SDK and downloaded it myself and changed the path to it in preference, to be able to set the target to api 30 a bit more peacefully. That shouldn't affect much though. Main thing is having EDM settings use jetifier, mainTemplate patching, and force resolving before you build (if you prefer not to have auto resolve on like me). In publishing settings I use custom gradle properties, main template, custom android manifest (i dont really touch main template or the android manifest anymore, I let them be filled by edm and facebook menu edit settings' "regenerate android manifest". If you get duplicate class error with all that being done, then you probably have extra ones in your project that you should remove. If using Adjust for instance you might resolve install referrer and still have another one in your project Plugins folder sitting there that u should delete, but yeah, most of the time if you use the settings I suggested all of these issues simply.. fade away.

TL;DR: Custom Gradle Properties Template, and add:

android.useAndroidX=true
android.enableJetifier=true

Custom Main Template, let EDM4U patch it, Jetifier on, Force resolve before build Custom Main Manifest, let Facebook Regenerate Manifest from its menu Edit Settings thingy, also make sure there are no errors there like PATH or whatever annoying thing facebook has I promise you you can build with a million sdks as I do daily, and I'm just a random junior game developer who went through this stuff a bit too much and resorted to Android Studio until custom gradle properties came out

mohamad-al-amaary avatar Oct 06 '20 15:10 mohamad-al-amaary

Okay, so finally I've found an issue - I had vectordrawable aar file floating around in files - this was causing the issue. Not sure which library copied it, but I've removed this file and all errors went away. Thanks for the hints anyway :)

piotrros avatar Oct 07 '20 07:10 piotrros

@mohamad-al-amaary Could you help me too? I have multiple SDKs implemented (admob, facebook, firebase, etc) and it all builds fine. But when I add a custom plugin (https://assetstore.unity.com/packages/tools/integration/android-install-referrer-179422) I get this error while building: https://pastebin.com/6eRHyi7a

Laur-Ivan avatar May 06 '22 11:05 Laur-Ivan