Browse Source

Addes ability to load build sources from file.

* If not present, the dialog asks to load build sources from a file.
* The export templates check now also verifies that build sources are installed and skips the template check.

This makes Android development easier.

(cherry picked from commit 6639cc98531013a995e3bda220a3f1a6412e678c)
reduz 4 years ago
parent
commit
ca223d71d8

+ 18 - 0
editor/editor_node.cpp

@@ -2223,6 +2223,10 @@ void EditorNode::_run(bool p_current, const String &p_custom) {
 	_playing_edited = p_current;
 	_playing_edited = p_current;
 }
 }
 
 
+void EditorNode::_android_build_source_selected(const String &p_file) {
+	export_template_manager->install_android_template_from_file(p_file);
+}
+
 void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
 void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
 	if (!p_confirmed) { //this may be a hack..
 	if (!p_confirmed) { //this may be a hack..
 		current_option = (MenuOptions)p_option;
 		current_option = (MenuOptions)p_option;
@@ -2753,6 +2757,10 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
 			export_template_manager->popup_manager();
 			export_template_manager->popup_manager();
 
 
 		} break;
 		} break;
+		case SETTINGS_INSTALL_ANDROID_BUILD_TEMPLATE: {
+			custom_build_manage_templates->hide();
+			file_android_build_source->popup_centered_ratio();
+		} break;
 		case SETTINGS_MANAGE_FEATURE_PROFILES: {
 		case SETTINGS_MANAGE_FEATURE_PROFILES: {
 			feature_profile_manager->popup_centered_clamped(Size2(900, 800) * EDSCALE, 0.8);
 			feature_profile_manager->popup_centered_clamped(Size2(900, 800) * EDSCALE, 0.8);
 		} break;
 		} break;
