googlesamples / unity-jar-resolver

Unity plugin which resolves Android & iOS dependencies and performs version management
Other
1.25k stars 343 forks source link

[FR] Improve Android Resolver resolution and logging when conflicts occur without mainTemplate.gradle #444

Open rotter opened 3 years ago

rotter commented 3 years ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the question here:

I'm a long time user of Jar Resolver (since 2018 or so), but never had to fiddle or understand its inner workings as it always worked fine for me. I always only used Google plugins (Firebase and Admob) and had no issues.

Recently I started using Facebook Audience Network but since a couple months I am having a problem which took me a while to find the root cause. This problem was causing a crash, after a while of debugging I noticed it was using a newer audience-network-sdk (6.5.0) than I was expecting (6.2.0), and for some reason this newer version has issues that are causing the crash that are unrelated to this post/repo. After more debugging I found out that EDM is changing the version to the latest version, and after narrowing it down a bit more I saw on the huge log that it says that there is a conflict, but I fail to understand what is this conflict, or how to solve it:

com.facebook.android:audience-network-sdk conflicting due to package(s):

Then after a few resolve iterations it changes the version to "6+" and that's what causes the SDK version to change to 6.5.0 (which currently is the latest version). But the names are exactly the same (1st line "com.facebook.android:audience-network-sdk:6.2.0" vs the right side of the slash), I dont understand the root cause of this conflict.

There's a second conflict that follows exactly the same pattern: com.google.android.gms:play-services-ads conflicting due to package(s):

Any help is appreciated, thanks in advance!

google-oss-bot commented 3 years ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

paulinon commented 3 years ago

Hi @rotter,

In order to identify what's causing this behavior, could you provide a minimal, reproducible example of your project?

rotter commented 3 years ago

Thanks @paulinon for the response. I have made the following steps to reproduce, which is pretty simple and I believe safer (for both of us) than me sending a project, but if you still prefer the project I can send it, let me know.

1) Created an empty project on Unity (selected 2D template but dont think it makes any difference) 2) Switched to Android 3) Imported FAN 6.2.0 ( https://developers.facebook.com/resources/audience-network-unity-sdk-6.2.0.zip ) 4) Ran Force Resolve and it worked (downloaded version 6.2.0) 5) Imported FAN-AdMob mediation 3.1.0 ( https://dl.google.com/googleadmobadssdk/mediation/unity/facebook/FacebookUnityAdapter-3.1.0.zip ) 6) Ran Force Resolve and it gave the conflicts mentioned and ended up downloading the latest FAN version (6.5.0) which is the undesired effect

Is something mis-configured on Facebook's FAN side? Or on Google's Mediation plugin side? Or is it a problem with jar resolver?

Obs: just found out by chance someone else with the same problem: https://forum.unity.com/threads/solved-gradle-is-not-building-after-importing-facebook-sdk-with-admob-mediation.1102282/

paulinon commented 3 years ago

Thanks for providing more information, @rotter. While I try to do these steps, could you try if using 1.2.166 of the resolver makes any difference?

rotter commented 3 years ago

I have just downloaded the latest version and tried again, same problem (did a Reimport All and also Delete Resolved Libraries to be sure).

The only difference I noticed from the scenario I reported yesterday is that now it is now downloading Audience Network version 6.5.1 (instead of 6.5.0), but I would guess Facebook released a new version yesterday night.

paulinon commented 3 years ago

Hi @rotter,

I've tried the steps you've given, but I wasn't able to replicate your issue. The version of the FAN SDK remained at version 6.2.0, and I encountered no conflicts after the last Force Resolve. It would be great if you could provide a minimal, reproducible example of your project so that we can narrow down the cause of your issue.

Additionally, could you confirm if performing these steps in a new project produces the same issue?

rotter commented 3 years ago

Hi @paulinon ! Thanks for trying it. I did those steps on a new project which I created specifically to test it, and I havent changed any setting of this newly created project.

Maybe it's related to the OS (Mac), or to my Unity version (2020.3.6f)? Or maybe it's related to my local files/local repo (Im not sure how it works)? In any case I will send you the link to the project zip via private message.

rotter commented 3 years ago

@paulinon

Ok, I dont know how to send a pm, it's probably not possible. Here goes the link. Deleted.

paulinon commented 3 years ago

I've downloaded it. You may now break the link.

paulinon commented 3 years ago

Hi @rotter,

I wasn't able to replicate your issue even with your project. Could you try using the latest version of the Unity Editor (2020.3.13f1 for LTS) and see if it makes a difference?

rotter commented 3 years ago

Hey again @paulinon ! I have just downloaded 2020.3.13f and migrated the project to it, did a Reimport All, then Delete Libs, then Force Resolve, same conflicts and same result (downloaded com.facebook.android.audience-network-sdk-6.5.1 ). Some possibilities:

rotter commented 3 years ago

Yesterday I tried on an employee's computer, which is an older ~2012 Mac on an older OSX version (Catalina), sent him the same ZIP and he had the same result as me (conflicts, then downloaded FAN 6.5.1). Also, he probably runs on default Unity settings, so I doubt it's related to Unity settings. That leaves only the OS from my original possibilities/suspicions (unless we both have some problem on our local files/repo), and unfortunately I dont have any Windows machine to test.

rotter commented 3 years ago

@stewartmiles can you shed any light here please? Anyone? Thanks :)

