Skip to content

Commit

Permalink
Merge pull request #101498 from m4gr3d/run_launcher_godot_app_from_ed…
Browse files Browse the repository at this point in the history
…itor

Use implicit launch when running a Godot Android project from the editor
  • Loading branch information
akien-mga committed Jan 13, 2025
2 parents df0a268 + 17279cd commit e898130
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
41 changes: 36 additions & 5 deletions platform/android/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,21 @@ String EditorExportPlatformAndroid::get_export_option_warning(const EditorExport
}
}
}
} else if (p_name == "package/show_in_android_tv") {
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
if (bool(p_preset->get("package/show_in_android_tv")) && !gradle_build_enabled) {
return TTR("\"Use Gradle Build\" must be enabled to enable \"Show In Android Tv\".");
}
} else if (p_name == "package/show_as_launcher_app") {
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
if (bool(p_preset->get("package/show_as_launcher_app")) && !gradle_build_enabled) {
return TTR("\"Use Gradle Build\" must be enabled to enable \"Show As Launcher App\".");
}
} else if (p_name == "package/show_in_app_library") {
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
if (!bool(p_preset->get("package/show_in_app_library")) && !gradle_build_enabled) {
return TTR("\"Use Gradle Build\" must be enabled to disable \"Show In App Library\".");
}
}
}
return String();
Expand Down Expand Up @@ -2283,15 +2298,31 @@ Error EditorExportPlatformAndroid::run(const Ref<EditorExportPreset> &p_preset,
}
args.push_back("-a");
args.push_back("android.intent.action.MAIN");
args.push_back("-n");
args.push_back(get_package_name(package_name) + "/com.godot.game.GodotApp");

// Going with implicit launch first based on the LAUNCHER category and the app's package.
args.push_back("-c");
args.push_back("android.intent.category.LAUNCHER");
args.push_back(get_package_name(package_name));

output.clear();
err = OS::get_singleton()->execute(adb, args, &output, &rv, true);
print_verbose(output);
if (err || rv != 0) {
add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Could not execute on device."));
CLEANUP_AND_RETURN(ERR_CANT_CREATE);
if (err || rv != 0 || output.contains("Error: Activity not started")) {
// The implicit launch failed, let's try an explicit launch by specifying the component name before giving up.
const String component_name = get_package_name(package_name) + "/com.godot.game.GodotApp";
print_line("Implicit launch failed.. Trying explicit launch using", component_name);
args.erase(get_package_name(package_name));
args.push_back("-n");
args.push_back(component_name);

output.clear();
err = OS::get_singleton()->execute(adb, args, &output, &rv, true);
print_verbose(output);

if (err || rv != 0 || output.begins_with("Error: Activity not started")) {
add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Could not execute on device."));
CLEANUP_AND_RETURN(ERR_CANT_CREATE);
}
}

CLEANUP_AND_RETURN(OK);
Expand Down
2 changes: 1 addition & 1 deletion platform/android/export/gradle_export_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ String _get_screen_sizes_tag(const Ref<EditorExportPreset> &p_preset) {
String _get_activity_tag(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug) {
String orientation = _get_android_orientation_label(DisplayServer::ScreenOrientation(int(GLOBAL_GET("display/window/handheld/orientation"))));
String manifest_activity_text = vformat(
" <activity android:name=\"com.godot.game.GodotApp\" "
" <activity android:name=\".GodotApp\" "
"tools:replace=\"android:screenOrientation,android:excludeFromRecents,android:resizeableActivity\" "
"tools:node=\"mergeOnlyAttributes\" "
"android:excludeFromRecents=\"%s\" "
Expand Down

0 comments on commit e898130

Please sign in to comment.