Skip to content
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

Re-architect how Android plugins are packaged and handled at export time #78958

Merged

Conversation

m4gr3d
Copy link
Contributor

@m4gr3d m4gr3d commented Jul 2, 2023

The previous packaging format for Godot Android plugins consisted of the plugin's gdap config file accompanied by binaries defined in the gdap file.
This format is now deprecated (starting with Godot 4.2), and instead Godot Android plugins are now packaged as EditorExportPlugin plugins.

The EditorExportPlugin class has been updated with the following methods to provide the necessary set of functionality:

  • _supports_platform: returns true if the plugin supports the given platform
  • _get_android_dependencies: retrieve the set of android dependencies (e.g: org.godot.example:my-plugin:0.0.0) provided by the plugin
  • _get_android_dependencies_maven_repos: retrieve the urls of the maven repos for the provided android dependencies
  • _get_android_libraries: retrieve the local paths of the android libraries (AAR files) provided by the plugin
  • _get_android_manifest_activity_element_contents: update the contents of the <activity> element in the generated Android manifest
  • _get_android_manifest_application_element_contents: update the contents of the <application> element in the generated Android manifest
  • _get_android_manifest_element_contents: update the contents of the <manifest> element in the generated Android manifest

The last three methods allow the plugin to automatically provide changes to the app's manifest which are preserved when the editor is updated, resolving a long standing issue.

Fixes #76963
Fixes #78782

Examples:

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Jul 2, 2023

cc @naithar The same concept can be applied on iOS removing the need for the .gdip config file, and aligning all the plugins to the same architecture.

@m4gr3d m4gr3d force-pushed the refactor_android_plugin_packaging_main branch 3 times, most recently from d4379fa to f90a1fa Compare July 2, 2023 23:31
m4gr3d added a commit to m4gr3d/Godot-Android-Samples that referenced this pull request Jul 2, 2023
m4gr3d added a commit to m4gr3d/Godot-Android-Samples that referenced this pull request Jul 2, 2023
@m4gr3d m4gr3d force-pushed the refactor_android_plugin_packaging_main branch 2 times, most recently from 684898d to 65590b9 Compare July 3, 2023 05:39
@m4gr3d m4gr3d marked this pull request as ready for review July 3, 2023 07:35
@m4gr3d m4gr3d requested review from a team as code owners July 3, 2023 07:35
@BastiaanOlij
Copy link
Contributor

