unity-jar-resolver icon indicating copy to clipboard operation
unity-jar-resolver copied to clipboard

Cannot use it with AndroidX

Open ber4444 opened this issue 6 years ago • 22 comments

My dependencies are

    <androidPackage spec="androidx.appcompat:appcompat:1.0.0-rc01"/>
    <androidPackage spec="androidx.legacy:legacy-support-v4:1.0.0-rc01"/>
    <androidPackage spec="androidx.browser:browser:1.0.0-rc01"/>

update: after adding xmlns:tools=”http://schemas.android.com/tools” to the manifest, I am now down to this error:

CommandInvokationFailure: Failed to re-package resources.
/home/gabor/Android/Sdk/build-tools/28.0.1/aapt package --auto-add-overlay -v -f -m -J "gen" -M "AndroidManifest.xml" -S "res" -I "/home/gabor/Android/Sdk/platforms/android-28/android.jar" -F bin/resources.ap_ --extra-packages com.chartboost.sdk.unity:android.arch.lifecycle:androidx.appcompat:androidx.arch.core:androidx.asynclayoutinflater:.........
/home/gabor/7.2.1/Temp/StagingArea/android-libraries/androidx.appcompat.appcompat-1.0.0-rc01/res/layout/abc_action_mode_close_item_material.xml:17: note: removing attribute http://schemas.android.com/apk/res/android:layout_marginEnd from <ImageView>
........ (and many similar errors)

If I switch from "internal" to "gradle" build system, the error changes to: : com.android.dex.DexException: Multiple dex files define Landroid/support/v4/media/MediaBrowserCompat$CallbackHandler;

Others are also having problems:

  • https://stackoverflow.com/questions/51683306/
  • https://stackoverflow.com/questions/50697192

ber4444 avatar Aug 20 '18 20:08 ber4444

@ber4444 I'm a little confused, how is this related to this plugin? All the Android Resolver does is download and integrate Android libraries into your Unity project. Perhaps this is a problem with the androidx library?

stewartmiles avatar Aug 21 '18 17:08 stewartmiles

I filed the issue here because I would assume Google would add support for their own libraries to their own Unity plugin. Maybe it will be a collaborative effort with Unity (the company) but again, I would assume you can work together on this as two giant size companies. As to your comment, "integrate Android libraries into your Unity project" is definitely bogus if said official android libraries fail to integrate in any meaningful way. Filing an issue under androidx (another open source project) would be an option but I doubt they have a clue about Unity3D as such.

ber4444 avatar Aug 21 '18 18:08 ber4444

@ber4444 this project is staffed by folks shipping Unity plugins at Google. We're certainly not on the hook for compatibility testing all possible Google Android libraries with Unity. I recommend opening an issue with the Android support library folks since they would know how it's expected to work and will be able to speak to the environments they support.

stewartmiles avatar Aug 21 '18 18:08 stewartmiles

I filed an issue here: https://issuetracker.google.com/issues/112871299 but the number one Google Android library (AndroidX since the legacy one will not be developed going forward) is not that extreme "all possible Google Android libraries" you wrote about.

ber4444 avatar Aug 21 '18 19:08 ber4444

@ber4444 I'm wondering whether you're mixing androidx.* dependencies and the old Android support libraries in your project or if this is just androidx.?

i.e the migration outlined in https://android-developers.googleblog.com/2018/05/hello-world-androidx.html is not currently automatically supported in the Android Resolver plugin. TBH I would prefer that we didn't add yet more one-off hacks to deal with things like this.

stewartmiles avatar Aug 21 '18 20:08 stewartmiles

Part of the problem, is that both old and new libs are downloaded by your jar resolver:

7.2.1/Assets/Plugins/Android/android.arch.lifecycle.common-1.0.0.jar
7.2.1/Assets/Plugins/Android/androidx.arch.core.core-common-2.0.0-rc01.jar
7.2.1/Assets/Plugins/Android/androidx.annotation.annotation-1.0.0-rc01.jar
7.2.1/Assets/Plugins/Android/android.arch.core.common-1.0.0.jar
7.2.1/Assets/Plugins/Android/androidx.lifecycle.lifecycle-common-2.0.0-rc01.jar
7.2.1/Assets/Plugins/Android/androidx.collection.collection-1.0.0-rc01.jar
7.2.1/Assets/Plugins/Android/com.android.support.support-annotations-26.1.0.jar

Try with the sample project I attached to https://issuetracker.google.com/issues/112871299

ber4444 avatar Aug 23 '18 20:08 ber4444

@ber4444 I've contacted the team internally. I see what you mean that this will result in quite a mess when including plugins that use the new androidx.* package structure with those that use the old android.* package structure. Also, old libraries will need to be rewritten by the jetifier to reference the new support libraries.

