Hi everybody! In my latest work I’ve been dealing with mobile projects that use a version of Gradle that is not the one bundled with the version of Unity we use (I know, this is not officially supported, but we use features that only newer versions have).
So I made this simple, free and open source package for automatically generating the Gradle Wrapper (gradlew) when exporting Android projects:
It is installable using UPM and the only setup needed is a Project Setting with the wanted version of Gradle. The plugin has an OnPostGenerateGradleAndroidProject method that generates the wrapper using the JDK and Gradle already configured in Unity, so there is no need to install or configure anything else.
Cool stuff about having gradlew in exported projects:
- Android Studio generates a Gradle Wrapper if there is none in the project, usually with one of the newest versions available. Having the wrapper already set up means Android Studio will use the exact version of Gradle that you need, so you don’t need to worry about it picking up a version of Gradle that is incompatible with your projects’ build scripts.
- If you need a version that is not the one bundled with Unity and you always export projects, that is, don’t use the builtin Android build from Unity, you don’t need to download Gradle independently and set it up in External Tools. Just run Android Studio or gradlew directly and voilà!
- Using gradlew might mean less environment setup, which is good for CI or when onboarding new developers into your team.
- The file ProjectSettings/GradleVersion.txt, generated by the plugin’s settings provider, serves as self documentation of which version of Gradle the project needs. Might be useful even if it’s the same as the one bundled with the Unity Android module.
And that’s it! If anybody tries it out, please let me know what you think. Also, feel free to open issues and discussions in the repo or here in this thread. I’d really appreciate any feedback. If it works or not, if it’s easy to install, easy to use, if current documentation is enough…
Thanks!