stewartmiles commented 3 years ago

I haven't worked on this project for quite a while. @chkuang-g is likely the best person to take a look. Looking at the original message it sounds like the package conflict resolution logic is wrong when the same package is pulled in from different paths of the dependency graph.

chkuang-g commented 3 years ago

Hi @stewartmiles!

Sorry for the long wait. I think there is an internal bug similar to this b/191478283.

To unblock you right now, I recommend you to turn ON Custom Gradle Template, a.k.a. mainTemplate.gradle. In that case, Unity will use Gradle to resolve dependency for you instead of having EDM4U doing such for you. If you are using Firebase and is using Unity 2020, also turn on Custom Gradle Property Template (to enable AndroidX and Jetifier) and Minify (to trim down unused symbols so that you do not need to use multi-dex). See the following picture.

Screen Shot 2021-07-21 at 11 35 09 AM

This should theoretically unblock you. Let me see if I can reproduce the issue from my end.

chkuang-g commented 3 years ago
Modified artifacts:
com.android.support:support-annotations:28.0.0 --> androidx.annotation:annotation:1.0.0
com.facebook.android:audience-network-sdk:6.2.0 --> com.facebook.android:audience-network-sdk:+
com.google.ads.mediation:facebook:6.2.0.0 --> com.google.ads.mediation:facebook:+

Alright, I did get this. Let me dig a bit more.

chkuang-g commented 3 years ago

Judge by the log, I think the main conflict is play-services-basement since FAN depends on 11.0.4 while Admob mediation depends on 17.0.0, 17.3.0. Since this is major version difference, I guess the gradle script in EDM4U ended up change both com.facebook.android:audience-network-sdk and com.google.ads.mediation:facebook to +.

