diff options
Diffstat (limited to 'platform/android')
-rw-r--r-- | platform/android/audio_driver_opensl.cpp | 11 | ||||
-rw-r--r-- | platform/android/export/export.cpp | 105 | ||||
-rw-r--r-- | platform/android/java_godot_lib_jni.cpp | 13 | ||||
-rw-r--r-- | platform/android/os_android.cpp | 8 |
4 files changed, 65 insertions, 72 deletions
diff --git a/platform/android/audio_driver_opensl.cpp b/platform/android/audio_driver_opensl.cpp index 3f7fd07997..711088c158 100644 --- a/platform/android/audio_driver_opensl.cpp +++ b/platform/android/audio_driver_opensl.cpp @@ -97,17 +97,10 @@ Error AudioDriverOpenSL::init() { { (SLuint32)SL_ENGINEOPTION_THREADSAFE, (SLuint32)SL_BOOLEAN_TRUE } }; res = slCreateEngine(&sl, 1, EngineOption, 0, NULL, NULL); - if (res != SL_RESULT_SUCCESS) { + ERR_FAIL_COND_V_MSG(res != SL_RESULT_SUCCESS, ERR_INVALID_PARAMETER, "Could not initialize OpenSL."); - ERR_EXPLAIN("Could not Initialize OpenSL"); - ERR_FAIL_V(ERR_INVALID_PARAMETER); - } res = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - if (res != SL_RESULT_SUCCESS) { - - ERR_EXPLAIN("Could not Realize OpenSL"); - ERR_FAIL_V(ERR_INVALID_PARAMETER); - } + ERR_FAIL_COND_V_MSG(res != SL_RESULT_SUCCESS, ERR_INVALID_PARAMETER, "Could not realize OpenSL."); return OK; } diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 2fba8bbf7f..16e49e8a38 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -32,6 +32,7 @@ #include "core/io/marshalls.h" #include "core/io/zip_io.h" +#include "core/os/dir_access.h" #include "core/os/file_access.h" #include "core/os/os.h" #include "core/project_settings.h" @@ -725,8 +726,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { uint32_t string_at = decode_uint32(&p_manifest[st_offset + i * 4]); string_at += st_offset + string_count * 4; - ERR_EXPLAIN("Unimplemented, can't read utf8 string table."); - ERR_FAIL_COND(string_flags & UTF8_FLAG); + ERR_FAIL_COND_MSG(string_flags & UTF8_FLAG, "Unimplemented, can't read UTF-8 string table."); if (string_flags & UTF8_FLAG) { @@ -863,8 +863,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { memcpy(manifest_end.ptrw(), &p_manifest[ofs], manifest_end.size()); int32_t attr_name_string = string_table.find("name"); - ERR_EXPLAIN("Template does not have 'name' attribute"); - ERR_FAIL_COND(attr_name_string == -1); + ERR_FAIL_COND_MSG(attr_name_string == -1, "Template does not have 'name' attribute."); int32_t ns_android_string = string_table.find("http://schemas.android.com/apk/res/android"); if (ns_android_string == -1) { @@ -896,8 +895,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { } else if (dof_index == 2) { required_value_string = "true"; } else { - ERR_EXPLAIN("Unknown dof index " + itos(dof_index)); - ERR_FAIL(); + ERR_FAIL_MSG("Unknown DoF index: " + itos(dof_index) + "."); } int32_t required_value = string_table.find(required_value_string); if (required_value == -1) { @@ -989,12 +987,10 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { memcpy(manifest_end.ptrw(), &p_manifest[ofs], manifest_end.size()); int32_t attr_name_string = string_table.find("name"); - ERR_EXPLAIN("Template does not have 'name' attribute"); - ERR_FAIL_COND(attr_name_string == -1); + ERR_FAIL_COND_MSG(attr_name_string == -1, "Template does not have 'name' attribute."); int32_t ns_android_string = string_table.find("android"); - ERR_EXPLAIN("Template does not have 'android' namespace"); - ERR_FAIL_COND(ns_android_string == -1); + ERR_FAIL_COND_MSG(ns_android_string == -1, "Template does not have 'android' namespace."); int32_t attr_uses_permission_string = string_table.find("uses-permission"); if (attr_uses_permission_string == -1) { @@ -1403,8 +1399,9 @@ public: return ERR_UNCONFIGURED; } - //export_temp + // Export_temp APK. if (ep.step("Exporting APK", 0)) { + device_lock->unlock(); return ERR_SKIP; } @@ -1414,11 +1411,20 @@ public: if (use_reverse) p_debug_flags |= DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST; - String export_to = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport.apk"); - Error err = export_project(p_preset, true, export_to, p_debug_flags); - if (err) { - device_lock->unlock(); - return err; + String tmp_export_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport.apk"); + +#define CLEANUP_AND_RETURN(m_err) \ + { \ + DirAccess::remove_file_or_error(tmp_export_path); \ + device_lock->unlock(); \ + return m_err; \ + } + + // Export to temporary APK before sending to device. + Error err = export_project(p_preset, true, tmp_export_path, p_debug_flags); + + if (err != OK) { + CLEANUP_AND_RETURN(err); } List<String> args; @@ -1430,7 +1436,7 @@ public: if (remove_prev) { if (ep.step("Uninstalling...", 1)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } print_line("Uninstalling previous version: " + devices[p_device].name); @@ -1445,7 +1451,7 @@ public: print_line("Installing to device (please wait...): " + devices[p_device].name); if (ep.step("Installing to device (please wait...)", 2)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } args.clear(); @@ -1453,13 +1459,12 @@ public: args.push_back(devices[p_device].id); args.push_back("install"); args.push_back("-r"); - args.push_back(export_to); + args.push_back(tmp_export_path); err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv); if (err || rv != 0) { EditorNode::add_io_error("Could not install to device."); - device_lock->unlock(); - return ERR_CANT_CREATE; + CLEANUP_AND_RETURN(ERR_CANT_CREATE); } if (use_remote) { @@ -1513,7 +1518,7 @@ public: } if (ep.step("Running on Device...", 3)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } args.clear(); args.push_back("-s"); @@ -1533,11 +1538,11 @@ public: err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv); if (err || rv != 0) { EditorNode::add_io_error("Could not execute on device."); - device_lock->unlock(); - return ERR_CANT_CREATE; + CLEANUP_AND_RETURN(ERR_CANT_CREATE); } - device_lock->unlock(); - return OK; + + CLEANUP_AND_RETURN(OK); +#undef CLEANUP_AND_RETURN } virtual Ref<Texture> get_run_icon() const { @@ -2028,8 +2033,16 @@ public: zlib_filefunc_def io2 = io; FileAccess *dst_f = NULL; io2.opaque = &dst_f; - String unaligned_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport-unaligned.apk"); - zipFile unaligned_apk = zipOpen2(unaligned_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2); + + String tmp_unaligned_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport-unaligned.apk"); + +#define CLEANUP_AND_RETURN(m_err) \ + { \ + DirAccess::remove_file_or_error(tmp_unaligned_path); \ + return m_err; \ + } + + zipFile unaligned_apk = zipOpen2(tmp_unaligned_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2); bool use_32_fb = p_preset->get("graphics/32_bits_framebuffer"); bool immersive = p_preset->get("screen/immersive_mode"); @@ -2157,7 +2170,7 @@ public: } if (ep.step("Adding Files...", 1)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } Error err = OK; Vector<String> cl = cmdline.strip_edges().split(" "); @@ -2189,7 +2202,7 @@ public: unzClose(pkg); EditorNode::add_io_error("Could not write expansion package file: " + apkfname); - return OK; + CLEANUP_AND_RETURN(ERR_SKIP); } cl.push_back("--use_apk_expansion"); @@ -2276,8 +2289,8 @@ public: zipClose(unaligned_apk, NULL); unzClose(pkg); - if (err) { - return err; + if (err != OK) { + CLEANUP_AND_RETURN(err); } if (_signed) { @@ -2285,7 +2298,7 @@ public: String jarsigner = EditorSettings::get_singleton()->get("export/android/jarsigner"); if (!FileAccess::exists(jarsigner)) { EditorNode::add_io_error("'jarsigner' could not be found.\nPlease supply a path in the Editor Settings.\nThe resulting APK is unsigned."); - return OK; + CLEANUP_AND_RETURN(OK); } String keystore; @@ -2305,7 +2318,7 @@ public: } if (ep.step("Signing debug APK...", 103)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } } else { @@ -2314,13 +2327,13 @@ public: user = release_username; if (ep.step("Signing release APK...", 103)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } } if (!FileAccess::exists(keystore)) { EditorNode::add_io_error("Could not find keystore, unable to export."); - return ERR_FILE_CANT_OPEN; + CLEANUP_AND_RETURN(ERR_FILE_CANT_OPEN); } List<String> args; @@ -2338,30 +2351,30 @@ public: args.push_back(keystore); args.push_back("-storepass"); args.push_back(password); - args.push_back(unaligned_path); + args.push_back(tmp_unaligned_path); args.push_back(user); int retval; OS::get_singleton()->execute(jarsigner, args, true, NULL, NULL, &retval); if (retval) { EditorNode::add_io_error("'jarsigner' returned with error #" + itos(retval)); - return ERR_CANT_CREATE; + CLEANUP_AND_RETURN(ERR_CANT_CREATE); } if (ep.step("Verifying APK...", 104)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } args.clear(); args.push_back("-verify"); args.push_back("-keystore"); args.push_back(keystore); - args.push_back(unaligned_path); + args.push_back(tmp_unaligned_path); args.push_back("-verbose"); OS::get_singleton()->execute(jarsigner, args, true, NULL, NULL, &retval); if (retval) { EditorNode::add_io_error("'jarsigner' verification of APK failed. Make sure to use a jarsigner from OpenJDK 8."); - return ERR_CANT_CREATE; + CLEANUP_AND_RETURN(ERR_CANT_CREATE); } } @@ -2370,14 +2383,14 @@ public: static const int ZIP_ALIGNMENT = 4; if (ep.step("Aligning APK...", 105)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } - unzFile tmp_unaligned = unzOpen2(unaligned_path.utf8().get_data(), &io); + unzFile tmp_unaligned = unzOpen2(tmp_unaligned_path.utf8().get_data(), &io); if (!tmp_unaligned) { - EditorNode::add_io_error("Could not find temp unaligned APK."); - return ERR_FILE_NOT_FOUND; + EditorNode::add_io_error("Could not unzip temporary unaligned APK."); + CLEANUP_AND_RETURN(ERR_FILE_NOT_FOUND); } ret = unzGoToFirstFile(tmp_unaligned); @@ -2447,7 +2460,7 @@ public: zipClose(final_apk, NULL); unzClose(tmp_unaligned); - return OK; + CLEANUP_AND_RETURN(OK); } virtual void get_platform_features(List<String> *r_features) { diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp index 77f077456e..1159e93166 100644 --- a/platform/android/java_godot_lib_jni.cpp +++ b/platform/android/java_godot_lib_jni.cpp @@ -686,20 +686,11 @@ static void _initialize_java_modules() { print_line("Loading Android module: " + m); jstring strClassName = env->NewStringUTF(m.utf8().get_data()); jclass singletonClass = (jclass)env->CallObjectMethod(cls, findClass, strClassName); - - if (!singletonClass) { - - ERR_EXPLAIN("Couldn't find singleton for class: " + m); - ERR_CONTINUE(!singletonClass); - } + ERR_CONTINUE_MSG(!singletonClass, "Couldn't find singleton for class: " + m + "."); jmethodID initialize = env->GetStaticMethodID(singletonClass, "initialize", "(Landroid/app/Activity;)Lorg/godotengine/godot/Godot$SingletonBase;"); + ERR_CONTINUE_MSG(!initialize, "Couldn't find proper initialize function 'public static Godot.SingletonBase Class::initialize(Activity p_activity)' initializer for singleton class: " + m + "."); - if (!initialize) { - - ERR_EXPLAIN("Couldn't find proper initialize function 'public static Godot.SingletonBase Class::initialize(Activity p_activity)' initializer for singleton class: " + m); - ERR_CONTINUE(!initialize); - } jobject obj = env->CallStaticObjectMethod(singletonClass, initialize, godot_java->get_activity()); env->NewGlobalRef(obj); } diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index ebc319e57d..701a351203 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -71,8 +71,7 @@ const char *OS_Android::get_video_driver_name(int p_driver) const { case VIDEO_DRIVER_GLES2: return "GLES2"; } - ERR_EXPLAIN("Invalid video driver index " + itos(p_driver)); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Invalid video driver index: " + itos(p_driver) + "."); } int OS_Android::get_audio_driver_count() const { @@ -223,10 +222,7 @@ bool OS_Android::request_permission(const String &p_name) { Error OS_Android::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) { p_library_handle = dlopen(p_path.utf8().get_data(), RTLD_NOW); - if (!p_library_handle) { - ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + dlerror()); - ERR_FAIL_V(ERR_CANT_OPEN); - } + ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + p_path + ", error: " + dlerror() + "."); return OK; } |