@@ -5513,6 +5521,7 @@ void EditorNode::_bind_methods() {
 	ClassDB::bind_method("_unhandled_input", &EditorNode::_unhandled_input);
 	ClassDB::bind_method("_unhandled_input", &EditorNode::_unhandled_input);
 	ClassDB::bind_method("_update_file_menu_opened", &EditorNode::_update_file_menu_opened);
 	ClassDB::bind_method("_update_file_menu_opened", &EditorNode::_update_file_menu_opened);
 	ClassDB::bind_method("_update_file_menu_closed", &EditorNode::_update_file_menu_closed);
 	ClassDB::bind_method("_update_file_menu_closed", &EditorNode::_update_file_menu_closed);
+	ClassDB::bind_method("_android_build_source_selected", &EditorNode::_android_build_source_selected);
 
 
 	ClassDB::bind_method(D_METHOD("push_item", "object", "property", "inspector_only"), &EditorNode::push_item, DEFVAL(""), DEFVAL(false));
 	ClassDB::bind_method(D_METHOD("push_item", "object", "property", "inspector_only"), &EditorNode::push_item, DEFVAL(""), DEFVAL(false));
 
 
@@ -6660,9 +6669,18 @@ EditorNode::EditorNode() {
 	custom_build_manage_templates = memnew(ConfirmationDialog);
 	custom_build_manage_templates = memnew(ConfirmationDialog);
 	custom_build_manage_templates->set_text(TTR("Android build template is missing, please install relevant templates."));
 	custom_build_manage_templates->set_text(TTR("Android build template is missing, please install relevant templates."));
 	custom_build_manage_templates->get_ok()->set_text(TTR("Manage Templates"));
 	custom_build_manage_templates->get_ok()->set_text(TTR("Manage Templates"));
+	custom_build_manage_templates->add_button(TTR("Install from file"))->connect("pressed", this, "_menu_option", varray(SETTINGS_INSTALL_ANDROID_BUILD_TEMPLATE));
 	custom_build_manage_templates->connect("confirmed", this, "_menu_option", varray(SETTINGS_MANAGE_EXPORT_TEMPLATES));
 	custom_build_manage_templates->connect("confirmed", this, "_menu_option", varray(SETTINGS_MANAGE_EXPORT_TEMPLATES));
 	gui_base->add_child(custom_build_manage_templates);
 	gui_base->add_child(custom_build_manage_templates);
 
 
+	file_android_build_source = memnew(EditorFileDialog);
+	file_android_build_source->set_title(TTR("Select android sources file"));
+	file_android_build_source->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
+	file_android_build_source->set_mode(EditorFileDialog::MODE_OPEN_FILE);
+	file_android_build_source->add_filter("*.zip");
+	file_android_build_source->connect("file_selected", this, "_android_build_source_selected");
+	gui_base->add_child(file_android_build_source);
+
 	install_android_build_template = memnew(ConfirmationDialog);
 	install_android_build_template = memnew(ConfirmationDialog);
 	install_android_build_template->set_text(TTR("This will set up your project for custom Android builds by installing the source template to \"res://android/build\".\nYou can then apply modifications and build your own custom APK on export (adding modules, changing the AndroidManifest.xml, etc.).\nNote that in order to make custom builds instead of using pre-built APKs, the \"Use Custom Build\" option should be enabled in the Android export preset."));
 	install_android_build_template->set_text(TTR("This will set up your project for custom Android builds by installing the source template to \"res://android/build\".\nYou can then apply modifications and build your own custom APK on export (adding modules, changing the AndroidManifest.xml, etc.).\nNote that in order to make custom builds instead of using pre-built APKs, the \"Use Custom Build\" option should be enabled in the Android export preset."));
 	install_android_build_template->get_ok()->set_text(TTR("Install"));
 	install_android_build_template->get_ok()->set_text(TTR("Install"));

+ 4 - 0
editor/editor_node.h

@@ -187,6 +187,7 @@ private:
 		SETTINGS_EDITOR_CONFIG_FOLDER,
 		SETTINGS_EDITOR_CONFIG_FOLDER,
 		SETTINGS_MANAGE_EXPORT_TEMPLATES,
 		SETTINGS_MANAGE_EXPORT_TEMPLATES,
 		SETTINGS_MANAGE_FEATURE_PROFILES,
 		SETTINGS_MANAGE_FEATURE_PROFILES,
+		SETTINGS_INSTALL_ANDROID_BUILD_TEMPLATE,
 		SETTINGS_PICK_MAIN_SCENE,
 		SETTINGS_PICK_MAIN_SCENE,
 		SETTINGS_TOGGLE_CONSOLE,
 		SETTINGS_TOGGLE_CONSOLE,
 		SETTINGS_TOGGLE_FULLSCREEN,
 		SETTINGS_TOGGLE_FULLSCREEN,
@@ -332,6 +333,7 @@ private:
 	EditorFileDialog *file_templates;
 	EditorFileDialog *file_templates;
 	EditorFileDialog *file_export_lib;
 	EditorFileDialog *file_export_lib;
 	EditorFileDialog *file_script;
 	EditorFileDialog *file_script;
+	EditorFileDialog *file_android_build_source;
 	CheckBox *file_export_lib_merge;
 	CheckBox *file_export_lib_merge;
 	String current_path;
 	String current_path;
 	MenuButton *update_spinner;
 	MenuButton *update_spinner;
@@ -456,6 +458,8 @@ private:
 	void _menu_confirm_current();
 	void _menu_confirm_current();
 	void _menu_option_confirm(int p_option, bool p_confirmed);
 	void _menu_option_confirm(int p_option, bool p_confirmed);
 
 
+	void _android_build_source_selected(const String &p_file);
+
 	void _request_screenshot();
 	void _request_screenshot();
 	void _screenshot(bool p_use_utc = false);
 	void _screenshot(bool p_use_utc = false);
 	void _save_screenshot(NodePath p_path);
 	void _save_screenshot(NodePath p_path);

+ 7 - 5
editor/export_template_manager.cpp

@@ -643,6 +643,12 @@ bool ExportTemplateManager::can_install_android_template() {
 }
 }
 
 
 Error ExportTemplateManager::install_android_template() {
 Error ExportTemplateManager::install_android_template() {
+	const String &templates_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(VERSION_FULL_CONFIG);
+	const String &source_zip = templates_path.plus_file("android_source.zip");
+	ERR_FAIL_COND_V(!FileAccess::exists(source_zip), ERR_CANT_OPEN);
+	return install_android_template_from_file(source_zip);
+}
+Error ExportTemplateManager::install_android_template_from_file(const String &p_file) {
 	// To support custom Android builds, we install the Java source code and buildsystem
 	// To support custom Android builds, we install the Java source code and buildsystem
 	// from android_source.zip to the project's res://android folder.
 	// from android_source.zip to the project's res://android folder.
 
 
@@ -675,14 +681,10 @@ Error ExportTemplateManager::install_android_template() {
 
 
 	// Uncompress source template.
 	// Uncompress source template.
 
 
-	const String &templates_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(VERSION_FULL_CONFIG);
-	const String &source_zip = templates_path.plus_file("android_source.zip");
-	ERR_FAIL_COND_V(!FileAccess::exists(source_zip), ERR_CANT_OPEN);
-
 	FileAccess *src_f = nullptr;
 	FileAccess *src_f = nullptr;
 	zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
 	zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
 
 
-	unzFile pkg = unzOpen2(source_zip.utf8().get_data(), &io);
+	unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io);
 	ERR_FAIL_COND_V_MSG(!pkg, ERR_CANT_OPEN, "Android sources not in ZIP format.");
 	ERR_FAIL_COND_V_MSG(!pkg, ERR_CANT_OPEN, "Android sources not in ZIP format.");
 
 
 	int ret = unzGoToFirstFile(pkg);
 	int ret = unzGoToFirstFile(pkg);

+ 2 - 0
editor/export_template_manager.h

@@ -125,6 +125,8 @@ public:
 	bool can_install_android_template();
 	bool can_install_android_template();
 	Error install_android_template();
 	Error install_android_template();
 
 
+	Error install_android_template_from_file(const String &p_file);
+
 	void popup_manager();
 	void popup_manager();
 
 
 	ExportTemplateManager();
 	ExportTemplateManager();

+ 1 - 2
platform/android/export/export.cpp

@@ -2125,10 +2125,9 @@ public:
 				err += template_err;
 				err += template_err;
 			}
 			}
 		} else {
 		} else {
-			r_missing_templates = !exists_export_template("android_source.zip", &err);
-
 			bool installed_android_build_template = FileAccess::exists("res://android/build/build.gradle");
 			bool installed_android_build_template = FileAccess::exists("res://android/build/build.gradle");
 			if (!installed_android_build_template) {
 			if (!installed_android_build_template) {
+				r_missing_templates = !exists_export_template("android_source.zip", &err);
 				err += TTR("Android build template not installed in the project. Install it from the Project menu.") + "\n";
 				err += TTR("Android build template not installed in the project. Install it from the Project menu.") + "\n";
 			}
 			}