Skip to content

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

@256p

Description

@256p

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2022.2.2f1
  • External Dependency Manager version: 1.2.175
  • Source you installed EDM4U: .unitypackage
  • Features in External Dependency Manager in use: Android Resolver
  • Plugins SDK in use: None
  • Platform you are using the Unity editor on: Mac

[REQUIRED] Please describe the issue here:

(Please list the full steps to reproduce the issue. Include device logs, Unity logs, and stack traces if available.)

Steps to reproduce:

  1. Add Dependencies.xml which has custom <repository> specified.
  2. Enable custom main gradle template and custom grade properties template.
  3. Run Android resolver through Assets > External Dependency Manager > Android Resolver > Resolve or Force Resolve.

Expected:

Successful build

Observed:

A lot of warnings from Gradle like that:

Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'unityLibrary/build.gradle'

And this error:

Execution failed for task ':launcher:checkReleaseDuplicateClasses'.
> Could not resolve all dependencies for configuration ':launcher:releaseRuntimeClasspath'.
  The project declares repositories, effectively ignoring the repositories you have declared in the settings.
  You can figure out how project repositories are declared by configuring your build to fail on project repositories.
  See https://docs.gradle.org/7.2/userguide/declaring_repositories.html#sub:fail_build_on_project_repositories for details.
   > Could not find com.ironsource.sdk:mediationsdk:7.2.7.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/ironsource/sdk/mediationsdk/7.2.7/mediationsdk-7.2.7.pom
       - https://repo.maven.apache.org/maven2/com/ironsource/sdk/mediationsdk/7.2.7/mediationsdk-7.2.7.pom
       - file:/Users/stanislavspetkevics/Desktop/unity-jar-resolver-custom-template/Library/Bee/Android/Prj/Mono2x/Gradle/unityLibrary/libs/mediationsdk-7.2.7.jar
       - file:/Users/stanislavspetkevics/Desktop/unity-jar-resolver-custom-template/Library/Bee/Android/Prj/Mono2x/Gradle/unityLibrary/libs/mediationsdk.jar
     Required by:
         project :launcher > project :unityLibrary

You can use this project for testing: https://github.com/256p/unity-jar-resolver-custom-template.git

The reason behind this is that some time ago Unity switched to the new Android Gradle Plugin version (7.1.0). In this version repository setting was moved from the top-level build.gradle file to the setting.gradle (release notes: https://developer.android.com/studio/past-releases/past-agp-releases/agp-7-1-0-release-notes#settings-gradle). But EDM4U still adds project.repositories block in the main gradle template which will not work if settings.gradle has dependencyResolutionManagement block.

As I see there are several possible solutions:

  1. Use IPostGenerateGradleAndroidProject.OnPostGenerateGradleAndroidProject and modify settings.gradle after every build.
  2. Generate settingsTemplate.gradle automatically and add repositories there instead of the main gradle template.
  3. Ask the user to create settingsTemplate.gradle and then generate a repositories list there. But Unity doesn't provide a checkbox for the settings template (which is quite odd), which means that the user will need to copy the correct template from PlaybackEngines/AndroidPlayer/Tools/GradleTemplates/.
  4. Or maybe some other solution.

Please answer the following, if applicable:

What's the issue repro rate? 100%

What happened? How can we make the problem occur?
This could be a description, log/console output, etc.

If you have a downloadable sample project that reproduces the bug you're reporting, you will
likely receive a faster response on your issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions