Skip to content

Commit

Permalink
Android port of the Godot Editor
Browse files Browse the repository at this point in the history
These set of changes focus primarily on getting the core logic and overall Godot Editor UI and functionality up and running natively on Android devices.
UI tweaks / cleanup / polish, as well configuration for Android specific functionality / restrictions will be addressed in follow-up PRs iteratively based on feedback.

Co-authored-by: thebestnom <shoval.arad@gmail.com>
  • Loading branch information
m4gr3d and thebestnom committed Mar 28, 2022
1 parent 0c7a15d commit 5711037
Show file tree
Hide file tree
Showing 25 changed files with 740 additions and 68 deletions.
3 changes: 3 additions & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@ void EditorNode::_notification(int p_what) {
get_tree()->get_root()->set_snap_2d_transforms_to_pixel(false);
get_tree()->get_root()->set_snap_2d_vertices_to_pixel(false);
get_tree()->set_auto_accept_quit(false);
#ifdef ANDROID_ENABLED
get_tree()->set_quit_on_go_back(false);
#endif
get_tree()->get_root()->connect("files_dropped", callable_mp(this, &EditorNode::_dropped_files));

command_palette->register_shortcuts_as_command();
Expand Down
3 changes: 2 additions & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2276,9 +2276,10 @@ bool Main::start() {

bool embed_subwindows = GLOBAL_DEF("display/window/subwindows/embed_subwindows", true);

if (OS::get_singleton()->is_single_window() || (!project_manager && !editor && embed_subwindows)) {
if (OS::get_singleton()->is_single_window() || (!project_manager && !editor && embed_subwindows) || !DisplayServer::get_singleton()->has_feature(DisplayServer::Feature::FEATURE_SUBWINDOWS)) {
sml->get_root()->set_embedding_subwindows(true);
}

ResourceLoader::add_custom_loaders();
ResourceSaver::add_custom_savers();

Expand Down
11 changes: 9 additions & 2 deletions platform/android/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@ else:
if lib_arch_dir != "":
if env["target"] == "release":
lib_type_dir = "release"
else: # release_debug, debug
elif env["target"] == "release_debug":
lib_type_dir = "debug"
else: # debug
lib_type_dir = "dev"

out_dir = "#platform/android/java/lib/libs/" + lib_type_dir + "/" + lib_arch_dir
if env["tools"]:
lib_tools_dir = "tools/"
else:
lib_tools_dir = ""

out_dir = "#platform/android/java/lib/libs/" + lib_tools_dir + lib_type_dir + "/" + lib_arch_dir
env_android.Command(
out_dir + "/libgodot_android.so", "#bin/libgodot" + env["SHLIBSUFFIX"], Move("$TARGET", "$SOURCE")
)
Expand Down
34 changes: 34 additions & 0 deletions platform/android/java/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ allprojects {
}
}

configurations {
// Initializes a placeholder for the devImplementation dependency configuration.
devImplementation {}
}

dependencies {
implementation libraries.kotlinStdLib
implementation libraries.androidxFragment
Expand All @@ -45,6 +50,7 @@ dependencies {
// Custom build mode. In this scenario this project is the only one around and the Godot
// library is available through the pre-generated godot-lib.*.aar android archive files.
debugImplementation fileTree(dir: 'libs/debug', include: ['*.jar', '*.aar'])
devImplementation fileTree(dir: 'libs/dev', include: ['*.jar', '*.aar'])
releaseImplementation fileTree(dir: 'libs/release', include: ['*.jar', '*.aar'])
}

Expand All @@ -66,6 +72,7 @@ dependencies {
android {
compileSdkVersion versions.compileSdk
buildToolsVersion versions.buildTools
ndkVersion versions.ndkVersion

compileOptions {
sourceCompatibility versions.javaVersion
Expand Down Expand Up @@ -93,6 +100,8 @@ android {
versionName getExportVersionName()
minSdkVersion getExportMinSdkVersion()
targetSdkVersion getExportTargetSdkVersion()

missingDimensionStrategy 'products', 'template'
}

lintOptions {
Expand Down Expand Up @@ -146,6 +155,18 @@ android {
}
}

dev {
initWith debug
// Signing and zip-aligning are skipped for prebuilt builds, but
// performed for custom builds.
zipAlignEnabled shouldZipAlign()
if (shouldSign()) {
signingConfig signingConfigs.debug
} else {
signingConfig null
}
}

release {
// Signing and zip-aligning are skipped for prebuilt builds, but
// performed for custom builds.
Expand All @@ -167,6 +188,7 @@ android {
assets.srcDirs = ['assets']
}
debug.jniLibs.srcDirs = ['libs/debug', 'libs/debug/vulkan_validation_layers']
dev.jniLibs.srcDirs = ['libs/dev']
release.jniLibs.srcDirs = ['libs/release']
}

Expand All @@ -183,6 +205,12 @@ task copyAndRenameDebugApk(type: Copy) {
rename "android_debug.apk", getExportFilename()
}

task copyAndRenameDevApk(type: Copy) {
from "$buildDir/outputs/apk/dev/android_dev.apk"
into getExportPath()
rename "android_dev.apk", getExportFilename()
}

task copyAndRenameReleaseApk(type: Copy) {
from "$buildDir/outputs/apk/release/android_release.apk"
into getExportPath()
Expand All @@ -195,6 +223,12 @@ task copyAndRenameDebugAab(type: Copy) {
rename "build-debug.aab", getExportFilename()
}

task copyAndRenameDevAab(type: Copy) {
from "$buildDir/outputs/bundle/dev/build-dev.aab"
into getExportPath()
rename "build-dev.aab", getExportFilename()
}

task copyAndRenameReleaseAab(type: Copy) {
from "$buildDir/outputs/bundle/release/build-release.aab"
into getExportPath()
Expand Down
52 changes: 45 additions & 7 deletions platform/android/java/app/config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ext.getGodotEditorVersion = { ->
String editorVersion = project.hasProperty("godot_editor_version") ? project.property("godot_editor_version") : ""
if (editorVersion == null || editorVersion.isEmpty()) {
// Try the library version first
editorVersion = getGodotLibraryVersion()
editorVersion = getGodotLibraryVersionName()

if (editorVersion.isEmpty()) {
// Fallback value.
Expand All @@ -86,9 +86,24 @@ ext.getGodotEditorVersion = { ->
return editorVersion
}

ext.getGodotLibraryVersionCode = { ->
String versionName = ""
int versionCode = 1
(versionName, versionCode) = getGodotLibraryVersion()
return versionCode
}

ext.getGodotLibraryVersionName = { ->
String versionName = ""
int versionCode = 1
(versionName, versionCode) = getGodotLibraryVersion()
return versionName
}

ext.generateGodotLibraryVersion = { List<String> requiredKeys ->
// Attempt to read the version from the `version.py` file.
String libraryVersion = ""
String libraryVersionName = ""
int libraryVersionCode = 0

File versionFile = new File("../../../version.py")
if (versionFile.isFile()) {
Expand All @@ -109,15 +124,35 @@ ext.generateGodotLibraryVersion = { List<String> requiredKeys ->
}

if (requiredKeys.empty) {
libraryVersion = map.values().join(".")
libraryVersionName = map.values().join(".")
try {
if (map.containsKey("patch")) {
libraryVersionCode = Integer.parseInt(map["patch"])
}

if (map.containsKey("minor")) {
libraryVersionCode += (Integer.parseInt(map["minor"]) * 100)
}

if (map.containsKey("major")) {
libraryVersionCode += (Integer.parseInt(map["major"]) * 10000)
}
} catch (NumberFormatException ignore) {
libraryVersionCode = 1
}
}
}

if (libraryVersion.isEmpty()) {
if (libraryVersionName.isEmpty()) {
// Fallback value in case we're unable to read the file.
libraryVersion = "custom_build"
libraryVersionName = "custom_build"
}

if (libraryVersionCode == 0) {
libraryVersionCode = 1
}
return libraryVersion

return [libraryVersionName, libraryVersionCode]
}

ext.getGodotLibraryVersion = { ->
Expand All @@ -127,7 +162,10 @@ ext.getGodotLibraryVersion = { ->

ext.getGodotPublishVersion = { ->
List<String> requiredKeys = ["major", "minor", "patch", "status"]
return generateGodotLibraryVersion(requiredKeys)
String versionName = ""
int versionCode = 1
(versionName, versionCode) = generateGodotLibraryVersion(requiredKeys)
return versionName
}

final String VALUE_SEPARATOR_REGEX = "\\|"
Expand Down
Loading

0 comments on commit 5711037

Please sign in to comment.