stewartmiles avatar Aug 30 '18 15:08 stewartmiles

@stewartmiles Can you describe how the android.support dependencies are being pulled in by the JAR resolver? Jetifier can't rewrite the android.support libraries themselves in this case -- it's only intended to rewrite libraries that depend on android.support.

alanv avatar Feb 21 '19 15:02 alanv

@alanv lets discuss this internally on b/113575309

stewartmiles avatar Mar 05 '19 17:03 stewartmiles

@ber4444 Jetifier is partially integrated with some caveats as explained in the release notes, feel free to give it a try.

stewartmiles avatar Jun 18 '19 18:06 stewartmiles

@stewartmiles i have imported latest version of unity jar resolver(1.2.118). On enabling Use Jetifeir i'm getting an exception. Snapshot of the error is attached below. error

mtahaGamerz avatar Jun 19 '19 12:06 mtahaGamerz

@mtahaGamerz which version of Unity are you using?

stewartmiles avatar Jun 19 '19 16:06 stewartmiles

@mtahaGamerz I pulled down the latest 2019 release and I'm seeing the issue now.

Stopped polling job due to exception: System.Reflection.TargetParameterCountException: parameters do not match signature
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0003c] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:188 
  at GooglePlayServices.UnityCompat.get_SDKToolsInst () [0x0002c] in Z:\tmp\tmp.AsZ9ozGX6p\third_party\unity\unity_jar_resolver\source\PlayServicesResolver\src\UnityCompat.cs:173 
  at GooglePlayServices.UnityCompat.FindNewestInstalledAndroidSDKVersion () [0x00020] in Z:\tmp\tmp.AsZ9ozGX6p\third_party\unity\unity_jar_resolver\source\PlayServicesResolver\src\UnityCompat.cs:219 
  at GooglePlayServices.UnityCompat.GetAndroidTargetSDKVersion () [0x0004d] in Z:\tmp\tmp.AsZ9ozGX6p\third_party\unity\unity_jar_resolver\source\PlayServicesResolver\src\UnityCompat.cs:119 
  at GooglePlayServices.PlayServicesResolver.CanEnableJetifierOrPromptUser () [0x000a8] in Z:\tmp\tmp.AsZ9ozGX6p\third_party\unity\unity_jar_resolver\source\PlayServicesResolver\src\PlayServicesResolver.cs:2213 
  at GooglePlayServices.PlayServicesResolver.ResolveUnsafe (System.Action`1 resolutionComplete, Boolean forceResolution, Boolean isAutoResolveJob) [0x00012] in Z:\tmp\tmp.AsZ9ozGX6p\third_party\unity\unity_jar_resolver\source\PlayServicesResolver\src\PlayServicesResolver.cs:1607 
  at GooglePlayServices.PlayServicesResolver+<ScheduleResolve>c__AnonStorey6.<>m__0 () [0x00000] in Z:\tmp\tmp.AsZ9ozGX6p\third_party\unity\unity_jar_resolver\source\PlayServicesResolver\src\PlayServicesResolver.cs:1581 
  at GooglePlayServices.PlayServicesResolver.ExecuteNextResolveJob () [0x00069] in Z:\tmp\tmp.AsZ9ozGX6p\third_party\unity\unity_jar_resolver\source\PlayServicesResolver\src\PlayServicesResolver.cs:1455 
  at GooglePlayServices.PlayServicesResolver.ScheduleResolve (Boolean forceResolution, System.Action`1 resolutionCompleteWithResult, Boolean isAutoResolveJob) [0x000a0] in Z:\tmp\tmp.AsZ9ozGX6p\third_party\unity\unity_jar_resolver\source\PlayServicesResolver\src\PlayServicesResolver.cs:1592 
  at GooglePlayServices.PlayServicesResolver.AutoResolve (System.Action resolutionComplete) [0x0001c] in Z:\tmp\tmp.AsZ9ozGX6p\third_party\unity\unity_jar_resolver\source\PlayServicesResolver\src\PlayServicesResolver.cs:1130 
  at GooglePlayServices.PlayServicesResolver.<ScheduleAutoResolve>m__8 () [0x00016] in Z:\tmp\tmp.AsZ9ozGX6p\third_party\unity\unity_jar_resolver\source\PlayServicesResolver\src\PlayServicesResolver.cs:1109 
  at Google.RunOnMainThread.ExecutePollingJobs () [0x0004a] in Z:\tmp\tmp.QSjn4ASG59\third_party\unity\unity_jar_resolver\source\VersionHandlerImpl\src\RunOnMainThread.cs:300 
