diff options
Diffstat (limited to 'editor/export_template_manager.cpp')
-rw-r--r-- | editor/export_template_manager.cpp | 89 |
1 files changed, 2 insertions, 87 deletions
diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp index 536cfaa1dd..202b554be4 100644 --- a/editor/export_template_manager.cpp +++ b/editor/export_template_manager.cpp @@ -562,10 +562,8 @@ bool ExportTemplateManager::can_install_android_template() { Error ExportTemplateManager::install_android_template() { - // To support custom Android builds, we install various things to the project's res://android folder. - // First is the Java source code and buildsystem from android_source.zip. - // Then we extract the Godot Android libraries from pre-build android_release.apk - // and android_debug.apk, to place them in the libs folder. + // To support custom Android builds, we install the Java source code and buildsystem + // from android_source.zip to the project's res://android folder. DirAccessRef da = DirAccess::open("res://"); ERR_FAIL_COND_V(!da, ERR_CANT_CREATE); @@ -661,89 +659,6 @@ Error ExportTemplateManager::install_android_template() { ProgressDialog::get_singleton()->end_task("uncompress_src"); unzClose(pkg); - // Extract libs from pre-built APKs. - err = _extract_libs_from_apk("release"); - ERR_FAIL_COND_V_MSG(err != OK, err, "Can't extract Android libs from android_release.apk."); - err = _extract_libs_from_apk("debug"); - ERR_FAIL_COND_V_MSG(err != OK, err, "Can't extract Android libs from android_debug.apk."); - - return OK; -} - -Error ExportTemplateManager::_extract_libs_from_apk(const String &p_target_name) { - - const String &templates_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(VERSION_FULL_CONFIG); - const String &apk_file = templates_path.plus_file("android_" + p_target_name + ".apk"); - ERR_FAIL_COND_V(!FileAccess::exists(apk_file), ERR_CANT_OPEN); - - FileAccess *src_f = NULL; - zlib_filefunc_def io = zipio_create_io_from_file(&src_f); - - unzFile pkg = unzOpen2(apk_file.utf8().get_data(), &io); - ERR_FAIL_COND_V_MSG(!pkg, ERR_CANT_OPEN, "Android APK can't be extracted."); - - DirAccessRef da = DirAccess::open("res://"); - ERR_FAIL_COND_V(!da, ERR_CANT_CREATE); - - // 8 steps because 4 arches, 2 libs per arch. - ProgressDialog::get_singleton()->add_task("extract_libs_from_apk", TTR("Extracting Android Libraries From APKs"), 8); - - int ret = unzGoToFirstFile(pkg); - Set<String> dirs_tested; - int idx = 0; - while (ret == UNZ_OK) { - // Get file path. - unz_file_info info; - char fpath[16384]; - ret = unzGetCurrentFileInfo(pkg, &info, fpath, 16384, NULL, 0, NULL, 0); - - String path = fpath; - String base_dir = path.get_base_dir(); - String file = path.get_file(); - - if (!base_dir.begins_with("lib") || path.ends_with("/")) { - ret = unzGoToNextFile(pkg); - continue; - } - - Vector<uint8_t> data; - data.resize(info.uncompressed_size); - - // Read. - unzOpenCurrentFile(pkg); - unzReadCurrentFile(pkg, data.ptrw(), data.size()); - unzCloseCurrentFile(pkg); - - // We have a "lib" folder in the APK, but it should be "libs/{release,debug}" in the source dir. - String target_base_dir = base_dir.replace_first("lib", String("libs").plus_file(p_target_name)); - - if (!dirs_tested.has(base_dir)) { - da->make_dir_recursive(String("android/build").plus_file(target_base_dir)); - dirs_tested.insert(base_dir); - } - - String to_write = String("res://android/build").plus_file(target_base_dir.plus_file(path.get_file())); - FileAccess *f = FileAccess::open(to_write, FileAccess::WRITE); - if (f) { - f->store_buffer(data.ptr(), data.size()); - memdelete(f); -#ifndef WINDOWS_ENABLED - // We can't retrieve Unix permissions from the APK it seems, so simply set 0755 as should be. - FileAccess::set_unix_permissions(to_write, 0755); -#endif - } else { - ERR_PRINTS("Can't uncompress file: " + to_write); - } - - ProgressDialog::get_singleton()->task_step("extract_libs_from_apk", path, idx); - - idx++; - ret = unzGoToNextFile(pkg); - } - - ProgressDialog::get_singleton()->end_task("extract_libs_from_apk"); - unzClose(pkg); - return OK; } |