Amazing work @m4gr3d, this indeed solves all the issues we were discussing in the XR meeting. For any logic we add to the core we can add the needed features and permissions to the loader for each platform (though I still hope that in that scenario we'll end up with standardised strings in due time), for any OpenXR extension we implement as a GDExtension we'll be able to handle those in that extension by adding an export plugin class to that as well.

@kisg , @dsnopek you guys should review this as well.

@akien-mga
Copy link
Member

akien-mga commented Jul 3, 2023

cc @naithar The same concept can be applied on iOS removing the need for the .gdip config file, and aligning all the plugins to the same architecture.

For the record, naithar hasn't been actively contributing to Godot lately. @bruvzg is the sole maintainer for iOS, he might be able to have a look at doing the matching changes for iOS, though any help from interested contributors would be welcome.

We should aim to have both platforms refactored around the same time, to avoid a situation where 4.2 would release with a different structure for Android and iOS.

@m4gr3d m4gr3d force-pushed the refactor_android_plugin_packaging_main branch from 0f76d25 to 1cf0f58 Compare July 3, 2023 17:04
@m4gr3d m4gr3d requested review from a team and removed request for a team July 3, 2023 17:05
@m4gr3d
Copy link
Contributor Author

m4gr3d commented Jul 3, 2023

Ran into a bug with restoring the saved values of the editor export plugin options from the preset:

Given an export plugin can be added at any time, we may need to separate the platform options from the export plugins' options and store them in the preset regardless of whether the export plugin is available or not.

@m4gr3d m4gr3d force-pushed the refactor_android_plugin_packaging_main branch from f5e8002 to 1224551 Compare July 4, 2023 23:37
@m4gr3d m4gr3d force-pushed the refactor_android_plugin_packaging_main branch from 1224551 to d7f9622 Compare July 17, 2023 19:20
Copy link
Contributor

@BastiaanOlij BastiaanOlij left a comment

Choose a reason for hiding this comment

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

As mentioned before, I really like this new approach. Code wise it looks really good

Copy link
Contributor

@YuriSizov YuriSizov left a comment

Choose a reason for hiding this comment

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

A couple of nitpicks, but also a couple of bigger notes worth addressing.

doc/classes/EditorExportPlugin.xml Outdated Show resolved Hide resolved
doc/classes/EditorExportPlugin.xml Outdated Show resolved Hide resolved
doc/classes/EditorExportPlugin.xml Outdated Show resolved Hide resolved
editor/export/editor_export_plugin.cpp Outdated Show resolved Hide resolved
editor/export/editor_export_plugin.h Outdated Show resolved Hide resolved
editor/export/editor_export_preset.cpp Outdated Show resolved Hide resolved
@m4gr3d m4gr3d force-pushed the refactor_android_plugin_packaging_main branch from d7f9622 to 4bdb1a1 Compare July 18, 2023 15:37
@m4gr3d m4gr3d requested a review from a team as a code owner July 18, 2023 15:37
The previous packaging format for Godot Android plugins consisted of the plugin's `gdap` config file accompanied by binaries defined in the `gdap` file.
This format is now deprecated (starting with Godot 4.2), and instead Godot Android plugins are now packaged as `EditorExportPlugin` plugins.

The `EditorExportPlugin` class has been updated with the following methods to provide the necessary set of functionality:
- `_supports_platform`: returns true if the plugin supports the given platform
- `_get_android_dependencies`: retrieve the set of android dependencies (e.g: `org.godot.example:my-plugin:0.0.0`) provided by the plugin
- `_get_android_dependencies_maven_repos`: retrieve the urls of the maven repos for the provided android dependencies
- `_get_android_libraries`: retrieve the local paths of the android libraries (AAR files) provided by the plugin
- `_get_android_manifest_activity_element_contents`: update the contents of the `<activity>` element in the generated Android manifest
- `_get_android_manifest_application_element_contents`: update the contents of the `<application>` element in the generated Android manifest
- `_get_android_manifest_element_contents`: update the contents of the `<manifest>` element in the generated Android manifest
Following on the previous commit, the XR features logic have now be moved to the Godot OpenXR loader plugin.

See GodotVR/godot_openxr_vendors#38
@YuriSizov YuriSizov force-pushed the refactor_android_plugin_packaging_main branch from 4bdb1a1 to b52e1be Compare July 18, 2023 17:16
@YuriSizov YuriSizov merged commit 8f175a8 into godotengine:master Jul 18, 2023
13 checks passed
@YuriSizov
Copy link
Contributor

Thanks!

@m4gr3d m4gr3d deleted the refactor_android_plugin_packaging_main branch July 18, 2023 19:01
@duarteroso
Copy link

If I understand correctly, only the way Godot interacts with the plugins has changed. The way the plugin is written remains the same. Am I correct?

I've checked the example repo, the package is placed inside the addons folder instead of plugins/android. Does this matter or location is irrelevant?

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Jul 26, 2023

If I understand correctly, only the way Godot interacts with the plugins has changed. The way the plugin is written remains the same. Am I correct?

I've checked the example repo, the package is placed inside the addons folder instead of plugins/android. Does this matter or location is irrelevant?

The plugin logic (java code) remains the same, but the configuration for the plugin, including the folder layout, are changed to the new format which better aligns with other types of Godot plugins.

I've checked the example repo, the package is placed inside the addons folder instead of plugins/android. Does this matter or location is irrelevant?

Yes the location matters. See the tutorial about making Godot plugins for reference.

The documentation for the Android plugins will be updated to reflect all of these changes prior to Godot 4.2 being stable. The current version of the documentation is now obsolete.

@tokengamedev
Copy link

This is big change with respect to how plugins are handled. Can the documentation be updated earlier than beta release so that I can test it properly and if any issues than it can be fixed within 4.2 release

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Jul 29, 2023

This is big change with respect to how plugins are handled. Can the documentation be updated earlier than beta release so that I can test it properly and if any issues than it can be fixed within 4.2 release

It'll be done prior to the beta release, but there are a few more incoming changes / refactor so the documentation will be updated once those are landed and the full end to end plugin flow has been validated.

I'll be posting examples as the refactor progress so you can use those as reference until the documentation is updated.
The Godot OpenXR loader plugin for example has already been updated.

@WNJH
Copy link

WNJH commented Aug 12, 2023

This is machine translation.
I want to delete “intent-filter“ from AndroidManifest.xml. However, after exporting as shown in the diagram, only elements are added.
How can I delete the red circle in the picture?
屏幕截图 2023-08-12 103339
屏幕截图 2023-08-12 103455

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Aug 12, 2023

This is machine translation. I want to delete “intent-filter“ from AndroidManifest.xml. However, after exporting as shown in the diagram, only elements are added. How can I delete the red circle in the picture? 屏幕截图 2023-08-12 103339 屏幕截图 2023-08-12 103455

@WNJH it's not possible to do so on purpose to prevent export plugins from interfering with each other.
What are you trying to achieve by removing the default intent-filter?

@WNJH
Copy link

WNJH commented Aug 12, 2023

这是机器翻译。我想从 AndroidManifest 中删除“意图过滤器”.xml。但是,如图所示导出后,仅添加元素。如何删除图片中的红色圆圈?屏幕截图 2023-08-12 103339 屏幕截图 2023-08-12 103455

不可能故意这样做以防止导出插件相互干扰。你想通过删除默认值来实现什么?intent-filter

Similar to this #78782 (comment)
I want to start my custom activity before going to GodotApp and then jump to GodotApp with the button.
So I create a new activity and cut GodotApp's intent-filter from build\AndroidManifest.xml into the custom activity.
When I use "one-click deploy", two apps will be installed on my phone, One is a GodotApp and the other is a custom activity.
So I need to remove "intent-filter" from build\src\debug\AndroidManifest.xml.

build\AndroidManifest.xml:
屏幕截图 2023-08-12 225133

build\src\debug\AndroidManifest.xml:
屏幕截图 2023-08-12 225234

My temporary solution is to make debug\AndroidManifest.xml read-only.

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Aug 12, 2023

@WNJH Only the android.intent.category.LAUNCHER category needs to be removed. I'll add an export settings for doing so.

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Aug 12, 2023

@WNJH I've added #80569 which adds an export setting to control whether the app shows in the app library.

@WNJH
Copy link

WNJH commented Aug 13, 2023

@m4gr3d Thank you!

I have one more small question." one-click deploy" Does it have to go directly to GodotApp? After I annotated "intent-filter", "one-click deploy" did not display the custom activity. But when I quit, and tap into the APP on my phone, the custom activity is displayed.

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Aug 13, 2023

@m4gr3d Thank you!

I have one more small question." one-click deploy" Does it have to go directly to GodotApp? After I annotated "intent-filter", "one-click deploy" did not display the custom activity. But when I quit, and tap into the APP on my phone, the custom activity is displayed.

@WNJH Yes it launches the GodotApp directly.
@BastiaanOlij is working on a proposal to improve the launch flow. As part of that proposal, we can add the option to specify which activity to launch, but for the moment it's hardcoded to the GodotApp since that's the most prevalent launch flow.

@duarteroso
Copy link

Is there an early version of the updated documentation that I could read? Having a crash in gd_mono.cpp:431 and I believe it to be related to the GodotPlugins with a failed initialization (a blank project works fine).
Instead of opening an issue, I'd rather try seriously 🙂

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Sep 6, 2023

Is there an early version of the updated documentation that I could read? Having a crash in gd_mono.cpp:431 and I believe it to be related to the GodotPlugins with a failed initialization (a blank project works fine). Instead of opening an issue, I'd rather try seriously 🙂

@duarteroso Early draft of the documentation update available in godotengine/godot-docs#7884

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.

AndroidManifest.xml can't change the default <activity> Unable to modify AndroidManifest.xml.
7 participants