Skip to content

[Android] Improve gradle build flow by automatically setting up the build directory - #119771

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
m4gr3d:auto_install_android_build_template
Aug 19, 2026
Merged

[Android] Improve gradle build flow by automatically setting up the build directory#119771
Repiteo merged 1 commit into
godotengine:masterfrom
m4gr3d:auto_install_android_build_template

Conversation

@m4gr3d

@m4gr3d m4gr3d commented May 26, 2026

Copy link
Copy Markdown
Contributor

This PR updates the setup of the gradle build environment as follow:

  • If it doesn't already exist, the gradle build directory will be automatically created and set up the first time a project is exported.
  • A new editor setting, export/android/build/automatically_delete_build_directory, is added to control whether an existing but invalid build directory (e.g. mismatched versions due to editor upgrade) should be automatically deleted and reinstalled on build.
Screenshot 2026-05-28 at 9 45 45 PM
  • If the export/android/build/automatically_delete_build_directory editor setting is disabled, then the build fails with an error prompting the user to manually delete the existing invalid build directory.
Screenshot 2026-05-28 at 9 34 55 PM
  • The error is also shown in the project export dialog when an existing build directory is invalid
Screenshot 2026-05-28 at 9 33 15 PM
  • The Install Android Build Template menu option is hidden by default but can be restored via the export/android/build/show_install_android_source_button editor setting.

@syntaxerror247 syntaxerror247 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few concerns here:

  1. Users can extend the build directory with custom code and files, such as notification icons, modifying gradle dependencies, and other changes. If we auto delete the build directory when exporting from a newer version, users could accidentally lose those modifications. So instead, I think we should only install the build template when it is not already present. If there is a version mismatch, we should show a dialog with two actions: Open the existing build directory, so users can review or copy their modifications if needed. And delete and reinstall the gradle template.

  2. We should also keep the Install Android Build Template menu option. When the Android export template is not present or downloaded, it currently provides an option to Install from a file.
    Removing this dialog would remove the ability to manually install a build template.

@m4gr3d

m4gr3d commented May 26, 2026

Copy link
Copy Markdown
Contributor Author

We should also keep the Install Android Build Template menu option. When the Android export template is not present or downloaded, it currently provides an option to Install from a file.
Removing this dialog would remove the ability to manually install a build template.

Manually setting up a build template is still possible either through the gradle_build/android_source_template export option, or through the Manage export template dialog and window.

The pattern being observed is to improve the build flow by reducing the number of clicks required for setup. There are in general two scenarios a user may be going through, and both are addressed by the new flow:

  • Scenario 1: user is using the default templates.

    • User either first launch the Manage export template window, and download the templates from there. Then user creates an Android export preset, select gradle_build/use_gradle_build, and is able to start exporting right away without any further clicks.
    • Or user first creates an Android export preset and select gradle_build/use_gradle_build. The export preset warns the user that the required template is missing, and provide a button to invoke the template manager so the user can download the required template.
  • Scenario 2: user is using custom templates. User then create an Android export preset, select gradle_build/use_gradle_build and set up the custom template using gradle_build/android_source_template. No additional clicks required.

@m4gr3d

m4gr3d commented May 26, 2026

Copy link
Copy Markdown
Contributor Author
  1. Users can extend the build directory with custom code and files, such as notification icons, modifying gradle dependencies, and other changes. If we auto delete the build directory when exporting from a newer version, users could accidentally lose those modifications. So instead, I think we should only install the build template when it is not already present. If there is a version mismatch, we should show a dialog with two actions: Open the existing build directory, so users can review or copy their modifications if needed. And delete and reinstall the gradle template.

Yeah I think we can go with this approach. We should also add a checkbox to allow users to specify Always delete and don't ask me again, as well as an advanced editor settings to control and reset that behavior if needed.

@m4gr3d
m4gr3d force-pushed the auto_install_android_build_template branch 2 times, most recently from 9be8b66 to 07ed702 Compare May 29, 2026 03:58
@m4gr3d

m4gr3d commented May 29, 2026

