summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFredia Huya-Kouadio <fhuya@meta.com>2023-07-05 12:06:39 -0700
committerFredia Huya-Kouadio <fhuya@meta.com>2023-07-05 12:10:05 -0700
commit93543c9cc7b9b7b3526fd3eb2a0f6819cc6fee32 (patch)
treeeffa5bd70925039ed7f6d4cbc56d5485e6e9a740
parent01f6b286390e552cd326df00ad16c65e5f5c703b (diff)
downloadgodot-android-samples-93543c9cc7b9b7b3526fd3eb2a0f6819cc6fee32.tar.gz
godot-android-samples-93543c9cc7b9b7b3526fd3eb2a0f6819cc6fee32.tar.bz2
godot-android-samples-93543c9cc7b9b7b3526fd3eb2a0f6819cc6fee32.zip
Update the directory structure for the Android plugin addon
The addon directory now contains two subfolders: - "addons/<plugin_dir>/export": - should contain the editor plugin script and the editor export plugin script. as well as any binaries needed for export - `plugin.cfg` must point to the editor plugin script in this directory - must contain a `.gdignore` file to exclude this directory from the export process - "addons/<plugin_dir>/interface": - optional directory - can contain helper gdscript files used by the project to interface with the functionality exposed by the plugin
-rw-r--r--README.md6
-rw-r--r--hello_signals/README.md4
-rw-r--r--hello_signals/build.gradle4
-rw-r--r--hello_signals/demo/Main.gd14
-rw-r--r--hello_signals/demo/addons/hello_signals_plugin/HelloSignals.debug.aarbin6825 -> 0 bytes
-rw-r--r--hello_signals/demo/addons/hello_signals_plugin/HelloSignals.release.aarbin6647 -> 0 bytes
-rw-r--r--hello_signals/demo/addons/hello_signals_plugin/export/.gdignore (renamed from hello_signals/demo/addons/hello_signals_plugin/.gdignore)0
-rw-r--r--hello_signals/demo/addons/hello_signals_plugin/export/HelloSignals.debug.aarbin0 -> 6826 bytes
-rw-r--r--hello_signals/demo/addons/hello_signals_plugin/export/HelloSignals.release.aarbin0 -> 6644 bytes
-rw-r--r--hello_signals/demo/addons/hello_signals_plugin/export/hello_signals_editor_export_plugin.gd (renamed from hello_signals/demo/addons/hello_signals_plugin/hello_signals_export_plugin.gd)4
-rw-r--r--hello_signals/demo/addons/hello_signals_plugin/export/hello_signals_editor_plugin.gd (renamed from hello_signals/demo/addons/hello_signals_plugin/hello_signals_plugin.gd)2
-rw-r--r--hello_signals/demo/addons/hello_signals_plugin/interface/hello_signals_plugin.gd27
-rw-r--r--hello_signals/demo/addons/hello_signals_plugin/plugin.cfg2
-rw-r--r--hello_signals/demo/export_presets.cfg8
-rw-r--r--hello_signals/demo/project.godot1
-rw-r--r--hello_world/README.md3
-rw-r--r--hello_world/build.gradle4
-rw-r--r--hello_world/demo/Main.gd9
-rw-r--r--hello_world/demo/addons/hello_world_plugin/.gdignore1
-rw-r--r--hello_world/demo/addons/hello_world_plugin/export/.gdignore0
-rw-r--r--hello_world/demo/addons/hello_world_plugin/export/HelloWorld.debug.aar (renamed from hello_world/demo/addons/hello_world_plugin/HelloWorld.debug.aar)bin6117 -> 6114 bytes
-rw-r--r--hello_world/demo/addons/hello_world_plugin/export/HelloWorld.release.aar (renamed from hello_world/demo/addons/hello_world_plugin/HelloWorld.release.aar)bin5988 -> 5978 bytes
-rw-r--r--hello_world/demo/addons/hello_world_plugin/export/hello_world_editor_export_plugin.gd (renamed from hello_world/demo/addons/hello_world_plugin/hello_world_export_plugin.gd)4
-rw-r--r--hello_world/demo/addons/hello_world_plugin/export/hello_world_editor_plugin.gd (renamed from hello_world/demo/addons/hello_world_plugin/hello_world_plugin.gd)2
-rw-r--r--hello_world/demo/addons/hello_world_plugin/interface/hello_world_plugin.gd18
-rw-r--r--hello_world/demo/addons/hello_world_plugin/plugin.cfg2
-rw-r--r--hello_world/demo/export_presets.cfg6
-rw-r--r--hello_world/demo/project.godot1
28 files changed, 88 insertions, 34 deletions
diff --git a/README.md b/README.md
index 547f6c2..9d8790e 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,8 @@
# Godot-Android-Plugins
-Collection of Godot Android plugin samples.
**Requires Godot 4.2 or above**
+
+Collection of samples showcasing how Godot Android plugins are built and packaged.
+
+ - [Hello World plugin](hello_world/README.md)
+ - [Hello Signals plugin](hello_signals/README.md)
diff --git a/hello_signals/README.md b/hello_signals/README.md
new file mode 100644
index 0000000..7845f21
--- /dev/null
+++ b/hello_signals/README.md
@@ -0,0 +1,4 @@
+## Hello Signals plugin
+
+Showcases how to build a Godot Android plugin which is invoked from gdscript and emit signals
+from the java logic.
diff --git a/hello_signals/build.gradle b/hello_signals/build.gradle
index cf82b7b..6549636 100644
--- a/hello_signals/build.gradle
+++ b/hello_signals/build.gradle
@@ -30,13 +30,13 @@ dependencies {
task copyDebugAARToAddons(type: Copy) {
from 'build/outputs/aar'
include 'HelloSignals.debug.aar'
- into 'demo/addons/hello_signals_plugin'
+ into 'demo/addons/hello_signals_plugin/export'
}
task copyReleaseAARToAddons(type: Copy) {
from 'build/outputs/aar'
include 'HelloSignals.release.aar'
- into 'demo/addons/hello_signals_plugin'
+ into 'demo/addons/hello_signals_plugin/export'
}
assemble.finalizedBy(copyDebugAARToAddons)
diff --git a/hello_signals/demo/Main.gd b/hello_signals/demo/Main.gd
index 1b3e972..2dca0db 100644
--- a/hello_signals/demo/Main.gd
+++ b/hello_signals/demo/Main.gd
@@ -2,16 +2,13 @@ extends Node2D
var timerCount = 0
var timerRunning = false
-var helloSignals
+var helloSignalsPlugin : HelloSignalsPlugin
func _ready():
- if Engine.has_singleton("HelloSignals"):
- helloSignals = Engine.get_singleton("HelloSignals")
- helloSignals.connect("TikTok", Callable(self, "_on_tiktok"))
+ helloSignalsPlugin = preload("res://addons/hello_signals_plugin/interface/hello_signals_plugin.gd").new()
+ helloSignalsPlugin.registerForTikTok(Callable(self, "_on_tiktok"))
- $Button.connect("pressed", Callable(self, "_on_Button_pressed"))
- else:
- print("Couldn't find HelloSignals singleton")
+ $Button.connect("pressed", Callable(self, "_on_Button_pressed"))
func _on_tiktok():
@@ -19,9 +16,10 @@ func _on_tiktok():
timerCount = timerCount + 1
$Label.text = str(timerCount)
+
func _on_Button_pressed():
print("on button pressed from GDScript")
- helloSignals.onButtonPressed()
+ helloSignalsPlugin.toggleTikTok()
timerRunning = !timerRunning
if (timerRunning):
$Button.text = "Stop Timer"
diff --git a/hello_signals/demo/addons/hello_signals_plugin/HelloSignals.debug.aar b/hello_signals/demo/addons/hello_signals_plugin/HelloSignals.debug.aar
deleted file mode 100644
index 3e445c6..0000000
--- a/hello_signals/demo/addons/hello_signals_plugin/HelloSignals.debug.aar
+++ /dev/null
Binary files differ
diff --git a/hello_signals/demo/addons/hello_signals_plugin/HelloSignals.release.aar b/hello_signals/demo/addons/hello_signals_plugin/HelloSignals.release.aar
deleted file mode 100644
index 6440048..0000000
--- a/hello_signals/demo/addons/hello_signals_plugin/HelloSignals.release.aar
+++ /dev/null
Binary files differ
diff --git a/hello_signals/demo/addons/hello_signals_plugin/.gdignore b/hello_signals/demo/addons/hello_signals_plugin/export/.gdignore
index 8b13789..8b13789 100644
--- a/hello_signals/demo/addons/hello_signals_plugin/.gdignore
+++ b/hello_signals/demo/addons/hello_signals_plugin/export/.gdignore
diff --git a/hello_signals/demo/addons/hello_signals_plugin/export/HelloSignals.debug.aar b/hello_signals/demo/addons/hello_signals_plugin/export/HelloSignals.debug.aar
new file mode 100644
index 0000000..d241ab1
--- /dev/null
+++ b/hello_signals/demo/addons/hello_signals_plugin/export/HelloSignals.debug.aar
Binary files differ
diff --git a/hello_signals/demo/addons/hello_signals_plugin/export/HelloSignals.release.aar b/hello_signals/demo/addons/hello_signals_plugin/export/HelloSignals.release.aar
new file mode 100644
index 0000000..6dae345
--- /dev/null
+++ b/hello_signals/demo/addons/hello_signals_plugin/export/HelloSignals.release.aar
Binary files differ
diff --git a/hello_signals/demo/addons/hello_signals_plugin/hello_signals_export_plugin.gd b/hello_signals/demo/addons/hello_signals_plugin/export/hello_signals_editor_export_plugin.gd
index afc4162..f0f3288 100644
--- a/hello_signals/demo/addons/hello_signals_plugin/hello_signals_export_plugin.gd
+++ b/hello_signals/demo/addons/hello_signals_plugin/export/hello_signals_editor_export_plugin.gd
@@ -8,9 +8,9 @@ func _supports_platform(platform):
func _get_android_libraries(platform, debug):
if debug:
- return PackedStringArray(["hello_signals_plugin/HelloSignals.debug.aar"])
+ return PackedStringArray(["hello_signals_plugin/export/HelloSignals.debug.aar"])
else:
- return PackedStringArray(["hello_signals_plugin/HelloSignals.release.aar"])
+ return PackedStringArray(["hello_signals_plugin/export/HelloSignals.release.aar"])
func _get_name():
return "Hello Signals plugin"
diff --git a/hello_signals/demo/addons/hello_signals_plugin/hello_signals_plugin.gd b/hello_signals/demo/addons/hello_signals_plugin/export/hello_signals_editor_plugin.gd
index 65d8034..5c71083 100644
--- a/hello_signals/demo/addons/hello_signals_plugin/hello_signals_plugin.gd
+++ b/hello_signals/demo/addons/hello_signals_plugin/export/hello_signals_editor_plugin.gd
@@ -6,7 +6,7 @@ var export_plugin : EditorExportPlugin
func _enter_tree():
# Initialization of the plugin goes here.
- export_plugin = preload("hello_signals_export_plugin.gd").new()
+ export_plugin = preload("hello_signals_editor_export_plugin.gd").new()
add_export_plugin(export_plugin)
pass
diff --git a/hello_signals/demo/addons/hello_signals_plugin/interface/hello_signals_plugin.gd b/hello_signals/demo/addons/hello_signals_plugin/interface/hello_signals_plugin.gd
new file mode 100644
index 0000000..0cc9c1d
--- /dev/null
+++ b/hello_signals/demo/addons/hello_signals_plugin/interface/hello_signals_plugin.gd
@@ -0,0 +1,27 @@
+class_name HelloSignalsPlugin extends Object
+
+## Interface used to access the functionality provided by the HelloSignals plugin
+
+var _hello_signals_singleton
+
+func _init():
+ if Engine.has_singleton("HelloSignals"):
+ _hello_signals_singleton = Engine.get_singleton("HelloSignals")
+ else:
+ printerr("Couldn't find HelloSignals singleton")
+
+
+## Register for the tiktok signals emitted
+func registerForTikTok(callback: Callable) -> void:
+ if _hello_signals_singleton:
+ _hello_signals_singleton.connect("TikTok", callback)
+ else:
+ printerr("Unable to register for tiktok")
+
+
+## Start tiktok if not started, otherwise stop it
+func toggleTikTok():
+ if _hello_signals_singleton:
+ _hello_signals_singleton.onButtonPressed()
+ else:
+ printerr("Unable to toggle tiktok")
diff --git a/hello_signals/demo/addons/hello_signals_plugin/plugin.cfg b/hello_signals/demo/addons/hello_signals_plugin/plugin.cfg
index 8fb2c37..b32555f 100644
--- a/hello_signals/demo/addons/hello_signals_plugin/plugin.cfg
+++ b/hello_signals/demo/addons/hello_signals_plugin/plugin.cfg
@@ -4,4 +4,4 @@ name="Hello Signals plugin"
description="Showcases how to package a sample Android plugin"
author="Fredia Huya-Kouadio"
version=""
-script="hello_signals_plugin.gd"
+script="export/hello_signals_editor_plugin.gd"
diff --git a/hello_signals/demo/export_presets.cfg b/hello_signals/demo/export_presets.cfg
index fda6651..1d4cb1f 100644
--- a/hello_signals/demo/export_presets.cfg
+++ b/hello_signals/demo/export_presets.cfg
@@ -8,7 +8,7 @@ custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
-export_path=""
+export_path="android/Hello Signals Plugin Demo.apk"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
@@ -39,9 +39,6 @@ launcher_icons/adaptive_foreground_432x432=""
launcher_icons/adaptive_background_432x432=""
graphics/opengl_debug=false
xr_features/xr_mode=0
-xr_features/hand_tracking=0
-xr_features/hand_tracking_frequency=0
-xr_features/passthrough=0
screen/immersive_mode=true
screen/support_small=true
screen/support_normal=true
@@ -199,3 +196,6 @@ permissions/write_sms=false
permissions/write_social_stream=false
permissions/write_sync_settings=false
permissions/write_user_dictionary=false
+xr_features/hand_tracking=0
+xr_features/hand_tracking_frequency=0
+xr_features/passthrough=0
diff --git a/hello_signals/demo/project.godot b/hello_signals/demo/project.godot
index d71c32c..655eefc 100644
--- a/hello_signals/demo/project.godot
+++ b/hello_signals/demo/project.godot
@@ -26,6 +26,7 @@ enabled=PackedStringArray("res://addons/hello_signals_plugin/plugin.cfg")
[rendering]
renderer/rendering_method="gl_compatibility"
+renderer/rendering_method.mobile="gl_compatibility"
textures/vram_compression/import_etc2_astc=true
environment/defaults/default_environment="res://default_env.tres"
quality/driver/driver_name="GLES2"
diff --git a/hello_world/README.md b/hello_world/README.md
new file mode 100644
index 0000000..5cfb640
--- /dev/null
+++ b/hello_world/README.md
@@ -0,0 +1,3 @@
+## Hello World plugin
+
+Showcase how to build a simple Godot Android plugin which is invoked from gdscript
diff --git a/hello_world/build.gradle b/hello_world/build.gradle
index 003ea6f..4c12e93 100644
--- a/hello_world/build.gradle
+++ b/hello_world/build.gradle
@@ -30,13 +30,13 @@ dependencies {
task copyDebugAARToAddons(type: Copy) {
from 'build/outputs/aar'
include 'HelloWorld.debug.aar'
- into 'demo/addons/hello_world_plugin'
+ into 'demo/addons/hello_world_plugin/export'
}
task copyReleaseAARToAddons(type: Copy) {
from 'build/outputs/aar'
include 'HelloWorld.release.aar'
- into 'demo/addons/hello_world_plugin'
+ into 'demo/addons/hello_world_plugin/export'
}
assemble.finalizedBy(copyDebugAARToAddons)
diff --git a/hello_world/demo/Main.gd b/hello_world/demo/Main.gd
index 11b332b..c5174eb 100644
--- a/hello_world/demo/Main.gd
+++ b/hello_world/demo/Main.gd
@@ -1,12 +1,11 @@
extends Node2D
-var hello_world
+var hello_world_plugin : HelloWorldPlugin
func _ready():
- if Engine.has_singleton("HelloWorld"):
- hello_world = Engine.get_singleton("HelloWorld")
+ hello_world_plugin = preload("res://addons/hello_world_plugin/interface/hello_world_plugin.gd").new()
func _on_Button_pressed():
- if hello_world:
- hello_world.helloWorld()
+ if hello_world_plugin:
+ hello_world_plugin.helloWorld()
diff --git a/hello_world/demo/addons/hello_world_plugin/.gdignore b/hello_world/demo/addons/hello_world_plugin/.gdignore
deleted file mode 100644
index 8b13789..0000000
--- a/hello_world/demo/addons/hello_world_plugin/.gdignore
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/hello_world/demo/addons/hello_world_plugin/export/.gdignore b/hello_world/demo/addons/hello_world_plugin/export/.gdignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/hello_world/demo/addons/hello_world_plugin/export/.gdignore
diff --git a/hello_world/demo/addons/hello_world_plugin/HelloWorld.debug.aar b/hello_world/demo/addons/hello_world_plugin/export/HelloWorld.debug.aar
index ddb9986..4d59e06 100644
--- a/hello_world/demo/addons/hello_world_plugin/HelloWorld.debug.aar
+++ b/hello_world/demo/addons/hello_world_plugin/export/HelloWorld.debug.aar
Binary files differ
diff --git a/hello_world/demo/addons/hello_world_plugin/HelloWorld.release.aar b/hello_world/demo/addons/hello_world_plugin/export/HelloWorld.release.aar
index 8277aa5..6b112c5 100644
--- a/hello_world/demo/addons/hello_world_plugin/HelloWorld.release.aar
+++ b/hello_world/demo/addons/hello_world_plugin/export/HelloWorld.release.aar
Binary files differ
diff --git a/hello_world/demo/addons/hello_world_plugin/hello_world_export_plugin.gd b/hello_world/demo/addons/hello_world_plugin/export/hello_world_editor_export_plugin.gd
index 6749497..46a8a3b 100644
--- a/hello_world/demo/addons/hello_world_plugin/hello_world_export_plugin.gd
+++ b/hello_world/demo/addons/hello_world_plugin/export/hello_world_editor_export_plugin.gd
@@ -8,9 +8,9 @@ func _supports_platform(platform):
func _get_android_libraries(platform, debug):
if debug:
- return PackedStringArray(["hello_world_plugin/HelloWorld.debug.aar"])
+ return PackedStringArray(["hello_world_plugin/export/HelloWorld.debug.aar"])
else:
- return PackedStringArray(["hello_world_plugin/HelloWorld.release.aar"])
+ return PackedStringArray(["hello_world_plugin/export/HelloWorld.release.aar"])
func _get_name():
return "HelloWorldPlugin"
diff --git a/hello_world/demo/addons/hello_world_plugin/hello_world_plugin.gd b/hello_world/demo/addons/hello_world_plugin/export/hello_world_editor_plugin.gd
index 05bb37a..3865634 100644
--- a/hello_world/demo/addons/hello_world_plugin/hello_world_plugin.gd
+++ b/hello_world/demo/addons/hello_world_plugin/export/hello_world_editor_plugin.gd
@@ -6,7 +6,7 @@ var export_plugin : EditorExportPlugin
func _enter_tree():
# Initialization of the plugin goes here.
- export_plugin = preload("hello_world_export_plugin.gd").new()
+ export_plugin = preload("hello_world_editor_export_plugin.gd").new()
add_export_plugin(export_plugin)
pass
diff --git a/hello_world/demo/addons/hello_world_plugin/interface/hello_world_plugin.gd b/hello_world/demo/addons/hello_world_plugin/interface/hello_world_plugin.gd
new file mode 100644
index 0000000..ed84ef3
--- /dev/null
+++ b/hello_world/demo/addons/hello_world_plugin/interface/hello_world_plugin.gd
@@ -0,0 +1,18 @@
+class_name HelloWorldPlugin extends Object
+
+## Interface used to access the functionality provided by this plugin
+
+var _hello_world_singleton
+
+func _init():
+ if Engine.has_singleton("HelloWorld"):
+ _hello_world_singleton = Engine.get_singleton("HelloWorld")
+ else:
+ printerr("Initialization error: unable to access the java logic")
+
+## Toggle between showing and hiding the hello world text
+func helloWorld():
+ if _hello_world_singleton:
+ _hello_world_singleton.helloWorld()
+ else:
+ printerr("Initialization error")
diff --git a/hello_world/demo/addons/hello_world_plugin/plugin.cfg b/hello_world/demo/addons/hello_world_plugin/plugin.cfg
index 0024e5f..bc8575e 100644
--- a/hello_world/demo/addons/hello_world_plugin/plugin.cfg
+++ b/hello_world/demo/addons/hello_world_plugin/plugin.cfg
@@ -4,4 +4,4 @@ name="HelloWorldPlugin"
description="Sample to showcase how to package a Godot Android plugin "
author="Fredia Huya-Kouadio (m4gr3d)"
version=""
-script="hello_world_plugin.gd"
+script="export/hello_world_editor_plugin.gd"
diff --git a/hello_world/demo/export_presets.cfg b/hello_world/demo/export_presets.cfg
index 3892c84..6356705 100644
--- a/hello_world/demo/export_presets.cfg
+++ b/hello_world/demo/export_presets.cfg
@@ -39,9 +39,6 @@ launcher_icons/adaptive_foreground_432x432=""
launcher_icons/adaptive_background_432x432=""
graphics/opengl_debug=false
xr_features/xr_mode=0
-xr_features/hand_tracking=0
-xr_features/hand_tracking_frequency=0
-xr_features/passthrough=0
screen/immersive_mode=true
screen/support_small=true
screen/support_normal=true
@@ -199,3 +196,6 @@ permissions/write_sms=false
permissions/write_social_stream=false
permissions/write_sync_settings=false
permissions/write_user_dictionary=false
+xr_features/hand_tracking=0
+xr_features/hand_tracking_frequency=0
+xr_features/passthrough=0
diff --git a/hello_world/demo/project.godot b/hello_world/demo/project.godot
index a9cf847..3fcf242 100644
--- a/hello_world/demo/project.godot
+++ b/hello_world/demo/project.godot
@@ -26,6 +26,7 @@ enabled=PackedStringArray("res://addons/hello_world_plugin/plugin.cfg")
[rendering]
renderer/rendering_method="gl_compatibility"
+renderer/rendering_method.mobile="gl_compatibility"
textures/vram_compression/import_etc2_astc=true
environment/defaults/default_environment="res://default_env.tres"
quality/driver/driver_name="GLES2"