unity-jar-resolver
unity-jar-resolver copied to clipboard
Cannot use it with AndroidX
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 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?
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 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.
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 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.
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 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 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 lets discuss this internally on b/113575309
@ber4444 Jetifier is partially integrated with some caveats as explained in the release notes, feel free to give it a try.
@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.
@mtahaGamerz which version of Unity are you using?
@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...
@mtahaGamerz try https://github.com/googlesamples/unity-jar-resolver/releases/tag/v1.2.119
@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.
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".
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!.
@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.
@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
@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
- Download the latest version of this plugin.
- Found at the root of this repo named
play-services-resolver-X.X.X.X.unitypackage
- At this time it is play-services-resolver-1.2.122.0.unitypackage
- Found at the root of this repo named
- Open this to import into your Unit project.
- Accept the replacement of these files if prompted
- I recommend restarting Unity here now, sometimes DLLs don't reload themselves
- After reopening your project go to
Assets
>Play Services Resolver
>Android Resolver
>Settings
and check "Use Jetifier" and press OK - 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.
- Go to
File
>Build Settings...
then click on the "Player Settings..." button. - 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.
- If this was enabled already you should rename your
- Go to
Assets
>Play Services Resolver
>Android Resolver
>Settings
and check "patch mainTemplate.gradle" and press OK.
@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 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.