virtouso
virtouso

Reputation: 569

How to resolve conflict between Android support library and AndroidX?

I'm a unity developer that for solving conflict try to export my project to android studio.

I use both firebase and vungle library. firebase depends on androix-core and vungle depends on support-compat. if i compile both of them i receive compile error:

Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (:androidx.core.core-1.0.0:) and support-compat-27.1.1.jar (support-compat-27.1.1.jar)

if i comment one of them i receive runtime error when game starts. what can i really do?

thanks

Upvotes: 2

Views: 5166

Answers (5)

Mark Nashat
Mark Nashat

Reputation: 768

Try this

Refactor -> Migrate to AndroidX
and rebuild the project after that

OR Replace in gradle-Module-app

 'com.android.support:appcompat-v7:28.+'
 'com.android.support.constraint:constraint-layout:1.0.2'

with

'androidx.appcompat:appcompat:1.1.0'
'androidx.constraintlayout:constraintlayout:1.1.3'

Upvotes: 0

Vincent Plus
Vincent Plus

Reputation: 260

Vungle SDK supports androidx since 6.5, and it is in early access right now.If you want to use 6.4.11, it will be great to use Android Studio Gradle tools to do the migration as other answers mentioned. Then the issue should be fixed with SDK 6.4.11. But in case, someone does not want to export an Android Studio project and still want to use SDK 6.4.11. You can follow the document here to migrate Vungle SDK by yourself without Android Studio. What you need to do is:

  1. Download jetifier and unzip it
  2. Use terminal and cd to the folder(mac)
  3. Download the SDK 6.4.11 and Drag the SDK 6.4.11 jar/aar to the folder jetifier-standalone⁩/bin

The last steps run the command below:

./jetifier-standalone -i publisher-sdk-android-6.4.11.aar -o publisher-sdk-android-6.4.11-androidx.aar

OR

./jetifier-standalone -i vungle-android-sdk-6.4.11.jar -o vungle-android-sdk-6.4.11-androidx.jar
./jetifier-standalone -i vng-moat-mobile-app-kit-2.5.1.jar -o vng-moat-mobile-app-kit-2.5.1-androidx.jar

Please make sure to convert two libs if you use the jar file to integrate.

Please use JD-GUI to check the jar/aar and make sure the migration has been done. I met a failure migration without any error once. So it will be great to check it. You can check the file below: enter image description here enter image description here

At last, if you DO NOT want to do it by yourself, please feel free to download the migrated aar file from my dropbox. I am sure it will be available for a while. Please let me know if anyone need jars.

Upvotes: 1

CristianBanan
CristianBanan

Reputation: 41

You can try

Refactor -> Migrate to AndroidX...

and rebuild the project after that

Upvotes: 0

Umair Iqbal
Umair Iqbal

Reputation: 2069

Add these to your gradle properties and from clicking on file in android studio invalidate Cache restart your studio

android.useAndroidX=true
android.enableJetifier=true

Upvotes: 1

Ronald Petit
Ronald Petit

Reputation: 574

The answer given here points out that the best approach is to stick to AndroidX as is the new library to replace the Android Support, however using androidx in gradle.properties only means that your project is going to use AndroidX but if your classes over the project are still importing the Android Support libraries the same error is going to popup.

If you go to the vungle support site here, there is a section that talks about AndroidX compatibility and says:

AndroidX Compatibility Vungle Android SDK 6.4.11 or earlier versions do not officially support AndroidX. Publishers must use migration tool that is available from Android Studio to transform the SDK and its dependencies (third-party libraries) for AndroidX compatibility. The official support for AndroidX will be available with 6.5.0 which is currently in early access stage, and that version would not need any further transformation to be AndroidX compatible. Please reach out through your Account Manager for early access to 6.5.0 if you needed.

So, you need to import your vungle library to Android Studio and follow the guides (this one), to migrate the entire project to AndroidX and then compile the library and use it over your Unity project. However, I must warn you that this is tricky, sometimes the migrating tool of Android Studio doesn't change all the use cases of the Android Support and even sometimes it doesn't update them to the current AndroidX classes, and you might have to go through each file of the library changing every android support reference to AndroidX, and that might take you days, depending on how big the library is.

OR, and this is a big or, you have to wait for the Vungle Android SDK 6.5.0 that will be compatible with AndroidX.

PD: As stated by Vungle support site, you can also get the current early access SDK of the Vungle 6.5.0, but that might contain bugs as it is still at development.

Upvotes: 1

Related Questions