com.google.android.gms:play-services-basement conflicting due to package(s):
- com.facebook.android:audience-network-sdk:6.2.0/com.google.android.gms:play-services-basement:11.0.4
- com.google.ads.mediation:facebook:6.2.0.0/com.facebook.android:audience-network-sdk:6.2.0/com.google.android.gms:play-services-basement:11.0.4
- com.google.ads.mediation:facebook:6.2.0.0/com.google.android.gms:play-services-ads:19.5.0/com.google.android.gms:play-services-ads-identifier:17.0.0/com.google.android.gms:play-services-basement:17.0.0
- com.google.ads.mediation:facebook:6.2.0.0/com.google.android.gms:play-services-ads:19.5.0/com.google.android.gms:play-services-ads-lite:[19.5.0]/com.google.android.gms:play-services-basement:17.3.0
- com.google.ads.mediation:facebook:6.2.0.0/com.google.android.gms:play-services-ads:19.5.0/com.google.android.gms:play-services-ads-lite:[19.5.0]/com.google.android.gms:play-services-measurement-sdk-api:17.2.0/com.google.android.gms:play-services-basement:17.0.0
- com.google.ads.mediation:facebook:6.2.0.0/com.google.android.gms:play-services-ads:19.5.0/com.google.android.gms:play-services-ads-lite:[19.5.0]/com.google.android.gms:play-services-measurement-sdk-api:17.2.0/com.google.android.gms:play-services-measurement-base:[17.2.0]/com.google.android.gms:play-services-basement:17.0.0
- com.google.ads.mediation:facebook:6.2.0.0/com.google.android.gms:play-services-ads:19.5.0/com.google.android.gms:play-services-basement:17.3.0
- com.google.ads.mediation:facebook:6.2.0.0/com.google.android.gms:play-services-ads:19.5.0/com.google.android.gms:play-services-gass:[19.5.0]/com.google.android.gms:play-services-ads-identifier:17.0.0/com.google.android.gms:play-services-basement:17.0.0
- com.google.ads.mediation:facebook:6.2.0.0/com.google.android.gms:play-services-ads:19.5.0/com.google.android.gms:play-services-gass:[19.5.0]/com.google.android.gms:play-services-ads-lite:[19.5.0]/com.google.android.gms:play-services-basement:17.3.0
- com.google.ads.mediation:facebook:6.2.0.0/com.google.android.gms:play-services-ads:19.5.0/com.google.android.gms:play-services-gass:[19.5.0]/com.google.android.gms:play-services-ads-lite:[19.5.0]/com.google.android.gms:play-services-measurement-sdk-api:17.2.0/com.google.android.gms:play-services-basement:17.0.0
- com.google.ads.mediation:facebook:6.2.0.0/com.google.android.gms:play-services-ads:19.5.0/com.google.android.gms:play-services-gass:[19.5.0]/com.google.android.gms:play-services-ads-lite:[19.5.0]/com.google.android.gms:play-services-measurement-sdk-api:17.2.0/com.google.android.gms:play-services-measurement-base:[17.2.0]/com.google.android.gms:play-services-basement:17.0.0
- com.google.ads.mediation:facebook:6.2.0.0/com.google.android.gms:play-services-ads:19.5.0/com.google.android.gms:play-services-gass:[19.5.0]/com.google.android.gms:play-services-basement:17.3.0
- com.google.ads.mediation:facebook:6.2.0.0/com.google.android.gms:play-services-ads:19.5.0/com.google.android.gms:play-services-gass:[19.5.0]/com.google.android.gms:play-services-tasks:17.1.0/com.google.android.gms:play-services-basement:17.3.0

Based on what the Admob team found out in b/191478283#comment24, what I recommended in https://github.com/googlesamples/unity-jar-resolver/issues/444#issuecomment-884549348 should work for you.

I think there are a couple of actions items for your reporting:

  1. It is really hard to learn there is a conflict during resolution. First, tracking the true cause of the conflict is only available through verbose logging and the verbose log is really long. Second, EDM4U report Resolution Succeeded even if there is some conflicts. Perhaps it should have three types of result: Resolution Succeeded with no conflict, Resolution succeeded with initial conflict with package A, B and C, and Resolution failed due to conflict with package A, B and C.
  2. EDM4U log conflicts for some packages where there is no conflict at all, which is confusing. Ex.
    com.facebook.android:audience-network-sdk conflicting due to package(s):
    - com.facebook.android:audience-network-sdk:6.2.0 
    - com.google.ads.mediation:facebook:6.2.0.0/com.facebook.android:audience-network-sdk:6.2.0   
  3. Understand why EDM4U gradle script failed while mainTemplate.gradle succeeded and potentially improve the resolution logic while mainTemplate.gradle is not in use.

Let me change the title a bit and change this to a feature request.

Let us know if this helps.

paulinon commented 2 years ago

Hi @rotter,

Could you confirm if turning on the Custom Gradle Template is helpful for your use case?

dots-alberto-uriarte commented 2 years ago

In my case turning on the Custom Gradle Template worked 😄

If download_artifacts.gradle is not able to resolve dependencies properly (or it doesn't have an option to define the strategy), maybe you should consider the option to remove it from the project and enforce the use of Custom Gradle Template.