Skip to content

[Bug] mainTemplate.gradle and ProjectSettings/AndroidResolverDependencies.xml change when switching between building Android build and exporting Android project #537

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
marekzd opened this issue Aug 24, 2022 · 3 comments · Fixed by #610 or #616

Comments

@marekzd
Copy link

marekzd commented Aug 24, 2022

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2020.3.17f1
  • External Dependency Manager version: 1.2.171
  • Source you installed EDM4U: .unitypackage
  • Features in External Dependency Manager in use: Android Resolver
  • Plugins SDK in use: Firebase, Facebook
  • Platform you are using the Unity editor on: Mac

[REQUIRED] Please describe the issue here:

  1. Open Unity project

  2. Switch to Android target

  3. Build for Android

    mainTemplate.gradle will look like this:

    def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\\", "/")
    maven {
        url (unityProjectPath + "/Assets/GeneratedLocalRepo/Firebase/m2repository") // Assets/Firebase/Editor/AnalyticsDependencies.xml:18, Assets/Firebase/Editor/AppDependencies.xml:22, Assets/Firebase/Editor/CrashlyticsDependencies.xml:20, Assets/Firebase/Editor/DynamicLinksDependencies.xml:20
    }

    and generated unityLibrary/build.gradle will look like this:

    def unityProjectPath = $/file:////Users/marekzd/Documents/projects/unity-project/$.replace("\\", "/")
    maven {
        url (unityProjectPath + "/Assets/GeneratedLocalRepo/Firebase/m2repository") // Assets/Firebase/Editor/AnalyticsDependencies.xml:18, Assets/Firebase/Editor/AppDependencies.xml:22, Assets/Firebase/Editor/CrashlyticsDependencies.xml:20, Assets/Firebase/Editor/DynamicLinksDependencies.xml:20
    }

    additionally ProjectSettings/AndroidResolverDependencies.xml will change to:

    <setting name="projectExportEnabled" value="False" />
  4. Export Android project to Android Studio

    mainTemplate.gradle will change to:

    def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\\", "/")
    maven {
        url "file:////Users/marekzd/Documents/projects/unity-project/Assets/GeneratedLocalRepo/Firebase/m2repository" // Assets/Firebase/Editor/AnalyticsDependencies.xml:18, Assets/Firebase/Editor/AppDependencies.xml:22, Assets/Firebase/Editor/CrashlyticsDependencies.xml:20, Assets/Firebase/Editor/DynamicLinksDependencies.xml:20
    }

    and unityLibrary/build.gradle in exported project will look like this:

    def unityProjectPath = $/file:////Users/marekzd/Documents/projects/unity-project/$.replace("\\", "/")
    maven {
        url "file:////Users/marekzd/Documents/projects/unity-project/Assets/GeneratedLocalRepo/Firebase/m2repository" // Assets/Firebase/Editor/AnalyticsDependencies.xml:18, Assets/Firebase/Editor/AppDependencies.xml:22, Assets/Firebase/Editor/CrashlyticsDependencies.xml:20, Assets/Firebase/Editor/DynamicLinksDependencies.xml:20
    }

    additionally ProjectSettings/AndroidResolverDependencies.xml will change to:

    <setting name="projectExportEnabled" value="True" />
  5. When you will build for Android once again mainTemplate.gradle and ProjectSettings/AndroidResolverDependencies.xml will change once again.

Would it be possible to avoid changing these files during building ?
These changes frequently ends up in random commits and obscure them.

Would it be possible to always use unityProjectPath in mainTemplate.gradle generated code ?

Here seems to be a code responsible for these changes in mainTemplate.gradle.

Please answer the following, if applicable:

What's the issue repro rate? (eg 100%, 1/5 etc)
100%

@marekzd marekzd added new to be triaged type: question labels Aug 24, 2022
@google-oss-bot
Copy link

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

@chkuang-g
Copy link
Collaborator

Hi @marekzd

Hmm, after reading the change 7d84e3b again, I THINK we might be able to always use unityProjectPath, no matter it is exported project or not. I cannot recall why I used absolute path by that time. It could be oversight or to handle for certain configuration.

We will need to verify the following scenario just in case the change still works for all scenario

  • In Unity 2018 and 2019
  • Build without exporting
  • Build with exporting under the same Unity project
  • Build with exporting under a different location to the Unity project.

We may need to schedule some time in the future to verify this.

Or feel free to send us a Pull Request about this change and also help the community to verify if the change works in the scenario describe above.

@chkuang-g
Copy link
Collaborator

Also, unityLibrary/build.gradle is not created by EDM4U but by Unity based on mainTemplate.gradle. It might not be a good idea to version control this file if this project may be downloaded to a different workstation because def unityProjectPath = $/file:////Users/marekzd/Documents/projects/unity-project/$.replace("\\", "/") may not be valid on a different workstation.

As for AndroidResolverDependencies.xml, while it is generated by EDM4U, it is probably not a good idea to version control it since this is a cached dependency resolution file specifically for the workstation.

chkuang-g added a commit that referenced this issue Apr 27, 2023
- Version 1.2.176 - Apr 27, 2023
* Android Resolver - Added two Android Resolver settings to determine whether
  EDM4U injects custom local Maven repo path as a relative path or full path.
  Fixes #537
* Android Resolver - Inject Maven Repo to `settingTemplate.gradle` from
  Unity `2022.2+`
  Fixes #594
* Android Resolver - Jetifier option is enabled by default now.
* Android Resolver - `Explode Aar` option applies to all cases, whether the
  project will be exported or not.
  Fixes #584
  Fixes #287
chkuang-g added a commit that referenced this issue Apr 27, 2023
- Version 1.2.176 - Apr 27, 2023
* Android Resolver - Added two Android Resolver settings to determine whether
  EDM4U injects custom local Maven repo path as a relative path or full path.
  Fixes #537
* Android Resolver - Inject Maven Repo to `settingTemplate.gradle` from
  Unity `2022.2+`
  Fixes #594
* Android Resolver - Jetifier option is enabled by default now.
* Android Resolver - `Explode Aar` option applies to all cases, whether the
  project will be exported or not.
  Fixes #584
  Fixes #287
@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.
Projects
None yet
4 participants