Skip to content

Commit e898130

Browse files
committed
Merge pull request godotengine#101498 from m4gr3d/run_launcher_godot_app_from_editor
Use implicit launch when running a Godot Android project from the editor
2 parents df0a268 + 17279cd commit e898130

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

platform/android/export/export_plugin.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,6 +1917,21 @@ String EditorExportPlatformAndroid::get_export_option_warning(const EditorExport
19171917
}
19181918
}
19191919
}
1920+
} else if (p_name == "package/show_in_android_tv") {
1921+
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
1922+
if (bool(p_preset->get("package/show_in_android_tv")) && !gradle_build_enabled) {
1923+
return TTR("\"Use Gradle Build\" must be enabled to enable \"Show In Android Tv\".");
1924+
}
1925+
} else if (p_name == "package/show_as_launcher_app") {
1926+
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
1927+
if (bool(p_preset->get("package/show_as_launcher_app")) && !gradle_build_enabled) {
1928+
return TTR("\"Use Gradle Build\" must be enabled to enable \"Show As Launcher App\".");
1929+
}
1930+
} else if (p_name == "package/show_in_app_library") {
1931+
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
1932+
if (!bool(p_preset->get("package/show_in_app_library")) && !gradle_build_enabled) {
1933+
return TTR("\"Use Gradle Build\" must be enabled to disable \"Show In App Library\".");
1934+
}
19201935
}
19211936
}
19221937
return String();
@@ -2283,15 +2298,31 @@ Error EditorExportPlatformAndroid::run(const Ref<EditorExportPreset> &p_preset,
22832298
}
22842299
args.push_back("-a");
22852300
args.push_back("android.intent.action.MAIN");
2286-
args.push_back("-n");
2287-
args.push_back(get_package_name(package_name) + "/com.godot.game.GodotApp");
2301+
2302+
// Going with implicit launch first based on the LAUNCHER category and the app's package.
2303+
args.push_back("-c");
2304+
args.push_back("android.intent.category.LAUNCHER");
2305+
args.push_back(get_package_name(package_name));
22882306

22892307
output.clear();
22902308
err = OS::get_singleton()->execute(adb, args, &output, &rv, true);
22912309
print_verbose(output);
2292-
if (err || rv != 0) {
2293-
add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Could not execute on device."));
2294-
CLEANUP_AND_RETURN(ERR_CANT_CREATE);
2310+
if (err || rv != 0 || output.contains("Error: Activity not started")) {
2311+
// The implicit launch failed, let's try an explicit launch by specifying the component name before giving up.
2312+
const String component_name = get_package_name(package_name) + "/com.godot.game.GodotApp";
2313+
print_line("Implicit launch failed.. Trying explicit launch using", component_name);
2314+
args.erase(get_package_name(package_name));
2315+
args.push_back("-n");
2316+
args.push_back(component_name);
2317+
2318+
output.clear();
2319+
err = OS::get_singleton()->execute(adb, args, &output, &rv, true);
2320+
print_verbose(output);
2321+
2322+
if (err || rv != 0 || output.begins_with("Error: Activity not started")) {
2323+
add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Could not execute on device."));
2324+
CLEANUP_AND_RETURN(ERR_CANT_CREATE);
2325+
}
22952326
}
22962327

22972328
CLEANUP_AND_RETURN(OK);

platform/android/export/gradle_export_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ String _get_screen_sizes_tag(const Ref<EditorExportPreset> &p_preset) {
260260
String _get_activity_tag(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug) {
261261
String orientation = _get_android_orientation_label(DisplayServer::ScreenOrientation(int(GLOBAL_GET("display/window/handheld/orientation"))));
262262
String manifest_activity_text = vformat(
263-
" <activity android:name=\"com.godot.game.GodotApp\" "
263+
" <activity android:name=\".GodotApp\" "
264264
"tools:replace=\"android:screenOrientation,android:excludeFromRecents,android:resizeableActivity\" "
265265
"tools:node=\"mergeOnlyAttributes\" "
266266
"android:excludeFromRecents=\"%s\" "

0 commit comments

Comments
 (0)