UnityEngine.Debug:LogError(Object)
Google.RunOnMainThread:ExecutePollingJobs() (at Z:/tmp/tmp.QSjn4ASG59/third_party/unity/unity_jar_resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:303)
Google.RunOnMainThread:<ExecuteAll>m__1() (at Z:/tmp/tmp.QSjn4ASG59/third_party/unity/unity_jar_resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:414)
Google.RunOnMainThread:RunAction(Action) (at Z:/tmp/tmp.QSjn4ASG59/third_party/unity/unity_jar_resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:234)
Google.RunOnMainThread:ExecuteAll() (at Z:/tmp/tmp.QSjn4ASG59/third_party/unity/unity_jar_resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:406)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

Debugging...

stewartmiles avatar Jun 19 '19 22:06 stewartmiles

@mtahaGamerz try https://github.com/googlesamples/unity-jar-resolver/releases/tag/v1.2.119

stewartmiles avatar Jun 20 '19 00:06 stewartmiles

@stewartmiles the issue i reported has been resolved in this new update. Thanks for this. But the actual issue that i'm facing is that i'm having both the new Androidx files & the old com.android files. The plugin which i'm using in my project requires old com.android.support.support-v4-26.1.0. file and other old files. Can you please help me out in this regard? I'm using unity version 2018.2.6f1. The snapshot of my plugin folder is attached below. Plugin

mtahaGamerz avatar Jun 20 '19 05:06 mtahaGamerz

None of my dependencies require AndroidX, but PlayResolver still imports androidx libraries, although the project works fine with 28 libs. You should just have a checkbox "I don't want to import androidx libs".

revolt3r avatar Jun 21 '19 09:06 revolt3r

I had the following problem with AndroidX and facebook library for unity:

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

I updated unity-jar-resolver version to 1.2.120 and enabled Use Jetiffier on Assets -> GooglePlayResolver -> Android Resolver -> Settings and it works!.

nanox77 avatar Jun 27 '19 15:06 nanox77

@revolt3r Google Play Services moved to AndroidX which means that if you're using anything Google you're likely going to have to migrate to AndroidX especially since the old Android Support Library and AndroidX are in some cases incompatible with each other.

stewartmiles avatar Jun 27 '19 15:06 stewartmiles

@revolt3r Google Play Services moved to AndroidX which means that if you're using anything Google you're likely going to have to migrate to AndroidX especially since the old Android Support Library and AndroidX are in some cases incompatible with each other.

How to migrate to AndroidX in unity

anwar96se avatar Jul 05 '19 09:07 anwar96se

@anwarse25 The https://github.com/googlesamples/unity-jar-resolver/issues/145#issuecomment-506400108 from nanox77 above details on how to enable Jetifier which will update all depencies to AndroidX in Unity.

Here is a step by step with some more detail though

  1. Download the latest version of this plugin.
  2. Open this to import into your Unit project.
  3. Accept the replacement of these files if prompted
  4. I recommend restarting Unity here now, sometimes DLLs don't reload themselves
  5. After reopening your project go to Assets > Play Services Resolver > Android Resolver > Settings and check "Use Jetifier" and press OK
  6. Run Assets>Play Services Resolver>Android Resolver>Force Resolve` if nothing happened after pressing ok.

If you still run into issues I recommend trying the following additional steps. This seems necessary if there are any .aar / .jar files there were not added to your project via a this plugin.

  1. Go to File > Build Settings... then click on the "Player Settings..." button.
  2. From here go to Publishing Settings and check "Custom Gradle Template".
    • If this was enabled already you should rename your mainTemplate.gradle file so it is regenerated, as it may contain out of date settings.
  3. Go to Assets > Play Services Resolver > Android Resolver > Settings and check "patch mainTemplate.gradle" and press OK.

jkasten2 avatar Jul 10 '19 08:07 jkasten2

@jkasten2 If you still run into issues I recommend trying the following additional steps. This seems necessary if there are any .aar / .jar files there were not added to your project via a this plugin.

Go to File > Build Settings... then click on the "Player Settings..." button. From here go to Publishing Settings and check "Custom Gradle Template" Go to Assets > Play Services Resolver > Android Resolver > Settings and check "patch mainTemplate.gradle" and press OK.

Well, this definitely added all dependent libraries after creating build in Android Studio. One thing to mention, that I used Custom Gradle Template at some point in past and inside were some obsolete (possible conflicting) lines, so before enable this option I deleted "mainTemplate.gradle.DISABLED" file and when this option is enabled "mainTemplate.gradle" was recreated with all new stuff. This is just to mention for those that are unsure (like I wasn't) and save some time.

dmax1 avatar Aug 11 '19 21:08 dmax1

@dmax1 Good point, if this file was modified and contains old or bad settings it would be a good idea to rename it so it is regenerated at this point. I updated my reply above.

jkasten2 avatar Aug 13 '19 10:08 jkasten2