googlesamples / googlesamples/unity-jar-resolver

Modify the build.gradle file in a post process step when possible

Open
#308 5 comments 2 reactions 0 assignees View on GitHub
type: feature request
Dominant language
C#
Stars
1.5k
Forks
371
Avg merge
14h 21m
Merged PRs (30d)
3

Description

### Please fill in the following fields:
Unity editor version: >= 2018.1
Features in Play Services Resolver in use: Android Resolver
Platform you are targeting: Android

### Please describe the issue here:
This is a feature request / suggestion for improvement / request for comments.

Summary: I would like the Android resolver to be able to delegate the dependencies resolution to Gradle without requiring the presence of a `mainTemplate.gradle` file.
Here's the rationale:
- First of all, we prefer delegating the dependencies resolution to Gradle: we have a set of dependencies that the Android Resolver struggles to resolve, running multiple attempts, taking a long time (several minutes), and giving a result that differs from the one we get from Gradle (some versions get unlocked in the process)
- When the `mainTemplate.gradle` is present the Android Resolver does an amazing job (collecting the dependencies, repositories, handling AndroidX+Jetifier, etc...) 👏
- The `mainTemplate.gradle` file has to be in sync with the one provided by Unity. Large projects can take multiple years (and live ones have to be maintained for a long time), and we often have to update the Unity version in the process. Updating the `mainTemplate.gradle` file is easy to forget, it becomes a chore and it's error-prone to compare the differences in the Unity provided ones between versions and porting our own customizations
- Because of the previous point we're trying to get rid of the `mainTemplate.gradle` file so Unity can automatically provide its own one without us having to care about updating it
- We've updated our customizations to be applied to the generated `build.gradle` as a post-process step using [IPostGenerateGradleAndroidProject](https://docs.unity3d.com/ScriptReference/Android.IPostGenerateGradleAndroidProject.html) (it was added in [Unity 2018.1.0](https://unity3d.com/unity/whats-new/unity-2018.1.0))
- When I tried removing the `mainTemplate.gradle` file I noticed the Android Resolver was falling back to its internal resolution again 😢

Ideally I would like the Android Resolver to offer an "approach" option where the users could choose between:
- "Final build.gradle patching": Available when the project is built using Gradle and Unity >= 2018.1, using an `IPostGenerateGradleAndroidProject` (whether the `mainTemplate.gradle` file is provided or not)
- "mainTemplate.gradle patching": Available when the project is built using Gradle and it has a `mainTemplate.gradle` file
- "Internal resolution": The classic approach, always available

Do you think it's possible? Does it fit the direction of the project? Do you see value in it? Do you think it would be doable with relatively small effort?

Thanks!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.