Copy link
Copy Markdown
Contributor Author
  1. Users can extend the build directory with custom code and files, such as notification icons, modifying gradle dependencies, and other changes. If we auto delete the build directory when exporting from a newer version, users could accidentally lose those modifications. So instead, I think we should only install the build template when it is not already present. If there is a version mismatch, we should show a dialog with two actions: Open the existing build directory, so users can review or copy their modifications if needed. And delete and reinstall the gradle template.

Yeah I think we can go with this approach. We should also add a checkbox to allow users to specify Always delete and don't ask me again, as well as an advanced editor settings to control and reset that behavior if needed.

@syntaxerror247 I've updated the implementation. See the updated description.

@m4gr3d
m4gr3d requested a review from syntaxerror247 May 29, 2026 04:50
@m4gr3d
m4gr3d force-pushed the auto_install_android_build_template branch from 07ed702 to 5da6905 Compare June 20, 2026 02:48
@Repiteo Repiteo modified the milestones: 4.8, 4.x Jun 24, 2026
@m4gr3d m4gr3d modified the milestones: 4.x, 4.8 Jul 1, 2026
@syntaxerror247

syntaxerror247 commented Jul 2, 2026

Copy link
Copy Markdown
Member

We should also keep the Install Android Build Template menu option. When the Android export template is not present or downloaded, it currently provides an option to Install from a file.
Removing this dialog would remove the ability to manually install a build template.

Manually setting up a build template is still possible either through the gradle_build/android_source_template export option, or through the Manage export template dialog and window.

The pattern being observed is to improve the build flow by reducing the number of clicks required for setup. There are in general two scenarios a user may be going through, and both are addressed by the new flow:

  • Scenario 1: user is using the default templates.

    • User either first launch the Manage export template window, and download the templates from there. Then user creates an Android export preset, select gradle_build/use_gradle_build, and is able to start exporting right away without any further clicks.
    • Or user first creates an Android export preset and select gradle_build/use_gradle_build. The export preset warns the user that the required template is missing, and provide a button to invoke the template manager so the user can download the required template.
  • Scenario 2: user is using custom templates. User then create an Android export preset, select gradle_build/use_gradle_build and set up the custom template using gradle_build/android_source_template. No additional clicks required.

@m4gr3d problem is that I'd have to first export to generate the android build directory, and after that I'd be able to customize that. I'd like to first get the build directory, customize and then export. After this PR there's no option to get build directory before export.
For eg, godot-play-game-services plugin requires users to first customize the build directory to add game's project id before export. we'd have to add an awkward instruction to first export to generate the build directory and then do the rest :-)

Removing Install Android Build Template menu option also breaks every tutorial video, so we should take conservative approach for that as well.

@Repiteo Repiteo modified the milestones: 4.8, 4.x Jul 2, 2026
@dsnopek

dsnopek commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

I also personally like keeping the Install Android Build Template menu item. It becomes optional (which I expect most people will eventually take advantage of) but leaves the old workflow in place

@m4gr3d
m4gr3d force-pushed the auto_install_android_build_template branch 3 times, most recently from 8a40e54 to 664ff25 Compare July 28, 2026 10:32
@m4gr3d

m4gr3d commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

@dsnopek @syntaxerror247 I've updated the implementation to keep the Install Android Build Template... button, but have it hidden by default with the ability to show it via the export/android/build/show_install_android_source_button editor setting.

@m4gr3d m4gr3d modified the milestones: 4.x, 4.8 Jul 28, 2026
Comment thread editor/editor_node.cpp Outdated
Comment thread editor/editor_node.cpp
Comment thread editor/editor_node.cpp Outdated
Comment thread platform/android/export/export_plugin.cpp Outdated
Comment thread editor/editor_node.cpp
@syntaxerror247

Copy link
Copy Markdown
Member

@dsnopek @syntaxerror247 I've updated the implementation to keep the Install Android Build Template... button, but have it hidden by default with the ability to show it via the export/android/build/show_install_android_source_button editor setting.

I don't think hiding a menu option behind an editor setting is a good idea. We should either have this setting or not have it at all.

We can update the documentations to only mention the new export flow but I'd still prefer keeping this option for now and remove it in 5.0 (or maybe later 4.x releases). I just think that removing this option would be a big change.

I'd ask Usability team to share their thoughts on removing Install Android Build Template menu option. @godotengine/usability

@dsnopek

dsnopek commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

