| 2318 | } |
| 2319 | |
| 2320 | Error EditorExportPlatformAndroid::run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) { |
| 2321 | ERR_FAIL_INDEX_V(p_device, devices.size(), ERR_INVALID_PARAMETER); |
| 2322 | |
| 2323 | String can_export_error; |
| 2324 | bool can_export_missing_templates; |
| 2325 | if (!can_export(p_preset, can_export_error, can_export_missing_templates)) { |
| 2326 | add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), can_export_error); |
| 2327 | return ERR_UNCONFIGURED; |
| 2328 | } |
| 2329 | |
| 2330 | MutexLock lock(device_lock); |
| 2331 | |
| 2332 | EditorProgress ep("run", vformat(TTR("Running on %s"), devices[p_device].name), 3); |
| 2333 | |
| 2334 | String adb = get_adb_path(); |
| 2335 | |
| 2336 | // Export_temp APK. |
| 2337 | if (ep.step(TTR("Exporting APK..."), 0)) { |
| 2338 | return ERR_SKIP; |
| 2339 | } |
| 2340 | |
| 2341 | const bool use_wifi_for_remote_debug = EDITOR_GET("export/android/use_wifi_for_remote_debug"); |
| 2342 | const bool use_remote = p_debug_flags.has_flag(DEBUG_FLAG_REMOTE_DEBUG) || p_debug_flags.has_flag(DEBUG_FLAG_DUMB_CLIENT); |
| 2343 | const bool use_reverse = devices[p_device].api_level >= 21 && !use_wifi_for_remote_debug; |
| 2344 | |
| 2345 | if (use_reverse) { |
| 2346 | p_debug_flags.set_flag(DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST); |
| 2347 | } |
| 2348 | |
| 2349 | String tmp_export_path = EditorPaths::get_singleton()->get_temp_dir().path_join("tmpexport." + uitos(OS::get_singleton()->get_unix_time()) + ".apk"); |
| 2350 | |
| 2351 | #define CLEANUP_AND_RETURN(m_err) \ |
| 2352 | { \ |
| 2353 | DirAccess::remove_file_or_error(tmp_export_path); \ |
| 2354 | if (FileAccess::exists(tmp_export_path + ".idsig")) { \ |
| 2355 | DirAccess::remove_file_or_error(tmp_export_path + ".idsig"); \ |
| 2356 | } \ |
| 2357 | return m_err; \ |
| 2358 | } \ |
| 2359 | ((void)0) |
| 2360 | |
| 2361 | // Export to temporary APK before sending to device. |
| 2362 | Error err = export_project_helper(p_preset, true, tmp_export_path, EXPORT_FORMAT_APK, true, p_debug_flags); |
| 2363 | |
| 2364 | if (err != OK) { |
| 2365 | CLEANUP_AND_RETURN(err); |
| 2366 | } |
| 2367 | |
| 2368 | List<String> args; |
| 2369 | int rv; |
| 2370 | String output; |
| 2371 | |
| 2372 | bool remove_prev = EDITOR_GET("export/android/one_click_deploy_clear_previous_install"); |
| 2373 | String version_name = p_preset->get_version("version/name"); |
| 2374 | String package_name = p_preset->get("package/unique_name"); |
| 2375 | |
| 2376 | if (remove_prev) { |
| 2377 | if (ep.step(TTR("Uninstalling..."), 1)) { |
no test coverage detected