2016-06-18 12:46:12 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* export.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:11:45 +00:00
|
|
|
/* https://godotengine.org */
|
2016-06-18 12:46:12 +00:00
|
|
|
/*************************************************************************/
|
2018-01-02 10:27:24 +00:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2016-06-18 12:46:12 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "export.h"
|
2017-03-18 22:45:45 +00:00
|
|
|
#include "editor/editor_import_export.h"
|
|
|
|
#include "editor/editor_node.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "editor/editor_settings.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "globals.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "io/marshalls.h"
|
|
|
|
#include "io/zip_io.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "os/file_access.h"
|
|
|
|
#include "os/os.h"
|
2017-06-25 12:26:24 +00:00
|
|
|
#include "platform/android/logo.gen.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "version.h"
|
2016-06-12 22:19:45 +00:00
|
|
|
#include <string.h>
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
static const char *android_perms[] = {
|
|
|
|
"ACCESS_CHECKIN_PROPERTIES",
|
|
|
|
"ACCESS_COARSE_LOCATION",
|
|
|
|
"ACCESS_FINE_LOCATION",
|
|
|
|
"ACCESS_LOCATION_EXTRA_COMMANDS",
|
|
|
|
"ACCESS_MOCK_LOCATION",
|
|
|
|
"ACCESS_NETWORK_STATE",
|
|
|
|
"ACCESS_SURFACE_FLINGER",
|
|
|
|
"ACCESS_WIFI_STATE",
|
|
|
|
"ACCOUNT_MANAGER",
|
|
|
|
"ADD_VOICEMAIL",
|
|
|
|
"AUTHENTICATE_ACCOUNTS",
|
|
|
|
"BATTERY_STATS",
|
|
|
|
"BIND_ACCESSIBILITY_SERVICE",
|
|
|
|
"BIND_APPWIDGET",
|
|
|
|
"BIND_DEVICE_ADMIN",
|
|
|
|
"BIND_INPUT_METHOD",
|
|
|
|
"BIND_NFC_SERVICE",
|
|
|
|
"BIND_NOTIFICATION_LISTENER_SERVICE",
|
|
|
|
"BIND_PRINT_SERVICE",
|
|
|
|
"BIND_REMOTEVIEWS",
|
|
|
|
"BIND_TEXT_SERVICE",
|
|
|
|
"BIND_VPN_SERVICE",
|
|
|
|
"BIND_WALLPAPER",
|
|
|
|
"BLUETOOTH",
|
|
|
|
"BLUETOOTH_ADMIN",
|
|
|
|
"BLUETOOTH_PRIVILEGED",
|
|
|
|
"BRICK",
|
|
|
|
"BROADCAST_PACKAGE_REMOVED",
|
|
|
|
"BROADCAST_SMS",
|
|
|
|
"BROADCAST_STICKY",
|
|
|
|
"BROADCAST_WAP_PUSH",
|
|
|
|
"CALL_PHONE",
|
|
|
|
"CALL_PRIVILEGED",
|
|
|
|
"CAMERA",
|
|
|
|
"CAPTURE_AUDIO_OUTPUT",
|
|
|
|
"CAPTURE_SECURE_VIDEO_OUTPUT",
|
|
|
|
"CAPTURE_VIDEO_OUTPUT",
|
|
|
|
"CHANGE_COMPONENT_ENABLED_STATE",
|
|
|
|
"CHANGE_CONFIGURATION",
|
|
|
|
"CHANGE_NETWORK_STATE",
|
|
|
|
"CHANGE_WIFI_MULTICAST_STATE",
|
|
|
|
"CHANGE_WIFI_STATE",
|
|
|
|
"CLEAR_APP_CACHE",
|
|
|
|
"CLEAR_APP_USER_DATA",
|
|
|
|
"CONTROL_LOCATION_UPDATES",
|
|
|
|
"DELETE_CACHE_FILES",
|
|
|
|
"DELETE_PACKAGES",
|
|
|
|
"DEVICE_POWER",
|
|
|
|
"DIAGNOSTIC",
|
|
|
|
"DISABLE_KEYGUARD",
|
|
|
|
"DUMP",
|
|
|
|
"EXPAND_STATUS_BAR",
|
|
|
|
"FACTORY_TEST",
|
|
|
|
"FLASHLIGHT",
|
|
|
|
"FORCE_BACK",
|
|
|
|
"GET_ACCOUNTS",
|
|
|
|
"GET_PACKAGE_SIZE",
|
|
|
|
"GET_TASKS",
|
|
|
|
"GET_TOP_ACTIVITY_INFO",
|
|
|
|
"GLOBAL_SEARCH",
|
|
|
|
"HARDWARE_TEST",
|
|
|
|
"INJECT_EVENTS",
|
|
|
|
"INSTALL_LOCATION_PROVIDER",
|
|
|
|
"INSTALL_PACKAGES",
|
|
|
|
"INSTALL_SHORTCUT",
|
|
|
|
"INTERNAL_SYSTEM_WINDOW",
|
|
|
|
"INTERNET",
|
|
|
|
"KILL_BACKGROUND_PROCESSES",
|
|
|
|
"LOCATION_HARDWARE",
|
|
|
|
"MANAGE_ACCOUNTS",
|
|
|
|
"MANAGE_APP_TOKENS",
|
|
|
|
"MANAGE_DOCUMENTS",
|
|
|
|
"MASTER_CLEAR",
|
|
|
|
"MEDIA_CONTENT_CONTROL",
|
|
|
|
"MODIFY_AUDIO_SETTINGS",
|
|
|
|
"MODIFY_PHONE_STATE",
|
|
|
|
"MOUNT_FORMAT_FILESYSTEMS",
|
|
|
|
"MOUNT_UNMOUNT_FILESYSTEMS",
|
|
|
|
"NFC",
|
|
|
|
"PERSISTENT_ACTIVITY",
|
|
|
|
"PROCESS_OUTGOING_CALLS",
|
|
|
|
"READ_CALENDAR",
|
|
|
|
"READ_CALL_LOG",
|
|
|
|
"READ_CONTACTS",
|
|
|
|
"READ_EXTERNAL_STORAGE",
|
|
|
|
"READ_FRAME_BUFFER",
|
|
|
|
"READ_HISTORY_BOOKMARKS",
|
|
|
|
"READ_INPUT_STATE",
|
|
|
|
"READ_LOGS",
|
|
|
|
"READ_PHONE_STATE",
|
|
|
|
"READ_PROFILE",
|
|
|
|
"READ_SMS",
|
|
|
|
"READ_SOCIAL_STREAM",
|
|
|
|
"READ_SYNC_SETTINGS",
|
|
|
|
"READ_SYNC_STATS",
|
|
|
|
"READ_USER_DICTIONARY",
|
|
|
|
"REBOOT",
|
|
|
|
"RECEIVE_BOOT_COMPLETED",
|
|
|
|
"RECEIVE_MMS",
|
|
|
|
"RECEIVE_SMS",
|
|
|
|
"RECEIVE_WAP_PUSH",
|
|
|
|
"RECORD_AUDIO",
|
|
|
|
"REORDER_TASKS",
|
|
|
|
"RESTART_PACKAGES",
|
|
|
|
"SEND_RESPOND_VIA_MESSAGE",
|
|
|
|
"SEND_SMS",
|
|
|
|
"SET_ACTIVITY_WATCHER",
|
|
|
|
"SET_ALARM",
|
|
|
|
"SET_ALWAYS_FINISH",
|
|
|
|
"SET_ANIMATION_SCALE",
|
|
|
|
"SET_DEBUG_APP",
|
|
|
|
"SET_ORIENTATION",
|
|
|
|
"SET_POINTER_SPEED",
|
|
|
|
"SET_PREFERRED_APPLICATIONS",
|
|
|
|
"SET_PROCESS_LIMIT",
|
|
|
|
"SET_TIME",
|
|
|
|
"SET_TIME_ZONE",
|
|
|
|
"SET_WALLPAPER",
|
|
|
|
"SET_WALLPAPER_HINTS",
|
|
|
|
"SIGNAL_PERSISTENT_PROCESSES",
|
|
|
|
"STATUS_BAR",
|
|
|
|
"SUBSCRIBED_FEEDS_READ",
|
|
|
|
"SUBSCRIBED_FEEDS_WRITE",
|
|
|
|
"SYSTEM_ALERT_WINDOW",
|
|
|
|
"TRANSMIT_IR",
|
|
|
|
"UNINSTALL_SHORTCUT",
|
|
|
|
"UPDATE_DEVICE_STATS",
|
|
|
|
"USE_CREDENTIALS",
|
|
|
|
"USE_SIP",
|
|
|
|
"VIBRATE",
|
|
|
|
"WAKE_LOCK",
|
|
|
|
"WRITE_APN_SETTINGS",
|
|
|
|
"WRITE_CALENDAR",
|
|
|
|
"WRITE_CALL_LOG",
|
|
|
|
"WRITE_CONTACTS",
|
|
|
|
"WRITE_EXTERNAL_STORAGE",
|
|
|
|
"WRITE_GSERVICES",
|
|
|
|
"WRITE_HISTORY_BOOKMARKS",
|
|
|
|
"WRITE_PROFILE",
|
|
|
|
"WRITE_SECURE_SETTINGS",
|
|
|
|
"WRITE_SETTINGS",
|
|
|
|
"WRITE_SMS",
|
|
|
|
"WRITE_SOCIAL_STREAM",
|
|
|
|
"WRITE_SYNC_SETTINGS",
|
|
|
|
"WRITE_USER_DICTIONARY",
|
|
|
|
NULL
|
|
|
|
};
|
2014-04-15 01:43:44 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
class EditorExportPlatformAndroid : public EditorExportPlatform {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
OBJ_TYPE(EditorExportPlatformAndroid, EditorExportPlatform);
|
2014-04-15 01:43:44 +00:00
|
|
|
|
|
|
|
enum {
|
2017-03-18 23:36:26 +00:00
|
|
|
MAX_USER_PERMISSIONS = 20,
|
|
|
|
SCREEN_SMALL = 0,
|
|
|
|
SCREEN_NORMAL = 1,
|
|
|
|
SCREEN_LARGE = 2,
|
|
|
|
SCREEN_XLARGE = 3,
|
|
|
|
SCREEN_MAX = 4
|
2014-04-15 01:43:44 +00:00
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String custom_release_package;
|
|
|
|
String custom_debug_package;
|
|
|
|
|
|
|
|
int version_code;
|
|
|
|
String version_name;
|
|
|
|
String package;
|
|
|
|
String name;
|
|
|
|
String icon;
|
2014-04-29 00:56:43 +00:00
|
|
|
String cmdline;
|
2014-02-10 01:10:30 +00:00
|
|
|
bool _signed;
|
2014-04-29 00:56:43 +00:00
|
|
|
bool apk_expansion;
|
2014-10-28 01:54:32 +00:00
|
|
|
bool remove_prev;
|
2015-03-31 22:02:40 +00:00
|
|
|
bool use_32_fb;
|
2015-04-17 19:18:46 +00:00
|
|
|
bool immersive;
|
2015-05-02 01:45:32 +00:00
|
|
|
bool export_arm;
|
2017-07-25 10:28:31 +00:00
|
|
|
bool export_arm64;
|
2015-05-02 01:45:32 +00:00
|
|
|
bool export_x86;
|
2014-04-29 00:56:43 +00:00
|
|
|
String apk_expansion_salt;
|
|
|
|
String apk_expansion_pkey;
|
2014-02-10 01:10:30 +00:00
|
|
|
int orientation;
|
|
|
|
|
|
|
|
String release_keystore;
|
2014-05-29 13:56:39 +00:00
|
|
|
String release_password;
|
2014-02-10 01:10:30 +00:00
|
|
|
String release_username;
|
|
|
|
|
|
|
|
struct APKExportData {
|
|
|
|
|
|
|
|
zipFile apk;
|
|
|
|
EditorProgress *ep;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Device {
|
|
|
|
|
|
|
|
String id;
|
|
|
|
String name;
|
|
|
|
String description;
|
2017-08-30 18:11:05 +00:00
|
|
|
int api_level;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Device> devices;
|
|
|
|
bool devices_changed;
|
|
|
|
Mutex *device_lock;
|
|
|
|
Thread *device_thread;
|
|
|
|
Ref<ImageTexture> logo;
|
|
|
|
|
2014-04-15 01:43:44 +00:00
|
|
|
Set<String> perms;
|
|
|
|
String user_perms[MAX_USER_PERMISSIONS];
|
|
|
|
bool screen_support[SCREEN_MAX];
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
volatile bool quit_request;
|
|
|
|
|
|
|
|
static void _device_poll_thread(void *ud);
|
|
|
|
|
2015-05-02 02:21:27 +00:00
|
|
|
String get_package_name();
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String get_project_name() const;
|
2017-03-18 23:36:26 +00:00
|
|
|
void _fix_manifest(Vector<uint8_t> &p_manifest, bool p_give_internet);
|
|
|
|
void _fix_resources(Vector<uint8_t> &p_manifest);
|
|
|
|
static Error save_apk_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total);
|
|
|
|
static bool _should_compress_asset(const String &p_path, const Vector<uint8_t> &p_data);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
protected:
|
2017-03-18 23:36:26 +00:00
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual String get_name() const { return "Android"; }
|
|
|
|
virtual ImageCompression get_image_compression() const { return IMAGE_COMPRESSION_ETC1; }
|
|
|
|
virtual Ref<Texture> get_logo() const { return logo; }
|
|
|
|
|
|
|
|
virtual bool poll_devices();
|
|
|
|
virtual int get_device_count() const;
|
|
|
|
virtual String get_device_name(int p_device) const;
|
|
|
|
virtual String get_device_info(int p_device) const;
|
2017-03-18 23:36:26 +00:00
|
|
|
virtual Error run(int p_device, int p_flags = 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-04-28 00:39:52 +00:00
|
|
|
virtual bool requires_password(bool p_debug) const { return !p_debug; }
|
2014-02-10 01:10:30 +00:00
|
|
|
virtual String get_binary_extension() const { return "apk"; }
|
2017-03-18 23:36:26 +00:00
|
|
|
virtual Error export_project(const String &p_path, bool p_debug, int p_flags = 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
virtual bool can_export(String *r_error = NULL) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
EditorExportPlatformAndroid();
|
|
|
|
~EditorExportPlatformAndroid();
|
|
|
|
};
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool EditorExportPlatformAndroid::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
|
|
|
|
|
String n = p_name;
|
|
|
|
|
|
|
|
if (n == "one_click_deploy/clear_previous_install")
|
|
|
|
remove_prev = p_value;
|
|
|
|
else if (n == "custom_package/debug")
|
|
|
|
custom_debug_package = p_value;
|
|
|
|
else if (n == "custom_package/release")
|
|
|
|
custom_release_package = p_value;
|
|
|
|
else if (n == "version/code")
|
|
|
|
version_code = p_value;
|
|
|
|
else if (n == "version/name")
|
|
|
|
version_name = p_value;
|
|
|
|
else if (n == "command_line/extra_args")
|
|
|
|
cmdline = p_value;
|
|
|
|
else if (n == "package/unique_name")
|
|
|
|
package = p_value;
|
|
|
|
else if (n == "package/name")
|
|
|
|
name = p_value;
|
|
|
|
else if (n == "package/icon")
|
|
|
|
icon = p_value;
|
|
|
|
else if (n == "package/signed")
|
|
|
|
_signed = p_value;
|
|
|
|
else if (n == "architecture/arm")
|
|
|
|
export_arm = p_value;
|
2017-07-25 10:28:31 +00:00
|
|
|
else if (n == "architecture/arm64")
|
|
|
|
export_arm64 = p_value;
|
2017-03-18 23:36:26 +00:00
|
|
|
else if (n == "architecture/x86")
|
|
|
|
export_x86 = p_value;
|
|
|
|
else if (n == "screen/use_32_bits_view")
|
|
|
|
use_32_fb = p_value;
|
|
|
|
else if (n == "screen/immersive_mode")
|
|
|
|
immersive = p_value;
|
|
|
|
else if (n == "screen/orientation")
|
|
|
|
orientation = p_value;
|
|
|
|
else if (n == "screen/support_small")
|
|
|
|
screen_support[SCREEN_SMALL] = p_value;
|
|
|
|
else if (n == "screen/support_normal")
|
|
|
|
screen_support[SCREEN_NORMAL] = p_value;
|
|
|
|
else if (n == "screen/support_large")
|
|
|
|
screen_support[SCREEN_LARGE] = p_value;
|
|
|
|
else if (n == "screen/support_xlarge")
|
|
|
|
screen_support[SCREEN_XLARGE] = p_value;
|
|
|
|
else if (n == "keystore/release")
|
|
|
|
release_keystore = p_value;
|
|
|
|
else if (n == "keystore/release_user")
|
|
|
|
release_username = p_value;
|
|
|
|
else if (n == "keystore/release_password")
|
|
|
|
release_password = p_value;
|
|
|
|
else if (n == "apk_expansion/enable")
|
|
|
|
apk_expansion = p_value;
|
|
|
|
else if (n == "apk_expansion/SALT")
|
|
|
|
apk_expansion_salt = p_value;
|
|
|
|
else if (n == "apk_expansion/public_key")
|
|
|
|
apk_expansion_pkey = p_value;
|
2014-04-15 01:43:44 +00:00
|
|
|
else if (n.begins_with("permissions/")) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String what = n.get_slicec('/', 1).to_upper();
|
2014-04-15 01:43:44 +00:00
|
|
|
bool state = p_value;
|
|
|
|
if (state)
|
|
|
|
perms.insert(what);
|
|
|
|
else
|
|
|
|
perms.erase(what);
|
|
|
|
} else if (n.begins_with("user_permissions/")) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int which = n.get_slicec('/', 1).to_int();
|
|
|
|
ERR_FAIL_INDEX_V(which, MAX_USER_PERMISSIONS, false);
|
|
|
|
user_perms[which] = p_value;
|
2014-04-15 01:43:44 +00:00
|
|
|
|
|
|
|
} else
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool EditorExportPlatformAndroid::_get(const StringName &p_name, Variant &r_ret) const {
|
|
|
|
|
|
|
|
String n = p_name;
|
|
|
|
if (n == "one_click_deploy/clear_previous_install")
|
|
|
|
r_ret = remove_prev;
|
|
|
|
else if (n == "custom_package/debug")
|
|
|
|
r_ret = custom_debug_package;
|
|
|
|
else if (n == "custom_package/release")
|
|
|
|
r_ret = custom_release_package;
|
|
|
|
else if (n == "version/code")
|
|
|
|
r_ret = version_code;
|
|
|
|
else if (n == "version/name")
|
|
|
|
r_ret = version_name;
|
|
|
|
else if (n == "command_line/extra_args")
|
|
|
|
r_ret = cmdline;
|
|
|
|
else if (n == "package/unique_name")
|
|
|
|
r_ret = package;
|
|
|
|
else if (n == "package/name")
|
|
|
|
r_ret = name;
|
|
|
|
else if (n == "package/icon")
|
|
|
|
r_ret = icon;
|
|
|
|
else if (n == "package/signed")
|
|
|
|
r_ret = _signed;
|
|
|
|
else if (n == "architecture/arm")
|
|
|
|
r_ret = export_arm;
|
2017-07-25 10:28:31 +00:00
|
|
|
else if (n == "architecture/arm64")
|
|
|
|
r_ret = export_arm64;
|
2017-03-18 23:36:26 +00:00
|
|
|
else if (n == "architecture/x86")
|
|
|
|
r_ret = export_x86;
|
|
|
|
else if (n == "screen/use_32_bits_view")
|
|
|
|
r_ret = use_32_fb;
|
|
|
|
else if (n == "screen/immersive_mode")
|
|
|
|
r_ret = immersive;
|
|
|
|
else if (n == "screen/orientation")
|
|
|
|
r_ret = orientation;
|
|
|
|
else if (n == "screen/support_small")
|
|
|
|
r_ret = screen_support[SCREEN_SMALL];
|
|
|
|
else if (n == "screen/support_normal")
|
|
|
|
r_ret = screen_support[SCREEN_NORMAL];
|
|
|
|
else if (n == "screen/support_large")
|
|
|
|
r_ret = screen_support[SCREEN_LARGE];
|
|
|
|
else if (n == "screen/support_xlarge")
|
|
|
|
r_ret = screen_support[SCREEN_XLARGE];
|
|
|
|
else if (n == "keystore/release")
|
|
|
|
r_ret = release_keystore;
|
|
|
|
else if (n == "keystore/release_user")
|
|
|
|
r_ret = release_username;
|
|
|
|
else if (n == "keystore/release_password")
|
|
|
|
r_ret = release_password;
|
|
|
|
else if (n == "apk_expansion/enable")
|
|
|
|
r_ret = apk_expansion;
|
|
|
|
else if (n == "apk_expansion/SALT")
|
|
|
|
r_ret = apk_expansion_salt;
|
|
|
|
else if (n == "apk_expansion/public_key")
|
|
|
|
r_ret = apk_expansion_pkey;
|
2014-04-15 01:43:44 +00:00
|
|
|
else if (n.begins_with("permissions/")) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String what = n.get_slicec('/', 1).to_upper();
|
2014-04-15 01:43:44 +00:00
|
|
|
r_ret = perms.has(what);
|
|
|
|
} else if (n.begins_with("user_permissions/")) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int which = n.get_slicec('/', 1).to_int();
|
|
|
|
ERR_FAIL_INDEX_V(which, MAX_USER_PERMISSIONS, false);
|
|
|
|
r_ret = user_perms[which];
|
2014-04-15 01:43:44 +00:00
|
|
|
} else
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-04-15 01:43:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void EditorExportPlatformAndroid::_get_property_list(List<PropertyInfo> *p_list) const {
|
|
|
|
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "one_click_deploy/clear_previous_install"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "apk"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE, "apk"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "command_line/extra_args"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "version/code", PROPERTY_HINT_RANGE, "1,65535,1"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "version/name"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "package/unique_name"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "package/name"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "package/icon", PROPERTY_HINT_FILE, "png"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "package/signed"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "architecture/arm"));
|
2017-07-25 10:28:31 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "architecture/arm64"));
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "architecture/x86"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "screen/use_32_bits_view"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "screen/immersive_mode"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "screen/orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "screen/support_small"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "screen/support_normal"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "screen/support_large"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "screen/support_xlarge"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "keystore/release", PROPERTY_HINT_GLOBAL_FILE, "keystore"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "keystore/release_user"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "keystore/release_password"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "apk_expansion/enable"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "apk_expansion/SALT"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "apk_expansion/public_key", PROPERTY_HINT_MULTILINE_TEXT));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-04-15 01:43:44 +00:00
|
|
|
const char **perms = android_perms;
|
2017-03-18 23:36:26 +00:00
|
|
|
while (*perms) {
|
2014-04-15 01:43:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "permissions/" + String(*perms).to_lower()));
|
2014-04-15 01:43:44 +00:00
|
|
|
perms++;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < MAX_USER_PERMISSIONS; i++) {
|
2014-04-15 01:43:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "user_permissions/" + itos(i)));
|
2014-04-15 01:43:44 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
//p_list->push_back( PropertyInfo( Variant::INT, "resources/pack_mode", PROPERTY_HINT_ENUM,"Copy,Single Exec.,Pack (.pck),Bundles (Optical)"));
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
static String _parse_string(const uint8_t *p_bytes, bool p_utf8) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t offset = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
uint32_t len = decode_uint16(&p_bytes[offset]);
|
|
|
|
|
|
|
|
if (p_utf8) {
|
|
|
|
//don't know how to read extended utf8, this will have to be for now
|
2017-03-18 23:36:26 +00:00
|
|
|
len >>= 8;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
offset += 2;
|
2014-08-02 01:10:38 +00:00
|
|
|
//printf("len %i, unicode: %i\n",len,int(p_utf8));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (p_utf8) {
|
|
|
|
|
|
|
|
Vector<uint8_t> str8;
|
2017-03-18 23:36:26 +00:00
|
|
|
str8.resize(len + 1);
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
str8[i] = p_bytes[offset + i];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
str8[len] = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
String str;
|
2017-03-18 23:36:26 +00:00
|
|
|
str.parse_utf8((const char *)str8.ptr());
|
2014-02-10 01:10:30 +00:00
|
|
|
return str;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String str;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
CharType c = decode_uint16(&p_bytes[offset + i * 2]);
|
|
|
|
if (c == 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
str += String::chr(c);
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void EditorExportPlatformAndroid::_fix_resources(Vector<uint8_t> &p_manifest) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
const int UTF8_FLAG = 0x00000100;
|
|
|
|
print_line("*******************GORRRGLE***********************");
|
|
|
|
|
|
|
|
uint32_t header = decode_uint32(&p_manifest[0]);
|
|
|
|
uint32_t filesize = decode_uint32(&p_manifest[4]);
|
|
|
|
uint32_t string_block_len = decode_uint32(&p_manifest[16]);
|
|
|
|
uint32_t string_count = decode_uint32(&p_manifest[20]);
|
|
|
|
uint32_t string_flags = decode_uint32(&p_manifest[28]);
|
|
|
|
const uint32_t string_table_begins = 40;
|
|
|
|
|
|
|
|
Vector<String> string_table;
|
|
|
|
|
2016-11-08 19:49:10 +00:00
|
|
|
//printf("stirng block len: %i\n",string_block_len);
|
|
|
|
//printf("stirng count: %i\n",string_count);
|
|
|
|
//printf("flags: %x\n",string_flags);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < string_count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t offset = decode_uint32(&p_manifest[string_table_begins + i * 4]);
|
|
|
|
offset += string_table_begins + string_count * 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String str = _parse_string(&p_manifest[offset], string_flags & UTF8_FLAG);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (str.begins_with("godot-project-name")) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "godot-project-name") {
|
2014-02-10 01:10:30 +00:00
|
|
|
//project name
|
|
|
|
str = get_project_name();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String lang = str.substr(str.find_last("-") + 1, str.length()).replace("-", "_");
|
|
|
|
String prop = "application/name_" + lang;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (Globals::get_singleton()->has(prop)) {
|
|
|
|
str = Globals::get_singleton()->get(prop);
|
|
|
|
} else {
|
|
|
|
str = get_project_name();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string_table.push_back(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
//write a new string table, but use 16 bits
|
|
|
|
Vector<uint8_t> ret;
|
2017-03-18 23:36:26 +00:00
|
|
|
ret.resize(string_table_begins + string_table.size() * 4);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < string_table_begins; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ret[i] = p_manifest[i];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int ofs = 0;
|
|
|
|
for (int i = 0; i < string_table.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(ofs, &ret[string_table_begins + i * 4]);
|
|
|
|
ofs += string_table[i].length() * 2 + 2 + 2;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ret.resize(ret.size() + ofs);
|
|
|
|
uint8_t *chars = &ret[ret.size() - ofs];
|
|
|
|
for (int i = 0; i < string_table.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String s = string_table[i];
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint16(s.length(), chars);
|
|
|
|
chars += 2;
|
|
|
|
for (int j = 0; j < s.length(); j++) {
|
|
|
|
encode_uint16(s[j], chars);
|
|
|
|
chars += 2;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint16(0, chars);
|
|
|
|
chars += 2;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//pad
|
2017-03-18 23:36:26 +00:00
|
|
|
while (ret.size() % 4)
|
2014-02-10 01:10:30 +00:00
|
|
|
ret.push_back(0);
|
|
|
|
|
|
|
|
//change flags to not use utf8
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(string_flags & ~0x100, &ret[28]);
|
2014-02-10 01:10:30 +00:00
|
|
|
//change length
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(ret.size() - 12, &ret[16]);
|
2014-02-10 01:10:30 +00:00
|
|
|
//append the rest...
|
2017-03-18 23:36:26 +00:00
|
|
|
int rest_from = 12 + string_block_len;
|
2014-02-10 01:10:30 +00:00
|
|
|
int rest_to = ret.size();
|
|
|
|
int rest_len = (p_manifest.size() - rest_from);
|
2017-03-18 23:36:26 +00:00
|
|
|
ret.resize(ret.size() + (p_manifest.size() - rest_from));
|
|
|
|
for (int i = 0; i < rest_len; i++) {
|
|
|
|
ret[rest_to + i] = p_manifest[rest_from + i];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
//finally update the size
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(ret.size(), &ret[4]);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_manifest = ret;
|
2016-11-08 19:49:10 +00:00
|
|
|
//printf("end\n");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String EditorExportPlatformAndroid::get_project_name() const {
|
|
|
|
|
|
|
|
String aname;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (this->name != "") {
|
|
|
|
aname = this->name;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
aname = Globals::get_singleton()->get("application/name");
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (aname == "") {
|
|
|
|
aname = _MKSTR(VERSION_NAME);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return aname;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void EditorExportPlatformAndroid::_fix_manifest(Vector<uint8_t> &p_manifest, bool p_give_internet) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
const int CHUNK_AXML_FILE = 0x00080003;
|
|
|
|
const int CHUNK_RESOURCEIDS = 0x00080180;
|
|
|
|
const int CHUNK_STRINGS = 0x001C0001;
|
|
|
|
const int CHUNK_XML_END_NAMESPACE = 0x00100101;
|
|
|
|
const int CHUNK_XML_END_TAG = 0x00100103;
|
|
|
|
const int CHUNK_XML_START_NAMESPACE = 0x00100100;
|
|
|
|
const int CHUNK_XML_START_TAG = 0x00100102;
|
|
|
|
const int CHUNK_XML_TEXT = 0x00100104;
|
|
|
|
const int UTF8_FLAG = 0x00000100;
|
|
|
|
|
|
|
|
Vector<String> string_table;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t ofs = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
uint32_t header = decode_uint32(&p_manifest[ofs]);
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t filesize = decode_uint32(&p_manifest[ofs + 4]);
|
|
|
|
ofs += 8;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
// print_line("FILESIZE: "+itos(filesize)+" ACTUAL: "+itos(p_manifest.size()));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
uint32_t string_count;
|
|
|
|
uint32_t styles_count;
|
|
|
|
uint32_t string_flags;
|
|
|
|
uint32_t string_data_offset;
|
|
|
|
|
|
|
|
uint32_t styles_offset;
|
|
|
|
uint32_t string_table_begins;
|
|
|
|
uint32_t string_table_ends;
|
|
|
|
Vector<uint8_t> stable_extra;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (ofs < p_manifest.size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
uint32_t chunk = decode_uint32(&p_manifest[ofs]);
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t size = decode_uint32(&p_manifest[ofs + 4]);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (chunk) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case CHUNK_STRINGS: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int iofs = ofs + 8;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
string_count = decode_uint32(&p_manifest[iofs]);
|
|
|
|
styles_count = decode_uint32(&p_manifest[iofs + 4]);
|
|
|
|
uint32_t string_flags = decode_uint32(&p_manifest[iofs + 8]);
|
|
|
|
string_data_offset = decode_uint32(&p_manifest[iofs + 12]);
|
|
|
|
styles_offset = decode_uint32(&p_manifest[iofs + 16]);
|
|
|
|
/*
|
2014-02-10 01:10:30 +00:00
|
|
|
printf("string count: %i\n",string_count);
|
|
|
|
printf("flags: %i\n",string_flags);
|
|
|
|
printf("sdata ofs: %i\n",string_data_offset);
|
|
|
|
printf("styles ofs: %i\n",styles_offset);
|
|
|
|
*/
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t st_offset = iofs + 20;
|
2014-02-10 01:10:30 +00:00
|
|
|
string_table.resize(string_count);
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t string_end = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
string_table_begins = st_offset;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < string_count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t string_at = decode_uint32(&p_manifest[st_offset + i * 4]);
|
|
|
|
string_at += st_offset + string_count * 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_EXPLAIN("Unimplemented, can't read utf8 string table.");
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND(string_flags & UTF8_FLAG);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (string_flags & UTF8_FLAG) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
uint32_t len = decode_uint16(&p_manifest[string_at]);
|
|
|
|
Vector<CharType> ucstring;
|
2017-03-18 23:36:26 +00:00
|
|
|
ucstring.resize(len + 1);
|
|
|
|
for (int j = 0; j < len; j++) {
|
|
|
|
uint16_t c = decode_uint16(&p_manifest[string_at + 2 + 2 * j]);
|
|
|
|
ucstring[j] = c;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
string_end = MAX(string_at + 2 + 2 * len, string_end);
|
|
|
|
ucstring[len] = 0;
|
|
|
|
string_table[i] = ucstring.ptr();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
// print_line("String "+itos(i)+": "+string_table[i]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = string_end; i < (ofs + size); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
stable_extra.push_back(p_manifest[i]);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
// printf("stable extra: %i\n",int(stable_extra.size()));
|
|
|
|
string_table_ends = ofs + size;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
// print_line("STABLE SIZE: "+itos(size)+" ACTUAL: "+itos(string_table_ends));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case CHUNK_XML_START_TAG: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int iofs = ofs + 8;
|
|
|
|
uint32_t line = decode_uint32(&p_manifest[iofs]);
|
|
|
|
uint32_t nspace = decode_uint32(&p_manifest[iofs + 8]);
|
|
|
|
uint32_t name = decode_uint32(&p_manifest[iofs + 12]);
|
|
|
|
uint32_t check = decode_uint32(&p_manifest[iofs + 16]);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String tname = string_table[name];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
// printf("NSPACE: %i\n",nspace);
|
2014-02-10 01:10:30 +00:00
|
|
|
//printf("NAME: %i (%s)\n",name,tname.utf8().get_data());
|
|
|
|
//printf("CHECK: %x\n",check);
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t attrcount = decode_uint32(&p_manifest[iofs + 20]);
|
|
|
|
iofs += 28;
|
2014-02-10 01:10:30 +00:00
|
|
|
//printf("ATTRCOUNT: %x\n",attrcount);
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < attrcount; i++) {
|
|
|
|
uint32_t attr_nspace = decode_uint32(&p_manifest[iofs]);
|
|
|
|
uint32_t attr_name = decode_uint32(&p_manifest[iofs + 4]);
|
|
|
|
uint32_t attr_value = decode_uint32(&p_manifest[iofs + 8]);
|
|
|
|
uint32_t attr_flags = decode_uint32(&p_manifest[iofs + 12]);
|
|
|
|
uint32_t attr_resid = decode_uint32(&p_manifest[iofs + 16]);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String value;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (attr_value != 0xFFFFFFFF)
|
|
|
|
value = string_table[attr_value];
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2017-03-18 23:36:26 +00:00
|
|
|
value = "Res #" + itos(attr_resid);
|
2014-02-10 01:10:30 +00:00
|
|
|
String attrname = string_table[attr_name];
|
|
|
|
String nspace;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (attr_nspace != 0xFFFFFFFF)
|
|
|
|
nspace = string_table[attr_nspace];
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2017-03-18 23:36:26 +00:00
|
|
|
nspace = "";
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-11-08 19:49:10 +00:00
|
|
|
//printf("ATTR %i NSPACE: %i\n",i,attr_nspace);
|
|
|
|
//printf("ATTR %i NAME: %i (%s)\n",i,attr_name,attrname.utf8().get_data());
|
|
|
|
//printf("ATTR %i VALUE: %i (%s)\n",i,attr_value,value.utf8().get_data());
|
|
|
|
//printf("ATTR %i FLAGS: %x\n",i,attr_flags);
|
|
|
|
//printf("ATTR %i RESID: %x\n",i,attr_resid);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//replace project information
|
2017-03-18 23:36:26 +00:00
|
|
|
if (tname == "manifest" && attrname == "package") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-11-08 19:49:10 +00:00
|
|
|
print_line("FOUND package");
|
2017-03-18 23:36:26 +00:00
|
|
|
string_table[attr_value] = get_package_name();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//print_line("tname: "+tname);
|
|
|
|
//print_line("nspace: "+nspace);
|
|
|
|
//print_line("attrname: "+attrname);
|
2017-03-18 23:36:26 +00:00
|
|
|
if (tname == "manifest" && /*nspace=="android" &&*/ attrname == "versionCode") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-11-08 19:49:10 +00:00
|
|
|
print_line("FOUND versionCode");
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(version_code, &p_manifest[iofs + 16]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (tname == "manifest" && /*nspace=="android" &&*/ attrname == "versionName") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-11-08 19:49:10 +00:00
|
|
|
print_line("FOUND versionName");
|
2017-03-18 23:36:26 +00:00
|
|
|
if (attr_value == 0xFFFFFFFF) {
|
2014-02-10 01:10:30 +00:00
|
|
|
WARN_PRINT("Version name in a resource, should be plaintext")
|
|
|
|
} else
|
2017-03-18 23:36:26 +00:00
|
|
|
string_table[attr_value] = version_name;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (tname == "activity" && /*nspace=="android" &&*/ attrname == "screenOrientation") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(orientation == 0 ? 0 : 1, &p_manifest[iofs + 16]);
|
2015-05-02 00:13:20 +00:00
|
|
|
/*
|
2014-02-10 01:10:30 +00:00
|
|
|
print_line("FOUND screen orientation");
|
|
|
|
if (attr_value==0xFFFFFFFF) {
|
|
|
|
WARN_PRINT("Version name in a resource, should be plaintext")
|
|
|
|
} else {
|
|
|
|
string_table[attr_value]=(orientation==0?"landscape":"portrait");
|
2015-05-02 00:13:20 +00:00
|
|
|
}*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (tname == "uses-permission" && /*nspace=="android" &&*/ attrname == "name") {
|
2014-04-15 01:43:44 +00:00
|
|
|
|
|
|
|
if (value.begins_with("godot.custom")) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int which = value.get_slice(".", 2).to_int();
|
|
|
|
if (which >= 0 && which < MAX_USER_PERMISSIONS && user_perms[which].strip_edges() != "") {
|
2014-04-15 01:43:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
string_table[attr_value] = user_perms[which].strip_edges();
|
2014-04-15 01:43:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (value.begins_with("godot.")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
String perm = value.get_slice(".", 1);
|
2015-08-06 05:37:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (perms.has(perm) || (p_give_internet && perm == "INTERNET")) {
|
2015-08-06 05:37:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
print_line("PERM: " + perm);
|
|
|
|
string_table[attr_value] = "android.permission." + perm;
|
2014-04-15 01:43:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (tname == "supports-screens") {
|
2014-04-15 01:43:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (attrname == "smallScreens") {
|
2014-04-15 01:43:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(screen_support[SCREEN_SMALL] ? 0xFFFFFFFF : 0, &p_manifest[iofs + 16]);
|
2014-04-15 01:43:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (attrname == "normalScreens") {
|
2014-04-15 01:43:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(screen_support[SCREEN_NORMAL] ? 0xFFFFFFFF : 0, &p_manifest[iofs + 16]);
|
2014-04-15 01:43:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (attrname == "largeScreens") {
|
2014-04-15 01:43:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(screen_support[SCREEN_LARGE] ? 0xFFFFFFFF : 0, &p_manifest[iofs + 16]);
|
2014-04-15 01:43:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (attrname == "xlargeScreens") {
|
2014-04-15 01:43:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(screen_support[SCREEN_XLARGE] ? 0xFFFFFFFF : 0, &p_manifest[iofs + 16]);
|
2014-04-15 01:43:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
iofs += 20;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
2016-11-08 19:49:10 +00:00
|
|
|
//printf("chunk %x: size: %d\n",chunk,size);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ofs += size;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-11-08 19:49:10 +00:00
|
|
|
//printf("end\n");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//create new andriodmanifest binary
|
|
|
|
|
|
|
|
Vector<uint8_t> ret;
|
2017-03-18 23:36:26 +00:00
|
|
|
ret.resize(string_table_begins + string_table.size() * 4);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < string_table_begins; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ret[i] = p_manifest[i];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ofs = 0;
|
|
|
|
for (int i = 0; i < string_table.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(ofs, &ret[string_table_begins + i * 4]);
|
|
|
|
ofs += string_table[i].length() * 2 + 2 + 2;
|
2016-11-08 19:49:10 +00:00
|
|
|
//print_line("ofs: "+itos(i)+": "+itos(ofs));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
ret.resize(ret.size() + ofs);
|
|
|
|
uint8_t *chars = &ret[ret.size() - ofs];
|
|
|
|
for (int i = 0; i < string_table.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String s = string_table[i];
|
2016-11-08 19:49:10 +00:00
|
|
|
//print_line("savint string :"+s);
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint16(s.length(), chars);
|
|
|
|
chars += 2;
|
|
|
|
for (int j = 0; j < s.length(); j++) { //include zero?
|
|
|
|
encode_uint16(s[j], chars);
|
|
|
|
chars += 2;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint16(0, chars);
|
|
|
|
chars += 2;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < stable_extra.size(); i++) {
|
2016-09-21 10:46:40 +00:00
|
|
|
ret.push_back(stable_extra[i]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (ret.size() % 4)
|
2016-09-21 10:46:40 +00:00
|
|
|
ret.push_back(0);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t new_stable_end = ret.size();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t extra = (p_manifest.size() - string_table_ends);
|
2014-02-10 01:10:30 +00:00
|
|
|
ret.resize(new_stable_end + extra);
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < extra; i++)
|
|
|
|
ret[new_stable_end + i] = p_manifest[string_table_ends + i];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (ret.size() % 4)
|
2014-02-10 01:10:30 +00:00
|
|
|
ret.push_back(0);
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(ret.size(), &ret[4]); //update new file size
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(new_stable_end - 8, &ret[12]); //update new string table size
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-11-08 19:49:10 +00:00
|
|
|
//print_line("file size: "+itos(ret.size()));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_manifest = ret;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
uint32_t header[9];
|
|
|
|
for(int i=0;i<9;i++) {
|
|
|
|
header[i]=decode_uint32(&p_manifest[i*4]);
|
|
|
|
}
|
|
|
|
|
2016-11-08 19:49:10 +00:00
|
|
|
//print_line("STO: "+itos(header[3]));
|
2014-02-10 01:10:30 +00:00
|
|
|
uint32_t st_offset=9*4;
|
|
|
|
//ERR_FAIL_COND(header[3]!=0x24)
|
|
|
|
uint32_t string_count=header[4];
|
|
|
|
|
|
|
|
|
|
|
|
string_table.resize(string_count);
|
|
|
|
|
|
|
|
for(int i=0;i<string_count;i++) {
|
|
|
|
|
|
|
|
uint32_t string_at = decode_uint32(&p_manifest[st_offset+i*4]);
|
|
|
|
string_at+=st_offset+string_count*4;
|
|
|
|
uint32_t len = decode_uint16(&p_manifest[string_at]);
|
|
|
|
Vector<CharType> ucstring;
|
|
|
|
ucstring.resize(len+1);
|
|
|
|
for(int j=0;j<len;j++) {
|
|
|
|
uint16_t c=decode_uint16(&p_manifest[string_at+2+2*j]);
|
|
|
|
ucstring[j]=c;
|
|
|
|
}
|
|
|
|
ucstring[len]=0;
|
|
|
|
string_table[i]=ucstring.ptr();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error EditorExportPlatformAndroid::save_apk_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
APKExportData *ed = (APKExportData *)p_userdata;
|
|
|
|
String dst_path = p_path;
|
|
|
|
dst_path = dst_path.replace_first("res://", "assets/");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
zipOpenNewFileInZip(ed->apk,
|
2017-03-18 23:36:26 +00:00
|
|
|
dst_path.utf8().get_data(),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
_should_compress_asset(p_path, p_data) ? Z_DEFLATED : 0,
|
|
|
|
Z_DEFAULT_COMPRESSION);
|
|
|
|
|
|
|
|
zipWriteInFileInZip(ed->apk, p_data.ptr(), p_data.size());
|
2014-02-10 01:10:30 +00:00
|
|
|
zipCloseFileInZip(ed->apk);
|
2017-03-18 23:36:26 +00:00
|
|
|
ed->ep->step("File: " + p_path, 3 + p_file * 100 / p_total);
|
2014-02-10 01:10:30 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool EditorExportPlatformAndroid::_should_compress_asset(const String &p_path, const Vector<uint8_t> &p_data) {
|
2016-06-11 11:08:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* By not compressing files with little or not benefit in doing so,
|
|
|
|
* a performance gain is expected at runtime. Moreover, if the APK is
|
|
|
|
* zip-aligned, assets stored as they are can be efficiently read by
|
|
|
|
* Android by memory-mapping them.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// -- Unconditional uncompress to mimic AAPT plus some other
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
static const char *unconditional_compress_ext[] = {
|
2016-06-11 11:08:42 +00:00
|
|
|
// From https://github.com/android/platform_frameworks_base/blob/master/tools/aapt/Package.cpp
|
|
|
|
// These formats are already compressed, or don't compress well:
|
|
|
|
".jpg", ".jpeg", ".png", ".gif",
|
|
|
|
".wav", ".mp2", ".mp3", ".ogg", ".aac",
|
|
|
|
".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet",
|
|
|
|
".rtttl", ".imy", ".xmf", ".mp4", ".m4a",
|
|
|
|
".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2",
|
|
|
|
".amr", ".awb", ".wma", ".wmv",
|
|
|
|
// Godot-specific:
|
|
|
|
".webp", // Same reasoning as .png
|
|
|
|
".cfb", // Don't let small config files slow-down startup
|
|
|
|
// Trailer for easier processing
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (const char **ext = unconditional_compress_ext; *ext; ++ext) {
|
2016-06-11 11:08:42 +00:00
|
|
|
if (p_path.to_lower().ends_with(String(*ext))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -- Compressed resource?
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_data.size() >= 4 && p_data[0] == 'R' && p_data[1] == 'S' && p_data[2] == 'C' && p_data[3] == 'C') {
|
2016-06-11 11:08:42 +00:00
|
|
|
// Already compressed
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- TODO: Decide on texture resources according to their image compression setting
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error EditorExportPlatformAndroid::export_project(const String &p_path, bool p_debug, int p_flags) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String src_apk;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorProgress ep("export", "Exporting for Android", 105);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-11-30 00:26:51 +00:00
|
|
|
if (p_debug)
|
2017-03-18 23:36:26 +00:00
|
|
|
src_apk = custom_debug_package;
|
2015-11-30 00:26:51 +00:00
|
|
|
else
|
2017-03-18 23:36:26 +00:00
|
|
|
src_apk = custom_release_package;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (src_apk == "") {
|
2015-11-30 00:26:51 +00:00
|
|
|
String err;
|
|
|
|
if (p_debug) {
|
2017-03-18 23:36:26 +00:00
|
|
|
src_apk = find_export_template("android_debug.apk", &err);
|
2015-11-30 00:26:51 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
src_apk = find_export_template("android_release.apk", &err);
|
2015-11-30 00:26:51 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
if (src_apk == "") {
|
2015-11-30 00:26:51 +00:00
|
|
|
EditorNode::add_io_error(err);
|
|
|
|
return ERR_FILE_NOT_FOUND;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
FileAccess *src_f = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ep.step("Creating APK", 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
unzFile pkg = unzOpen2(src_apk.utf8().get_data(), &io);
|
|
|
|
if (!pkg) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorNode::add_io_error("Could not find template APK to export:\n" + src_apk);
|
2014-02-10 01:10:30 +00:00
|
|
|
return ERR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!pkg, ERR_CANT_OPEN);
|
|
|
|
int ret = unzGoToFirstFile(pkg);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
zlib_filefunc_def io2 = io;
|
|
|
|
FileAccess *dst_f = NULL;
|
|
|
|
io2.opaque = &dst_f;
|
|
|
|
String unaligned_path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/tmpexport-unaligned.apk";
|
|
|
|
zipFile unaligned_apk = zipOpen2(unaligned_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (ret == UNZ_OK) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//get filename
|
|
|
|
unz_file_info info;
|
|
|
|
char fname[16384];
|
2017-03-18 23:36:26 +00:00
|
|
|
ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool skip = false;
|
2015-05-02 01:45:32 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String file = fname;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Vector<uint8_t> data;
|
|
|
|
data.resize(info.uncompressed_size);
|
|
|
|
|
|
|
|
//read
|
|
|
|
unzOpenCurrentFile(pkg);
|
2017-03-18 23:36:26 +00:00
|
|
|
unzReadCurrentFile(pkg, data.ptr(), data.size());
|
2014-02-10 01:10:30 +00:00
|
|
|
unzCloseCurrentFile(pkg);
|
|
|
|
|
|
|
|
//write
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (file == "AndroidManifest.xml") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_fix_manifest(data, p_flags & (EXPORT_DUMB_CLIENT | EXPORT_REMOTE_DEBUG));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (file == "resources.arsc") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_fix_resources(data);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (file == "res/drawable/icon.png") {
|
|
|
|
bool found = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (this->icon != "" && this->icon.ends_with(".png")) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
FileAccess *f = FileAccess::open(this->icon, FileAccess::READ);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (f) {
|
|
|
|
|
|
|
|
data.resize(f->get_len());
|
2017-03-18 23:36:26 +00:00
|
|
|
f->get_buffer(data.ptr(), data.size());
|
2014-02-10 01:10:30 +00:00
|
|
|
memdelete(f);
|
2017-03-18 23:36:26 +00:00
|
|
|
found = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
|
|
|
|
String appicon = Globals::get_singleton()->get("application/icon");
|
2017-03-18 23:36:26 +00:00
|
|
|
if (appicon != "" && appicon.ends_with(".png")) {
|
|
|
|
FileAccess *f = FileAccess::open(appicon, FileAccess::READ);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (f) {
|
|
|
|
data.resize(f->get_len());
|
2017-03-18 23:36:26 +00:00
|
|
|
f->get_buffer(data.ptr(), data.size());
|
2014-02-10 01:10:30 +00:00
|
|
|
memdelete(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (file == "lib/x86/libgodot_android.so" && !export_x86) {
|
|
|
|
skip = true;
|
2015-05-02 01:45:32 +00:00
|
|
|
}
|
|
|
|
|
2016-06-15 13:21:18 +00:00
|
|
|
if (file.match("lib/armeabi*/libgodot_android.so") && !export_arm) {
|
2017-03-18 23:36:26 +00:00
|
|
|
skip = true;
|
2015-05-02 01:45:32 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-07-25 10:28:31 +00:00
|
|
|
if (file.match("lib/arm64*/libgodot_android.so") && !export_arm64) {
|
|
|
|
skip = true;
|
|
|
|
}
|
|
|
|
|
2015-11-14 17:10:22 +00:00
|
|
|
if (file.begins_with("META-INF") && _signed) {
|
2017-03-18 23:36:26 +00:00
|
|
|
skip = true;
|
2015-11-14 17:10:22 +00:00
|
|
|
}
|
2015-05-02 01:45:32 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
print_line("ADDING: " + file);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-05-02 01:45:32 +00:00
|
|
|
if (!skip) {
|
2016-06-11 11:08:42 +00:00
|
|
|
|
|
|
|
// Respect decision on compression made by AAPT for the export template
|
|
|
|
const bool uncompressed = info.compression_method == 0;
|
|
|
|
|
2016-06-12 22:19:45 +00:00
|
|
|
zipOpenNewFileInZip(unaligned_apk,
|
2017-03-18 23:36:26 +00:00
|
|
|
file.utf8().get_data(),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
uncompressed ? 0 : Z_DEFLATED,
|
|
|
|
Z_DEFAULT_COMPRESSION);
|
|
|
|
|
|
|
|
zipWriteInFileInZip(unaligned_apk, data.ptr(), data.size());
|
2016-06-12 22:19:45 +00:00
|
|
|
zipCloseFileInZip(unaligned_apk);
|
2015-05-02 01:45:32 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ret = unzGoToNextFile(pkg);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ep.step("Adding Files..", 1);
|
|
|
|
Error err = OK;
|
2014-04-29 00:56:43 +00:00
|
|
|
Vector<String> cl = cmdline.strip_edges().split(" ");
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < cl.size(); i++) {
|
|
|
|
if (cl[i].strip_edges().length() == 0) {
|
2014-06-28 02:21:45 +00:00
|
|
|
cl.remove(i);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
gen_export_flags(cl, p_flags);
|
2015-08-06 05:37:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_flags & EXPORT_DUMB_CLIENT) {
|
2014-05-29 13:56:39 +00:00
|
|
|
|
2015-08-06 05:37:40 +00:00
|
|
|
/*String host = EditorSettings::get_singleton()->get("file_server/host");
|
2014-05-29 13:56:39 +00:00
|
|
|
int port = EditorSettings::get_singleton()->get("file_server/post");
|
|
|
|
String passwd = EditorSettings::get_singleton()->get("file_server/password");
|
|
|
|
cl.push_back("-rfs");
|
|
|
|
cl.push_back(host+":"+itos(port));
|
|
|
|
if (passwd!="") {
|
|
|
|
cl.push_back("-rfs_pass");
|
|
|
|
cl.push_back(passwd);
|
2015-08-06 05:37:40 +00:00
|
|
|
}*/
|
2014-05-29 13:56:39 +00:00
|
|
|
|
2014-04-29 00:56:43 +00:00
|
|
|
} else {
|
2014-05-29 13:56:39 +00:00
|
|
|
//all files
|
|
|
|
|
|
|
|
if (apk_expansion) {
|
2014-04-29 00:56:43 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String apkfname = "main." + itos(version_code) + "." + get_package_name() + ".obb";
|
|
|
|
String fullpath = p_path.get_base_dir().plus_file(apkfname);
|
|
|
|
FileAccess *pf = FileAccess::open(fullpath, FileAccess::WRITE);
|
2014-05-29 13:56:39 +00:00
|
|
|
if (!pf) {
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorNode::add_io_error("Could not write expansion package file: " + apkfname);
|
2014-05-29 13:56:39 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
err = save_pack(pf);
|
|
|
|
memdelete(pf);
|
2014-06-28 02:21:45 +00:00
|
|
|
|
|
|
|
cl.push_back("-use_apk_expansion");
|
|
|
|
cl.push_back("-apk_expansion_md5");
|
2014-05-29 13:56:39 +00:00
|
|
|
cl.push_back(FileAccess::get_md5(fullpath));
|
2014-06-28 02:21:45 +00:00
|
|
|
cl.push_back("-apk_expansion_key");
|
|
|
|
cl.push_back(apk_expansion_pkey.strip_edges());
|
2014-05-29 13:56:39 +00:00
|
|
|
|
|
|
|
} else {
|
2014-04-29 00:56:43 +00:00
|
|
|
|
2014-05-29 13:56:39 +00:00
|
|
|
APKExportData ed;
|
2017-03-18 23:36:26 +00:00
|
|
|
ed.ep = &ep;
|
|
|
|
ed.apk = unaligned_apk;
|
2014-05-29 13:56:39 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
err = export_project_files(save_apk_file, &ed, false);
|
2014-05-29 13:56:39 +00:00
|
|
|
}
|
2014-04-29 00:56:43 +00:00
|
|
|
}
|
|
|
|
|
2015-03-31 22:02:40 +00:00
|
|
|
if (use_32_fb)
|
|
|
|
cl.push_back("-use_depth_32");
|
|
|
|
|
2015-04-17 19:18:46 +00:00
|
|
|
if (immersive)
|
|
|
|
cl.push_back("-use_immersive");
|
2015-03-31 22:02:40 +00:00
|
|
|
|
2014-04-29 00:56:43 +00:00
|
|
|
if (cl.size()) {
|
|
|
|
//add comandline
|
|
|
|
Vector<uint8_t> clf;
|
|
|
|
clf.resize(4);
|
2017-03-18 23:36:26 +00:00
|
|
|
encode_uint32(cl.size(), &clf[0]);
|
|
|
|
for (int i = 0; i < cl.size(); i++) {
|
2014-04-29 00:56:43 +00:00
|
|
|
|
|
|
|
CharString txt = cl[i].utf8();
|
|
|
|
int base = clf.size();
|
2017-03-18 23:36:26 +00:00
|
|
|
clf.resize(base + 4 + txt.length());
|
|
|
|
encode_uint32(txt.length(), &clf[base]);
|
|
|
|
copymem(&clf[base + 4], txt.ptr(), txt.length());
|
|
|
|
print_line(itos(i) + " param: " + cl[i]);
|
2014-04-29 00:56:43 +00:00
|
|
|
}
|
|
|
|
|
2016-06-12 22:19:45 +00:00
|
|
|
zipOpenNewFileInZip(unaligned_apk,
|
2017-03-18 23:36:26 +00:00
|
|
|
"assets/_cl_",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
0, // No compress (little size gain and potentially slower startup)
|
|
|
|
Z_DEFAULT_COMPRESSION);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
zipWriteInFileInZip(unaligned_apk, clf.ptr(), clf.size());
|
2016-06-12 22:19:45 +00:00
|
|
|
zipCloseFileInZip(unaligned_apk);
|
2014-04-29 00:56:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
zipClose(unaligned_apk, NULL);
|
2014-02-10 01:10:30 +00:00
|
|
|
unzClose(pkg);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_signed) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String jarsigner = EditorSettings::get_singleton()->get("android/jarsigner");
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!FileAccess::exists(jarsigner)) {
|
|
|
|
EditorNode::add_io_error("'jarsigner' could not be found.\nPlease supply a path in the editor settings.\nResulting apk is unsigned.");
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
String keystore;
|
|
|
|
String password;
|
|
|
|
String user;
|
|
|
|
if (p_debug) {
|
2017-03-18 23:36:26 +00:00
|
|
|
keystore = EditorSettings::get_singleton()->get("android/debug_keystore");
|
|
|
|
password = EditorSettings::get_singleton()->get("android/debug_keystore_pass");
|
|
|
|
user = EditorSettings::get_singleton()->get("android/debug_keystore_user");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ep.step("Signing Debug APK..", 103);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
keystore = release_keystore;
|
|
|
|
password = release_password;
|
|
|
|
user = release_username;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ep.step("Signing Release APK..", 103);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!FileAccess::exists(keystore)) {
|
2014-12-07 14:33:57 +00:00
|
|
|
EditorNode::add_io_error("Could not find keystore, unable to export.");
|
2014-02-10 01:10:30 +00:00
|
|
|
return ERR_FILE_CANT_OPEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<String> args;
|
|
|
|
args.push_back("-digestalg");
|
2018-05-05 06:23:17 +00:00
|
|
|
args.push_back("SHA-256");
|
2014-02-10 01:10:30 +00:00
|
|
|
args.push_back("-sigalg");
|
2018-05-05 06:23:17 +00:00
|
|
|
args.push_back("SHA256withRSA");
|
2017-03-18 23:36:26 +00:00
|
|
|
String tsa_url = EditorSettings::get_singleton()->get("android/timestamping_authority_url");
|
2014-11-01 08:20:18 +00:00
|
|
|
if (tsa_url != "") {
|
|
|
|
args.push_back("-tsa");
|
|
|
|
args.push_back(tsa_url);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
args.push_back("-verbose");
|
|
|
|
args.push_back("-keystore");
|
|
|
|
args.push_back(keystore);
|
|
|
|
args.push_back("-storepass");
|
|
|
|
args.push_back(password);
|
2016-06-12 22:19:45 +00:00
|
|
|
args.push_back(unaligned_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
args.push_back(user);
|
|
|
|
int retval;
|
2017-03-18 23:36:26 +00:00
|
|
|
int err = OS::get_singleton()->execute(jarsigner, args, true, NULL, NULL, &retval);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (retval) {
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorNode::add_io_error("'jarsigner' returned with error #" + itos(retval));
|
2014-02-10 01:10:30 +00:00
|
|
|
return ERR_CANT_CREATE;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ep.step("Verifying APK..", 104);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
args.clear();
|
|
|
|
args.push_back("-verify");
|
2016-06-12 22:19:45 +00:00
|
|
|
args.push_back(unaligned_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
args.push_back("-verbose");
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
err = OS::get_singleton()->execute(jarsigner, args, true, NULL, NULL, &retval);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (retval) {
|
2016-06-11 11:11:42 +00:00
|
|
|
EditorNode::add_io_error("'jarsigner' verification of APK failed. Make sure to use jarsigner from Java 6.");
|
2014-02-10 01:10:30 +00:00
|
|
|
return ERR_CANT_CREATE;
|
|
|
|
}
|
|
|
|
}
|
2016-06-12 22:19:45 +00:00
|
|
|
|
|
|
|
// Let's zip-align (must be done after signing)
|
|
|
|
|
|
|
|
static const int ZIP_ALIGNMENT = 4;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ep.step("Aligning APK..", 105);
|
2016-06-12 22:19:45 +00:00
|
|
|
|
|
|
|
unzFile tmp_unaligned = unzOpen2(unaligned_path.utf8().get_data(), &io);
|
|
|
|
if (!tmp_unaligned) {
|
|
|
|
|
|
|
|
EditorNode::add_io_error("Could not find temp unaligned APK.");
|
|
|
|
return ERR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!tmp_unaligned, ERR_CANT_OPEN);
|
|
|
|
ret = unzGoToFirstFile(tmp_unaligned);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
io2 = io;
|
|
|
|
dst_f = NULL;
|
|
|
|
io2.opaque = &dst_f;
|
|
|
|
zipFile final_apk = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2);
|
2016-06-12 22:19:45 +00:00
|
|
|
|
|
|
|
// Take files from the unaligned APK and write them out to the aligned one
|
|
|
|
// in raw mode, i.e. not uncompressing and recompressing, aligning them as needed,
|
|
|
|
// following what is done in https://github.com/android/platform_build/blob/master/tools/zipalign/ZipAlign.cpp
|
|
|
|
int bias = 0;
|
2017-03-18 23:36:26 +00:00
|
|
|
while (ret == UNZ_OK) {
|
2016-06-12 22:19:45 +00:00
|
|
|
|
|
|
|
unz_file_info info;
|
|
|
|
memset(&info, 0, sizeof(info));
|
|
|
|
|
|
|
|
char fname[16384];
|
|
|
|
char extra[16384];
|
2017-03-18 23:36:26 +00:00
|
|
|
ret = unzGetCurrentFileInfo(tmp_unaligned, &info, fname, 16384, extra, 16384 - ZIP_ALIGNMENT, NULL, 0);
|
2016-06-12 22:19:45 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String file = fname;
|
2016-06-12 22:19:45 +00:00
|
|
|
|
|
|
|
Vector<uint8_t> data;
|
|
|
|
data.resize(info.compressed_size);
|
|
|
|
|
|
|
|
// read
|
|
|
|
int method, level;
|
|
|
|
unzOpenCurrentFile2(tmp_unaligned, &method, &level, 1); // raw read
|
|
|
|
long file_offset = unzGetCurrentFileZStreamPos64(tmp_unaligned);
|
2017-03-18 23:36:26 +00:00
|
|
|
unzReadCurrentFile(tmp_unaligned, data.ptr(), data.size());
|
2016-06-12 22:19:45 +00:00
|
|
|
unzCloseCurrentFile(tmp_unaligned);
|
|
|
|
|
|
|
|
// align
|
|
|
|
int padding = 0;
|
|
|
|
if (!info.compression_method) {
|
|
|
|
// Uncompressed file => Align
|
|
|
|
long new_offset = file_offset + bias;
|
2017-03-18 23:36:26 +00:00
|
|
|
padding = (ZIP_ALIGNMENT - (new_offset % ZIP_ALIGNMENT)) % ZIP_ALIGNMENT;
|
2016-06-12 22:19:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(extra + info.size_file_extra, 0, padding);
|
|
|
|
|
|
|
|
// write
|
|
|
|
zipOpenNewFileInZip2(final_apk,
|
2017-03-18 23:36:26 +00:00
|
|
|
file.utf8().get_data(),
|
|
|
|
NULL,
|
|
|
|
extra,
|
|
|
|
info.size_file_extra + padding,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
method,
|
|
|
|
level,
|
|
|
|
1); // raw write
|
|
|
|
zipWriteInFileInZip(final_apk, data.ptr(), data.size());
|
|
|
|
zipCloseFileInZipRaw(final_apk, info.uncompressed_size, info.crc);
|
2016-06-12 22:19:45 +00:00
|
|
|
|
|
|
|
bias += padding;
|
|
|
|
|
|
|
|
ret = unzGoToNextFile(tmp_unaligned);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
zipClose(final_apk, NULL);
|
2016-06-12 22:19:45 +00:00
|
|
|
unzClose(tmp_unaligned);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorExportPlatformAndroid::poll_devices() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool dc = devices_changed;
|
|
|
|
devices_changed = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return dc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int EditorExportPlatformAndroid::get_device_count() const {
|
|
|
|
|
|
|
|
device_lock->lock();
|
2017-03-18 23:36:26 +00:00
|
|
|
int dc = devices.size();
|
2014-02-10 01:10:30 +00:00
|
|
|
device_lock->unlock();
|
|
|
|
|
|
|
|
return dc;
|
|
|
|
}
|
2016-07-21 10:07:01 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String EditorExportPlatformAndroid::get_device_name(int p_device) const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_device, devices.size(), "");
|
2014-02-10 01:10:30 +00:00
|
|
|
device_lock->lock();
|
2017-03-18 23:36:26 +00:00
|
|
|
String s = devices[p_device].name;
|
2014-02-10 01:10:30 +00:00
|
|
|
device_lock->unlock();
|
|
|
|
return s;
|
|
|
|
}
|
2016-07-21 10:07:01 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String EditorExportPlatformAndroid::get_device_info(int p_device) const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_device, devices.size(), "");
|
2014-02-10 01:10:30 +00:00
|
|
|
device_lock->lock();
|
2017-03-18 23:36:26 +00:00
|
|
|
String s = devices[p_device].description;
|
2014-02-10 01:10:30 +00:00
|
|
|
device_lock->unlock();
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorExportPlatformAndroid::_device_poll_thread(void *ud) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorExportPlatformAndroid *ea = (EditorExportPlatformAndroid *)ud;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (!ea->quit_request) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String adb = EditorSettings::get_singleton()->get("android/adb");
|
2016-06-08 01:08:12 +00:00
|
|
|
if (FileAccess::exists(adb)) {
|
|
|
|
|
|
|
|
String devices;
|
|
|
|
List<String> args;
|
|
|
|
args.push_back("devices");
|
|
|
|
int ec;
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = OS::get_singleton()->execute(adb, args, true, NULL, &devices, &ec);
|
2016-06-08 01:08:12 +00:00
|
|
|
Vector<String> ds = devices.split("\n");
|
|
|
|
Vector<String> ldevices;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 1; i < ds.size(); i++) {
|
2016-06-08 01:08:12 +00:00
|
|
|
|
|
|
|
String d = ds[i];
|
|
|
|
int dpos = d.find("device");
|
2017-03-18 23:36:26 +00:00
|
|
|
if (dpos == -1)
|
2016-06-08 01:08:12 +00:00
|
|
|
continue;
|
2017-03-18 23:36:26 +00:00
|
|
|
d = d.substr(0, dpos).strip_edges();
|
|
|
|
// print_line("found devuce: "+d);
|
2016-06-08 01:08:12 +00:00
|
|
|
ldevices.push_back(d);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-08 01:08:12 +00:00
|
|
|
ea->device_lock->lock();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool different = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (devices.size() != ldevices.size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
different = true;
|
2016-06-08 01:08:12 +00:00
|
|
|
} else {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < ea->devices.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ea->devices[i].id != ldevices[i]) {
|
|
|
|
different = true;
|
2016-06-08 01:08:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-08 01:08:12 +00:00
|
|
|
if (different) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-08 01:08:12 +00:00
|
|
|
Vector<Device> ndevices;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < ldevices.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-08 01:08:12 +00:00
|
|
|
Device d;
|
2017-03-18 23:36:26 +00:00
|
|
|
d.id = ldevices[i];
|
|
|
|
for (int j = 0; j < ea->devices.size(); j++) {
|
|
|
|
if (ea->devices[j].id == ldevices[i]) {
|
|
|
|
d.description = ea->devices[j].description;
|
|
|
|
d.name = ea->devices[j].name;
|
2017-08-30 18:11:05 +00:00
|
|
|
d.api_level = ea->devices[j].api_level;
|
2016-06-08 01:08:12 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (d.description == "") {
|
2016-06-08 01:08:12 +00:00
|
|
|
//in the oven, request!
|
|
|
|
args.clear();
|
|
|
|
args.push_back("-s");
|
|
|
|
args.push_back(d.id);
|
|
|
|
args.push_back("shell");
|
2018-03-20 05:18:38 +00:00
|
|
|
args.push_back("getprop");
|
2016-06-08 01:08:12 +00:00
|
|
|
int ec;
|
|
|
|
String dp;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = OS::get_singleton()->execute(adb, args, true, NULL, &dp, &ec);
|
2016-07-20 00:26:12 +00:00
|
|
|
|
2016-06-08 01:08:12 +00:00
|
|
|
Vector<String> props = dp.split("\n");
|
|
|
|
String vendor;
|
|
|
|
String device;
|
2017-03-18 23:36:26 +00:00
|
|
|
d.description + "Device ID: " + d.id + "\n";
|
2017-08-30 18:11:05 +00:00
|
|
|
d.api_level = 0;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int j = 0; j < props.size(); j++) {
|
2016-06-08 01:08:12 +00:00
|
|
|
|
2018-03-20 05:18:38 +00:00
|
|
|
// got information by `shell cat /system/build.prop` before and its format is "property=value"
|
|
|
|
// it's now changed to use `shell getporp` because of permission issue with Android 8.0 and above
|
|
|
|
// its format is "[property]: [value]" so changed it as like build.prop
|
2016-06-08 01:08:12 +00:00
|
|
|
String p = props[j];
|
2018-03-20 05:18:38 +00:00
|
|
|
p = p.replace("]: ", "=");
|
|
|
|
p = p.replace("[", "");
|
|
|
|
p = p.replace("]", "");
|
|
|
|
|
2016-06-08 01:08:12 +00:00
|
|
|
if (p.begins_with("ro.product.model=")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
device = p.get_slice("=", 1).strip_edges();
|
2016-06-08 01:08:12 +00:00
|
|
|
} else if (p.begins_with("ro.product.brand=")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
vendor = p.get_slice("=", 1).strip_edges().capitalize();
|
2016-06-08 01:08:12 +00:00
|
|
|
} else if (p.begins_with("ro.build.display.id=")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
d.description += "Build: " + p.get_slice("=", 1).strip_edges() + "\n";
|
2016-06-08 01:08:12 +00:00
|
|
|
} else if (p.begins_with("ro.build.version.release=")) {
|
2017-08-30 18:11:05 +00:00
|
|
|
d.description += "Release: " + p.get_slice("=", 1).strip_edges() + "\n";
|
|
|
|
} else if (p.begins_with("ro.build.version.sdk=")) {
|
|
|
|
d.api_level = p.get_slice("=", 1).to_int();
|
2016-06-08 01:08:12 +00:00
|
|
|
} else if (p.begins_with("ro.product.cpu.abi=")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
d.description += "CPU: " + p.get_slice("=", 1).strip_edges() + "\n";
|
2016-06-08 01:08:12 +00:00
|
|
|
} else if (p.begins_with("ro.product.manufacturer=")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
d.description += "Manufacturer: " + p.get_slice("=", 1).strip_edges() + "\n";
|
2016-06-08 01:08:12 +00:00
|
|
|
} else if (p.begins_with("ro.board.platform=")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
d.description += "Chipset: " + p.get_slice("=", 1).strip_edges() + "\n";
|
2016-06-08 01:08:12 +00:00
|
|
|
} else if (p.begins_with("ro.opengles.version=")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t opengl = p.get_slice("=", 1).to_int();
|
|
|
|
d.description += "OpenGL: " + itos(opengl >> 16) + "." + itos((opengl >> 8) & 0xFF) + "." + itos((opengl)&0xFF) + "\n";
|
2016-06-08 01:08:12 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-06-08 01:08:12 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
d.name = vendor + " " + device;
|
|
|
|
// print_line("name: "+d.name);
|
|
|
|
// print_line("description: "+d.description);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 01:08:12 +00:00
|
|
|
ndevices.push_back(d);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ea->devices = ndevices;
|
|
|
|
ea->devices_changed = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 01:08:12 +00:00
|
|
|
ea->device_lock->unlock();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 01:08:12 +00:00
|
|
|
uint64_t wait = 3000000;
|
|
|
|
uint64_t time = OS::get_singleton()->get_ticks_usec();
|
2017-03-18 23:36:26 +00:00
|
|
|
while (OS::get_singleton()->get_ticks_usec() - time < wait) {
|
2016-06-08 01:08:12 +00:00
|
|
|
OS::get_singleton()->delay_usec(1000);
|
|
|
|
if (ea->quit_request)
|
|
|
|
break;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-02-27 15:11:40 +00:00
|
|
|
if (EditorSettings::get_singleton()->get("android/shutdown_adb_on_exit")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
String adb = EditorSettings::get_singleton()->get("android/adb");
|
2016-02-27 15:11:40 +00:00
|
|
|
if (!FileAccess::exists(adb)) {
|
|
|
|
return; //adb not configured
|
|
|
|
}
|
|
|
|
|
|
|
|
List<String> args;
|
|
|
|
args.push_back("kill-server");
|
2017-03-18 23:36:26 +00:00
|
|
|
OS::get_singleton()->execute(adb, args, true);
|
2016-02-27 15:11:40 +00:00
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-20 16:03:46 +00:00
|
|
|
Error EditorExportPlatformAndroid::run(int p_device, int p_flags) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_device, devices.size(), ERR_INVALID_PARAMETER);
|
2014-02-10 01:10:30 +00:00
|
|
|
device_lock->lock();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorProgress ep("run", "Running on " + devices[p_device].name, 3);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String adb = EditorSettings::get_singleton()->get("android/adb");
|
|
|
|
if (adb == "") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
EditorNode::add_io_error("ADB executable not configured in settings, can't run.");
|
|
|
|
device_lock->unlock();
|
|
|
|
return ERR_UNCONFIGURED;
|
|
|
|
}
|
|
|
|
|
|
|
|
//export_temp
|
2017-03-18 23:36:26 +00:00
|
|
|
ep.step("Exporting APK", 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-30 18:03:47 +00:00
|
|
|
const bool use_remote = (p_flags & EXPORT_REMOTE_DEBUG) || (p_flags & EXPORT_DUMB_CLIENT);
|
|
|
|
const bool use_reverse = devices[p_device].api_level >= 21;
|
|
|
|
|
|
|
|
if (use_reverse)
|
|
|
|
p_flags |= EXPORT_REMOTE_DEBUG_LOCALHOST;
|
2016-01-20 03:29:34 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String export_to = EditorSettings::get_singleton()->get_settings_path() + "/tmp/tmpexport.apk";
|
|
|
|
Error err = export_project(export_to, true, p_flags);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (err) {
|
|
|
|
device_lock->unlock();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<String> args;
|
|
|
|
int rv;
|
2014-10-28 01:54:32 +00:00
|
|
|
|
|
|
|
if (remove_prev) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ep.step("Uninstalling..", 1);
|
2014-10-28 01:54:32 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
print_line("Uninstalling previous version: " + devices[p_device].name);
|
2014-10-28 01:54:32 +00:00
|
|
|
|
|
|
|
args.push_back("-s");
|
|
|
|
args.push_back(devices[p_device].id);
|
|
|
|
args.push_back("uninstall");
|
2015-05-02 02:21:27 +00:00
|
|
|
args.push_back(get_package_name());
|
2014-10-28 01:54:32 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv);
|
2014-02-10 01:10:30 +00:00
|
|
|
#if 0
|
|
|
|
if (err || rv!=0) {
|
|
|
|
EditorNode::add_io_error("Could not install to device.");
|
|
|
|
device_lock->unlock();
|
|
|
|
return ERR_CANT_CREATE;
|
|
|
|
}
|
|
|
|
#endif
|
2014-10-28 01:54:32 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
print_line("Installing into device (please wait..): " + devices[p_device].name);
|
|
|
|
ep.step("Installing to Device (please wait..)..", 2);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
args.clear();
|
|
|
|
args.push_back("-s");
|
|
|
|
args.push_back(devices[p_device].id);
|
|
|
|
args.push_back("install");
|
2016-03-18 10:11:55 +00:00
|
|
|
args.push_back("-r");
|
2014-02-10 01:10:30 +00:00
|
|
|
args.push_back(export_to);
|
2014-10-28 01:54:32 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv);
|
|
|
|
if (err || rv != 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
EditorNode::add_io_error("Could not install to device.");
|
|
|
|
device_lock->unlock();
|
|
|
|
return ERR_CANT_CREATE;
|
|
|
|
}
|
|
|
|
|
2017-08-30 18:03:47 +00:00
|
|
|
if (use_remote) {
|
|
|
|
if (use_reverse) {
|
2016-01-20 03:29:34 +00:00
|
|
|
|
2017-08-30 18:03:47 +00:00
|
|
|
static const char *const msg = "** Device API >= 21; debugging over USB **";
|
|
|
|
EditorNode::get_singleton()->get_log()->add_message(msg);
|
|
|
|
print_line(String(msg).to_upper());
|
2016-01-20 03:29:34 +00:00
|
|
|
|
2017-08-30 18:03:47 +00:00
|
|
|
args.clear();
|
|
|
|
args.push_back("-s");
|
|
|
|
args.push_back(devices[p_device].id);
|
|
|
|
args.push_back("reverse");
|
|
|
|
args.push_back("--remove-all");
|
|
|
|
err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv);
|
2016-01-20 03:29:34 +00:00
|
|
|
|
2017-08-30 18:03:47 +00:00
|
|
|
if (p_flags & EXPORT_REMOTE_DEBUG) {
|
2017-08-21 22:26:35 +00:00
|
|
|
|
2017-08-30 18:03:47 +00:00
|
|
|
int dbg_port = (int)EditorSettings::get_singleton()->get("network/debug_port");
|
|
|
|
args.clear();
|
|
|
|
args.push_back("-s");
|
|
|
|
args.push_back(devices[p_device].id);
|
|
|
|
args.push_back("reverse");
|
|
|
|
args.push_back("tcp:" + itos(dbg_port));
|
|
|
|
args.push_back("tcp:" + itos(dbg_port));
|
2016-01-20 03:29:34 +00:00
|
|
|
|
2017-08-30 18:03:47 +00:00
|
|
|
err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv);
|
|
|
|
print_line("Reverse result: " + itos(rv));
|
|
|
|
}
|
2016-01-20 03:29:34 +00:00
|
|
|
|
2017-08-30 18:03:47 +00:00
|
|
|
if (p_flags & EXPORT_DUMB_CLIENT) {
|
2016-01-20 03:29:34 +00:00
|
|
|
|
2017-08-30 18:03:47 +00:00
|
|
|
int fs_port = EditorSettings::get_singleton()->get("file_server/port");
|
|
|
|
|
|
|
|
args.clear();
|
|
|
|
args.push_back("-s");
|
|
|
|
args.push_back(devices[p_device].id);
|
|
|
|
args.push_back("reverse");
|
|
|
|
args.push_back("tcp:" + itos(fs_port));
|
|
|
|
args.push_back("tcp:" + itos(fs_port));
|
|
|
|
|
|
|
|
err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv);
|
|
|
|
print_line("Reverse result2: " + itos(rv));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
static const char *const msg = "** Device API < 21; debugging over Wi-Fi **";
|
|
|
|
EditorNode::get_singleton()->get_log()->add_message(msg);
|
|
|
|
print_line(String(msg).to_upper());
|
|
|
|
}
|
2016-01-20 03:29:34 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ep.step("Running on Device..", 3);
|
2014-02-10 01:10:30 +00:00
|
|
|
args.clear();
|
|
|
|
args.push_back("-s");
|
|
|
|
args.push_back(devices[p_device].id);
|
|
|
|
args.push_back("shell");
|
|
|
|
args.push_back("am");
|
|
|
|
args.push_back("start");
|
2017-08-30 18:11:05 +00:00
|
|
|
if (bool(EDITOR_DEF("android/force_system_user", false)) && devices[p_device].api_level >= 17) { // Multi-user introduced in Android 17
|
2017-07-27 15:25:09 +00:00
|
|
|
args.push_back("--user");
|
|
|
|
args.push_back("0");
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
args.push_back("-a");
|
|
|
|
args.push_back("android.intent.action.MAIN");
|
|
|
|
args.push_back("-n");
|
2017-03-18 23:36:26 +00:00
|
|
|
args.push_back(get_package_name() + "/org.godotengine.godot.Godot");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv);
|
|
|
|
if (err || rv != 0) {
|
2017-07-27 15:25:09 +00:00
|
|
|
EditorNode::add_io_error("Could not execute on device.");
|
2014-02-10 01:10:30 +00:00
|
|
|
device_lock->unlock();
|
|
|
|
return ERR_CANT_CREATE;
|
|
|
|
}
|
|
|
|
device_lock->unlock();
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2015-05-02 02:21:27 +00:00
|
|
|
String EditorExportPlatformAndroid::get_package_name() {
|
|
|
|
|
|
|
|
String pname = package;
|
|
|
|
String basename = Globals::get_singleton()->get("application/name");
|
2017-03-18 23:36:26 +00:00
|
|
|
basename = basename.to_lower();
|
2015-05-02 02:21:27 +00:00
|
|
|
|
|
|
|
String name;
|
2017-03-18 23:36:26 +00:00
|
|
|
bool first = true;
|
|
|
|
for (int i = 0; i < basename.length(); i++) {
|
2015-05-02 02:21:27 +00:00
|
|
|
CharType c = basename[i];
|
2017-03-18 23:36:26 +00:00
|
|
|
if (c >= '0' && c <= '9' && first) {
|
2015-05-02 02:21:27 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) {
|
|
|
|
name += String::chr(c);
|
|
|
|
first = false;
|
2015-05-02 02:21:27 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
if (name == "")
|
|
|
|
name = "noname";
|
2015-05-02 02:21:27 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
pname = pname.replace("$genname", name);
|
2015-05-02 02:21:27 +00:00
|
|
|
return pname;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
EditorExportPlatformAndroid::EditorExportPlatformAndroid() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
version_code = 1;
|
|
|
|
version_name = "1.0";
|
|
|
|
package = "org.godotengine.$genname";
|
|
|
|
name = "";
|
|
|
|
_signed = true;
|
|
|
|
apk_expansion = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
device_lock = Mutex::create();
|
2017-03-18 23:36:26 +00:00
|
|
|
quit_request = false;
|
|
|
|
orientation = 0;
|
|
|
|
remove_prev = true;
|
|
|
|
use_32_fb = true;
|
|
|
|
immersive = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
export_arm = true;
|
2017-07-25 10:28:31 +00:00
|
|
|
export_arm64 = false;
|
2017-03-18 23:36:26 +00:00
|
|
|
export_x86 = false;
|
2015-05-02 01:45:32 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
device_thread = Thread::create(_device_poll_thread, this);
|
|
|
|
devices_changed = true;
|
2015-05-02 01:45:32 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Image img(_android_logo);
|
|
|
|
logo = Ref<ImageTexture>(memnew(ImageTexture));
|
2014-02-10 01:10:30 +00:00
|
|
|
logo->create_from_image(img);
|
2014-04-15 01:43:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
screen_support[i] = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorExportPlatformAndroid::can_export(String *r_error) const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool valid = true;
|
|
|
|
String adb = EditorSettings::get_singleton()->get("android/adb");
|
2014-02-10 01:10:30 +00:00
|
|
|
String err;
|
|
|
|
|
|
|
|
if (!FileAccess::exists(adb)) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = false;
|
|
|
|
err += "ADB executable not configured in editor settings.\n";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String js = EditorSettings::get_singleton()->get("android/jarsigner");
|
|
|
|
|
|
|
|
if (!FileAccess::exists(js)) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = false;
|
|
|
|
err += "OpenJDK 6 jarsigner not configured in editor settings.\n";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String dk = EditorSettings::get_singleton()->get("android/debug_keystore");
|
|
|
|
|
|
|
|
if (!FileAccess::exists(dk)) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = false;
|
|
|
|
err += "Debug Keystore not configured in editor settings.\n";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-11-30 00:26:51 +00:00
|
|
|
if (!exists_export_template("android_debug.apk") || !exists_export_template("android_release.apk")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = false;
|
|
|
|
err += "No export templates found.\nDownload and install export templates.\n";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (custom_debug_package != "" && !FileAccess::exists(custom_debug_package)) {
|
|
|
|
valid = false;
|
|
|
|
err += "Custom debug package not found.\n";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (custom_release_package != "" && !FileAccess::exists(custom_release_package)) {
|
|
|
|
valid = false;
|
|
|
|
err += "Custom release package not found.\n";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2014-04-29 00:56:43 +00:00
|
|
|
if (apk_expansion) {
|
|
|
|
|
2014-06-28 02:21:45 +00:00
|
|
|
//if (apk_expansion_salt=="") {
|
|
|
|
// valid=false;
|
|
|
|
// err+="Invalid SALT for apk expansion.\n";
|
|
|
|
//}
|
2017-03-18 23:36:26 +00:00
|
|
|
if (apk_expansion_pkey == "") {
|
|
|
|
valid = false;
|
|
|
|
err += "Invalid public key for apk expansion.\n";
|
2014-04-29 00:56:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (r_error)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_error = err;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorExportPlatformAndroid::~EditorExportPlatformAndroid() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
quit_request = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
Thread::wait_to_finish(device_thread);
|
2015-04-20 22:38:02 +00:00
|
|
|
memdelete(device_lock);
|
|
|
|
memdelete(device_thread);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void register_android_exporter() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String exe_ext = OS::get_singleton()->get_name() == "Windows" ? "exe" : "";
|
|
|
|
EDITOR_DEF("android/adb", "");
|
|
|
|
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "android/adb", PROPERTY_HINT_GLOBAL_FILE, exe_ext));
|
|
|
|
EDITOR_DEF("android/jarsigner", "");
|
|
|
|
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "android/jarsigner", PROPERTY_HINT_GLOBAL_FILE, exe_ext));
|
|
|
|
EDITOR_DEF("android/debug_keystore", "");
|
|
|
|
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "android/debug_keystore", PROPERTY_HINT_GLOBAL_FILE, "keystore"));
|
|
|
|
EDITOR_DEF("android/debug_keystore_user", "androiddebugkey");
|
|
|
|
EDITOR_DEF("android/debug_keystore_pass", "android");
|
2014-02-10 01:10:30 +00:00
|
|
|
//EDITOR_DEF("android/release_keystore","");
|
|
|
|
//EDITOR_DEF("android/release_username","");
|
|
|
|
//EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"android/release_keystore",PROPERTY_HINT_GLOBAL_FILE,"*.keystore"));
|
2017-07-27 15:25:09 +00:00
|
|
|
EDITOR_DEF("android/force_system_user", false);
|
2017-03-18 23:36:26 +00:00
|
|
|
EDITOR_DEF("android/timestamping_authority_url", "");
|
|
|
|
EDITOR_DEF("android/shutdown_adb_on_exit", true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<EditorExportPlatformAndroid> exporter = Ref<EditorExportPlatformAndroid>(memnew(EditorExportPlatformAndroid));
|
2014-02-10 01:10:30 +00:00
|
|
|
EditorImportExport::get_singleton()->add_export_platform(exporter);
|
|
|
|
}
|