@dsnopek @syntaxerror247 I've updated the implementation to keep the Install Android Build Template... button, but have it hidden by default with the ability to show it via the export/android/build/show_install_android_source_button editor setting.

I don't think hiding a menu option behind an editor setting is a good idea. We should either have this setting or not have it at all.

I agree.

My inclination would be to just leave the option in the menu for now. Most folks will hit on the automatic behavior by virtue of just going to export and everything working. And the folks who know they need the tool can continue to find it in the menu. There will be a short period where some people may continue using the tool, even though they really need it anymore, but this will likely fade with time

@m4gr3d

m4gr3d commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@dsnopek @syntaxerror247 I've updated the implementation to keep the Install Android Build Template... button, but have it hidden by default with the ability to show it via the export/android/build/show_install_android_source_button editor setting.

I don't think hiding a menu option behind an editor setting is a good idea. We should either have this setting or not have it at all.

I agree.

My inclination would be to just leave the option in the menu for now. Most folks will hit on the automatic behavior by virtue of just going to export and everything working. And the folks who know they need the tool can continue to find it in the menu. There will be a short period where some people may continue using the tool, even though they really need it anymore, but this will likely fade with time

The issue is that I am introducing a new button in #121849 to automatically download and setup the Android SDK, so following that PR, a user will have 3 UX to set up and configure their Android export:

  1. Export Template Manager used to download the Android export templates from the Available templates tree window
  2. Export Template Manager hosting the Setup Android SDK button that users can click to download and install the Android SDK
  3. Install Android Build Template... button in the Project menu that's used to install the Android build template.

The last button is now redundant with the functionality being added in this PR, except for expert users. So to avoid confusing regular users (which would be the vast majority), the current approach is to hide the last button by default, and provide a settings for expert users to bring it back if desired, similar to the approach used for the renderer selection drop-down.

Another approach would be to merge the functionality of the Setup Android SDK and Install Android Build Template... button together:

  • Clicking on the button would install and set up the Android SDK if it's not already set up
  • If the Android SDK is set up, then the logic would automatically install the Android build template, following the same flow as currently provided by the Install Android Build Template... button.

@m4gr3d
m4gr3d force-pushed the auto_install_android_build_template branch from 664ff25 to a6ba0f2 Compare August 4, 2026 23:29
@m4gr3d

m4gr3d commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Feedback from discussions with @dsnopek and @syntaxerror247:

  • Rename Install Android Build Template... to Setup Android Build
  • Update the button logic to check for the Android SDK, and prompt the user for install if it's not already installed.
  • Move the Setup Android SDK button in Automate Android & Java SDK setup #121849 from the Export Template Manager to the Export Window. It should be surfaced as a link similar to what we do for the Manage External template link

@m4gr3d
m4gr3d force-pushed the auto_install_android_build_template branch from a6ba0f2 to 02596fd Compare August 6, 2026 16:54
…rectory

If not set up, the build directory will be automatically created and set up the first time the project is exported.

A new editor setting (`export/android/build/automatically_delete_build_directory`) is added to control whether an existing but invalid build directory (e.g. mismatched versions due to upgrade) should be automatically deleted and reinstalled on build.
If disabled, then the build fails with an error prompting the user to manually delete if needed.
@m4gr3d
m4gr3d force-pushed the auto_install_android_build_template branch from 02596fd to 0fa44d8 Compare August 6, 2026 17:55
@m4gr3d

m4gr3d commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@dsnopek @syntaxerror247 I've addressed your feedback, the PR should be good to go!

@m4gr3d
m4gr3d requested a review from syntaxerror247 August 6, 2026 17:58

@syntaxerror247 syntaxerror247 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Comment thread platform/android/export/export_plugin.cpp

@dsnopek dsnopek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I skimmed the code, and it looks good to me

I also test all use cases I normally use when developing for Android:

  • Automatically installing when default export templates are present
  • Automatically installing when export preset has custom export templates
  • Using the original "Install Android Build Template..." dialog (both when export templates are present and not)

They all seemed to work great!

@Repiteo
Repiteo merged commit 3792b02 into godotengine:master Aug 19, 2026
26 of 27 checks passed
@Repiteo

Repiteo commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Thanks!

@m4gr3d
m4gr3d deleted the auto_install_android_build_template branch August 20, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants