googlesamples / unity-jar-resolver

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

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

Closed marekzd closed 1 year ago

marekzd commented 2 years ago

[REQUIRED] Please fill in the following fields:

[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%

google-oss-bot commented 2 years ago

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

chkuang-g commented 2 years ago

Hi @marekzd

Hmm, after reading the change https://github.com/googlesamples/unity-jar-resolver/commit/7d84e3bfd77f2d7efca73ff46d4d9d729d8af362 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

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 commented 2 years ago

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.