Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support for Gradle dependencyResolutionManagement RepositoriesMode.PREFER_SETTINGS #605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
256p wants to merge 6 commits into googlesamples:master from 256p:master

Conversation

@256p
Copy link

@256p 256p commented Mar 29, 2023
edited
Loading

This PR fixes #594 (comment)

Changes influence only builds when main Gradle template patching is enabled.

Changes:

  • Added "Patch settingsTemplate.gradle" checkbox in Android Resolver settings.
  • Implemented repositories injection in settingsTemplate.gradle
  • Added /resolve/gradlesettingstemplate report URL to the analytics. (Not sure if it is needed)

The logic of repositories injection depends on the project state:

  • Project state when mainTemplate.gradle and settingsTemplate.gradle are enabled and mainTemplate patching and settingsTemplate patching in Android Resolver settings are enabled:
    1. Android Resolver will check if settingsTemplate.gradle contains dependencyResolutionManagement block with RepositoriesMode.PREFER_SETTINGS or RepositoriesMode.FAIL_ON_PROJECT_REPOS. If the match is successful it would mean that Gradle is configured to read repositories from settingsTemplate.gradle and will not read repositories specified in mainTemplate.gradle.
    2. If the previous check is successful then Android Resolver will inject repositories in settingsTemplate.gradle before dependencyResolutionManagement line. Injected repositories are in separate dependencyResolutionManagement block and look like this:
    // Android Resolver Repos Start
    dependencyResolutionManagement {
     repositories {
     def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\\", "/")
     maven {
     url "https://maven.google.com"
     }
     maven {
     url "https://maven.google.com/" // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7, Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:12, Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:17, Assets/GoogleMobileAds/Editor/GoogleUmpDependencies.xml:7
     }
     mavenLocal()
     mavenCentral()
     }
    }
    // Android Resolver Repos End
    
    1. If the previous check isn't successful then Android Resolver will inject repositories the same way as it is doing in older versions in mainTemplate.gradle
  • In the project state when mainTemplate.gradle and settingsTemplate.gradle are enabled and mainTemplate patching is enabled but settingsTemplate patching in Android Resolver settings is disabled, Android Resolver will not patch settingsTemplate.gradle this will lead to the build fail and the user will need to manage repositories manually.
  • Project state when mainTemplate.gradle is enabled and mainTemplate patching and settingsTemplate patching in Android Resolver settings are enabled but settingsTemplate.gradle is disabled:
    1. If the Unity version is equal to or above 2022年2月10日 Android Resolver will fail and in the error log will be asked to enable the settings template in "Project Settings".
    2. If the Unity version is below 2022年2月10日 then Android Resolver will check if the default settingsTemplate.gradle in PlaybackEngines/AndroidPlayer/Tools/GradleTemplates contains dependencyResolutionManagement block. Effectively this will match any Unity version equal to or above the 2022.2 version because dependencyResolutionManagement was introduced in the 2022.2 version.
      2.1. If the previous check didn't match then Android Resolver will work as in the previous versions.
      2.2. If the previous check is successful then Android Resolver will enable settingsTemplate.gradle automatically (by copying the default template). Decided to do it in such a way because Unity >=2022.2 and <2022年2月10日 uses a settings template for repositories but don't have an option in "Project Settings" to enable a custom settings template. This option appeared only in 2022年2月10日.

joaoborks reacted with rocket emoji
Copy link
Collaborator

Hi @256p
Thank you so much for contributing this patch for EDM4U!
We are doing very similar things in #610 with some additional touches

  1. Unity 2022年2月1日 - 2022年2月9日 does not support template variable like **DIR_UNITYPROJECT** unfortunately. Therefore we added two settings to force EDM4U to always use absolute path.
  2. Unity 2022年2月1日 - 2022年2月9日 also does not have an option to enable custom Gradle settings template. This change automatically copy the template from the engine folder.

Still we appreciate your effort to put together this change for the community. And kudos to you to also add integration tests! The proper fix for this is a bit involved so we spent some time to make sure the experience is right.

I will close this PR for now.

Regards,
Shawn

256p reacted with thumbs up emoji

@googlesamples googlesamples locked and limited conversation to collaborators May 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Bug] Android Gradle project repositories block don't work for the latest Unity versions

2 participants

AltStyle によって変換されたページ (->オリジナル) /