export.cpp 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925
  1. #include "version.h"
  2. #include "export.h"
  3. #include "tools/editor/editor_settings.h"
  4. #include "tools/editor/editor_import_export.h"
  5. #include "tools/editor/editor_node.h"
  6. #include "io/zip_io.h"
  7. #include "io/marshalls.h"
  8. #include "globals.h"
  9. #include "os/file_access.h"
  10. #include "os/os.h"
  11. #include "platform/android/logo.h"
  12. #include <string.h>
  13. static const char* android_perms[]={
  14. "ACCESS_CHECKIN_PROPERTIES",
  15. "ACCESS_COARSE_LOCATION",
  16. "ACCESS_FINE_LOCATION",
  17. "ACCESS_LOCATION_EXTRA_COMMANDS",
  18. "ACCESS_MOCK_LOCATION",
  19. "ACCESS_NETWORK_STATE",
  20. "ACCESS_SURFACE_FLINGER",
  21. "ACCESS_WIFI_STATE",
  22. "ACCOUNT_MANAGER",
  23. "ADD_VOICEMAIL",
  24. "AUTHENTICATE_ACCOUNTS",
  25. "BATTERY_STATS",
  26. "BIND_ACCESSIBILITY_SERVICE",
  27. "BIND_APPWIDGET",
  28. "BIND_DEVICE_ADMIN",
  29. "BIND_INPUT_METHOD",
  30. "BIND_NFC_SERVICE",
  31. "BIND_NOTIFICATION_LISTENER_SERVICE",
  32. "BIND_PRINT_SERVICE",
  33. "BIND_REMOTEVIEWS",
  34. "BIND_TEXT_SERVICE",
  35. "BIND_VPN_SERVICE",
  36. "BIND_WALLPAPER",
  37. "BLUETOOTH",
  38. "BLUETOOTH_ADMIN",
  39. "BLUETOOTH_PRIVILEGED",
  40. "BRICK",
  41. "BROADCAST_PACKAGE_REMOVED",
  42. "BROADCAST_SMS",
  43. "BROADCAST_STICKY",
  44. "BROADCAST_WAP_PUSH",
  45. "CALL_PHONE",
  46. "CALL_PRIVILEGED",
  47. "CAMERA",
  48. "CAPTURE_AUDIO_OUTPUT",
  49. "CAPTURE_SECURE_VIDEO_OUTPUT",
  50. "CAPTURE_VIDEO_OUTPUT",
  51. "CHANGE_COMPONENT_ENABLED_STATE",
  52. "CHANGE_CONFIGURATION",
  53. "CHANGE_NETWORK_STATE",
  54. "CHANGE_WIFI_MULTICAST_STATE",
  55. "CHANGE_WIFI_STATE",
  56. "CLEAR_APP_CACHE",
  57. "CLEAR_APP_USER_DATA",
  58. "CONTROL_LOCATION_UPDATES",
  59. "DELETE_CACHE_FILES",
  60. "DELETE_PACKAGES",
  61. "DEVICE_POWER",
  62. "DIAGNOSTIC",
  63. "DISABLE_KEYGUARD",
  64. "DUMP",
  65. "EXPAND_STATUS_BAR",
  66. "FACTORY_TEST",
  67. "FLASHLIGHT",
  68. "FORCE_BACK",
  69. "GET_ACCOUNTS",
  70. "GET_PACKAGE_SIZE",
  71. "GET_TASKS",
  72. "GET_TOP_ACTIVITY_INFO",
  73. "GLOBAL_SEARCH",
  74. "HARDWARE_TEST",
  75. "INJECT_EVENTS",
  76. "INSTALL_LOCATION_PROVIDER",
  77. "INSTALL_PACKAGES",
  78. "INSTALL_SHORTCUT",
  79. "INTERNAL_SYSTEM_WINDOW",
  80. "INTERNET",
  81. "KILL_BACKGROUND_PROCESSES",
  82. "LOCATION_HARDWARE",
  83. "MANAGE_ACCOUNTS",
  84. "MANAGE_APP_TOKENS",
  85. "MANAGE_DOCUMENTS",
  86. "MASTER_CLEAR",
  87. "MEDIA_CONTENT_CONTROL",
  88. "MODIFY_AUDIO_SETTINGS",
  89. "MODIFY_PHONE_STATE",
  90. "MOUNT_FORMAT_FILESYSTEMS",
  91. "MOUNT_UNMOUNT_FILESYSTEMS",
  92. "NFC",
  93. "PERSISTENT_ACTIVITY",
  94. "PROCESS_OUTGOING_CALLS",
  95. "READ_CALENDAR",
  96. "READ_CALL_LOG",
  97. "READ_CONTACTS",
  98. "READ_EXTERNAL_STORAGE",
  99. "READ_FRAME_BUFFER",
  100. "READ_HISTORY_BOOKMARKS",
  101. "READ_INPUT_STATE",
  102. "READ_LOGS",
  103. "READ_PHONE_STATE",
  104. "READ_PROFILE",
  105. "READ_SMS",
  106. "READ_SOCIAL_STREAM",
  107. "READ_SYNC_SETTINGS",
  108. "READ_SYNC_STATS",
  109. "READ_USER_DICTIONARY",
  110. "REBOOT",
  111. "RECEIVE_BOOT_COMPLETED",
  112. "RECEIVE_MMS",
  113. "RECEIVE_SMS",
  114. "RECEIVE_WAP_PUSH",
  115. "RECORD_AUDIO",
  116. "REORDER_TASKS",
  117. "RESTART_PACKAGES",
  118. "SEND_RESPOND_VIA_MESSAGE",
  119. "SEND_SMS",
  120. "SET_ACTIVITY_WATCHER",
  121. "SET_ALARM",
  122. "SET_ALWAYS_FINISH",
  123. "SET_ANIMATION_SCALE",
  124. "SET_DEBUG_APP",
  125. "SET_ORIENTATION",
  126. "SET_POINTER_SPEED",
  127. "SET_PREFERRED_APPLICATIONS",
  128. "SET_PROCESS_LIMIT",
  129. "SET_TIME",
  130. "SET_TIME_ZONE",
  131. "SET_WALLPAPER",
  132. "SET_WALLPAPER_HINTS",
  133. "SIGNAL_PERSISTENT_PROCESSES",
  134. "STATUS_BAR",
  135. "SUBSCRIBED_FEEDS_READ",
  136. "SUBSCRIBED_FEEDS_WRITE",
  137. "SYSTEM_ALERT_WINDOW",
  138. "TRANSMIT_IR",
  139. "UNINSTALL_SHORTCUT",
  140. "UPDATE_DEVICE_STATS",
  141. "USE_CREDENTIALS",
  142. "USE_SIP",
  143. "VIBRATE",
  144. "WAKE_LOCK",
  145. "WRITE_APN_SETTINGS",
  146. "WRITE_CALENDAR",
  147. "WRITE_CALL_LOG",
  148. "WRITE_CONTACTS",
  149. "WRITE_EXTERNAL_STORAGE",
  150. "WRITE_GSERVICES",
  151. "WRITE_HISTORY_BOOKMARKS",
  152. "WRITE_PROFILE",
  153. "WRITE_SECURE_SETTINGS",
  154. "WRITE_SETTINGS",
  155. "WRITE_SMS",
  156. "WRITE_SOCIAL_STREAM",
  157. "WRITE_SYNC_SETTINGS",
  158. "WRITE_USER_DICTIONARY",
  159. NULL};
  160. class EditorExportPlatformAndroid : public EditorExportPlatform {
  161. OBJ_TYPE( EditorExportPlatformAndroid,EditorExportPlatform );
  162. enum {
  163. MAX_USER_PERMISSIONS=20,
  164. SCREEN_SMALL=0,
  165. SCREEN_NORMAL=1,
  166. SCREEN_LARGE=2,
  167. SCREEN_XLARGE=3,
  168. SCREEN_MAX=4
  169. };
  170. String custom_release_package;
  171. String custom_debug_package;
  172. int version_code;
  173. String version_name;
  174. String package;
  175. String name;
  176. String icon;
  177. String cmdline;
  178. bool _signed;
  179. bool apk_expansion;
  180. bool remove_prev;
  181. bool use_32_fb;
  182. bool immersive;
  183. bool export_arm;
  184. bool export_x86;
  185. String apk_expansion_salt;
  186. String apk_expansion_pkey;
  187. int orientation;
  188. String release_keystore;
  189. String release_password;
  190. String release_username;
  191. struct APKExportData {
  192. zipFile apk;
  193. EditorProgress *ep;
  194. };
  195. struct Device {
  196. String id;
  197. String name;
  198. String description;
  199. };
  200. Vector<Device> devices;
  201. bool devices_changed;
  202. Mutex *device_lock;
  203. Thread *device_thread;
  204. Ref<ImageTexture> logo;
  205. Set<String> perms;
  206. String user_perms[MAX_USER_PERMISSIONS];
  207. bool screen_support[SCREEN_MAX];
  208. volatile bool quit_request;
  209. static void _device_poll_thread(void *ud);
  210. String get_package_name();
  211. String get_project_name() const;
  212. void _fix_manifest(Vector<uint8_t>& p_manifest, bool p_give_internet);
  213. void _fix_resources(Vector<uint8_t>& p_manifest);
  214. static Error save_apk_file(void *p_userdata,const String& p_path, const Vector<uint8_t>& p_data,int p_file,int p_total);
  215. static bool _should_compress_asset(const String& p_path, const Vector<uint8_t>& p_data);
  216. protected:
  217. bool _set(const StringName& p_name, const Variant& p_value);
  218. bool _get(const StringName& p_name,Variant &r_ret) const;
  219. void _get_property_list( List<PropertyInfo> *p_list) const;
  220. public:
  221. virtual String get_name() const { return "Android"; }
  222. virtual ImageCompression get_image_compression() const { return IMAGE_COMPRESSION_ETC1; }
  223. virtual Ref<Texture> get_logo() const { return logo; }
  224. virtual bool poll_devices();
  225. virtual int get_device_count() const;
  226. virtual String get_device_name(int p_device) const;
  227. virtual String get_device_info(int p_device) const;
  228. virtual Error run(int p_device,int p_flags=0);
  229. virtual bool requires_password(bool p_debug) const { return !p_debug; }
  230. virtual String get_binary_extension() const { return "apk"; }
  231. virtual Error export_project(const String& p_path, bool p_debug, int p_flags=0);
  232. virtual bool can_export(String *r_error=NULL) const;
  233. EditorExportPlatformAndroid();
  234. ~EditorExportPlatformAndroid();
  235. };
  236. bool EditorExportPlatformAndroid::_set(const StringName& p_name, const Variant& p_value) {
  237. String n=p_name;
  238. if (n=="one_click_deploy/clear_previous_install")
  239. remove_prev=p_value;
  240. else if (n=="custom_package/debug")
  241. custom_debug_package=p_value;
  242. else if (n=="custom_package/release")
  243. custom_release_package=p_value;
  244. else if (n=="version/code")
  245. version_code=p_value;
  246. else if (n=="version/name")
  247. version_name=p_value;
  248. else if (n=="command_line/extra_args")
  249. cmdline=p_value;
  250. else if (n=="package/unique_name")
  251. package=p_value;
  252. else if (n=="package/name")
  253. name=p_value;
  254. else if (n=="package/icon")
  255. icon=p_value;
  256. else if (n=="package/signed")
  257. _signed=p_value;
  258. else if (n=="architecture/arm")
  259. export_arm=p_value;
  260. else if (n=="architecture/x86")
  261. export_x86=p_value;
  262. else if (n=="screen/use_32_bits_view")
  263. use_32_fb=p_value;
  264. else if (n=="screen/immersive_mode")
  265. immersive=p_value;
  266. else if (n=="screen/orientation")
  267. orientation=p_value;
  268. else if (n=="screen/support_small")
  269. screen_support[SCREEN_SMALL]=p_value;
  270. else if (n=="screen/support_normal")
  271. screen_support[SCREEN_NORMAL]=p_value;
  272. else if (n=="screen/support_large")
  273. screen_support[SCREEN_LARGE]=p_value;
  274. else if (n=="screen/support_xlarge")
  275. screen_support[SCREEN_XLARGE]=p_value;
  276. else if (n=="keystore/release")
  277. release_keystore=p_value;
  278. else if (n=="keystore/release_user")
  279. release_username=p_value;
  280. else if (n=="keystore/release_password")
  281. release_password=p_value;
  282. else if (n=="apk_expansion/enable")
  283. apk_expansion=p_value;
  284. else if (n=="apk_expansion/SALT")
  285. apk_expansion_salt=p_value;
  286. else if (n=="apk_expansion/public_key")
  287. apk_expansion_pkey=p_value;
  288. else if (n.begins_with("permissions/")) {
  289. String what = n.get_slicec('/',1).to_upper();
  290. bool state = p_value;
  291. if (state)
  292. perms.insert(what);
  293. else
  294. perms.erase(what);
  295. } else if (n.begins_with("user_permissions/")) {
  296. int which = n.get_slicec('/',1).to_int();
  297. ERR_FAIL_INDEX_V(which,MAX_USER_PERMISSIONS,false);
  298. user_perms[which]=p_value;
  299. } else
  300. return false;
  301. return true;
  302. }
  303. bool EditorExportPlatformAndroid::_get(const StringName& p_name,Variant &r_ret) const{
  304. String n=p_name;
  305. if (n=="one_click_deploy/clear_previous_install")
  306. r_ret=remove_prev;
  307. else if (n=="custom_package/debug")
  308. r_ret=custom_debug_package;
  309. else if (n=="custom_package/release")
  310. r_ret=custom_release_package;
  311. else if (n=="version/code")
  312. r_ret=version_code;
  313. else if (n=="version/name")
  314. r_ret=version_name;
  315. else if (n=="command_line/extra_args")
  316. r_ret=cmdline;
  317. else if (n=="package/unique_name")
  318. r_ret=package;
  319. else if (n=="package/name")
  320. r_ret=name;
  321. else if (n=="package/icon")
  322. r_ret=icon;
  323. else if (n=="package/signed")
  324. r_ret=_signed;
  325. else if (n=="architecture/arm")
  326. r_ret=export_arm;
  327. else if (n=="architecture/x86")
  328. r_ret=export_x86;
  329. else if (n=="screen/use_32_bits_view")
  330. r_ret=use_32_fb;
  331. else if (n=="screen/immersive_mode")
  332. r_ret=immersive;
  333. else if (n=="screen/orientation")
  334. r_ret=orientation;
  335. else if (n=="screen/support_small")
  336. r_ret=screen_support[SCREEN_SMALL];
  337. else if (n=="screen/support_normal")
  338. r_ret=screen_support[SCREEN_NORMAL];
  339. else if (n=="screen/support_large")
  340. r_ret=screen_support[SCREEN_LARGE];
  341. else if (n=="screen/support_xlarge")
  342. r_ret=screen_support[SCREEN_XLARGE];
  343. else if (n=="keystore/release")
  344. r_ret=release_keystore;
  345. else if (n=="keystore/release_user")
  346. r_ret=release_username;
  347. else if (n=="keystore/release_password")
  348. r_ret=release_password;
  349. else if (n=="apk_expansion/enable")
  350. r_ret=apk_expansion;
  351. else if (n=="apk_expansion/SALT")
  352. r_ret=apk_expansion_salt;
  353. else if (n=="apk_expansion/public_key")
  354. r_ret=apk_expansion_pkey;
  355. else if (n.begins_with("permissions/")) {
  356. String what = n.get_slicec('/',1).to_upper();
  357. r_ret = perms.has(what);
  358. } else if (n.begins_with("user_permissions/")) {
  359. int which = n.get_slicec('/',1).to_int();
  360. ERR_FAIL_INDEX_V(which,MAX_USER_PERMISSIONS,false);
  361. r_ret=user_perms[which];
  362. } else
  363. return false;
  364. return true;
  365. }
  366. void EditorExportPlatformAndroid::_get_property_list( List<PropertyInfo> *p_list) const{
  367. p_list->push_back( PropertyInfo( Variant::BOOL, "one_click_deploy/clear_previous_install"));
  368. p_list->push_back( PropertyInfo( Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE,"apk"));
  369. p_list->push_back( PropertyInfo( Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE,"apk"));
  370. p_list->push_back( PropertyInfo( Variant::STRING, "command_line/extra_args"));
  371. p_list->push_back( PropertyInfo( Variant::INT, "version/code", PROPERTY_HINT_RANGE,"1,65535,1"));
  372. p_list->push_back( PropertyInfo( Variant::STRING, "version/name") );
  373. p_list->push_back( PropertyInfo( Variant::STRING, "package/unique_name") );
  374. p_list->push_back( PropertyInfo( Variant::STRING, "package/name") );
  375. p_list->push_back( PropertyInfo( Variant::STRING, "package/icon",PROPERTY_HINT_FILE,"png") );
  376. p_list->push_back( PropertyInfo( Variant::BOOL, "package/signed") );
  377. p_list->push_back( PropertyInfo( Variant::BOOL, "architecture/arm") );
  378. p_list->push_back( PropertyInfo( Variant::BOOL, "architecture/x86") );
  379. p_list->push_back( PropertyInfo( Variant::BOOL, "screen/use_32_bits_view") );
  380. p_list->push_back( PropertyInfo( Variant::BOOL, "screen/immersive_mode") );
  381. p_list->push_back( PropertyInfo( Variant::INT, "screen/orientation",PROPERTY_HINT_ENUM,"Landscape,Portrait") );
  382. p_list->push_back( PropertyInfo( Variant::BOOL, "screen/support_small") );
  383. p_list->push_back( PropertyInfo( Variant::BOOL, "screen/support_normal") );
  384. p_list->push_back( PropertyInfo( Variant::BOOL, "screen/support_large") );
  385. p_list->push_back( PropertyInfo( Variant::BOOL, "screen/support_xlarge") );
  386. p_list->push_back( PropertyInfo( Variant::STRING, "keystore/release",PROPERTY_HINT_GLOBAL_FILE,"keystore") );
  387. p_list->push_back( PropertyInfo( Variant::STRING, "keystore/release_user" ) );
  388. p_list->push_back( PropertyInfo( Variant::STRING, "keystore/release_password" ) );
  389. p_list->push_back( PropertyInfo( Variant::BOOL, "apk_expansion/enable" ) );
  390. p_list->push_back( PropertyInfo( Variant::STRING, "apk_expansion/SALT" ) );
  391. p_list->push_back( PropertyInfo( Variant::STRING, "apk_expansion/public_key",PROPERTY_HINT_MULTILINE_TEXT ) );
  392. const char **perms = android_perms;
  393. while(*perms) {
  394. p_list->push_back( PropertyInfo( Variant::BOOL, "permissions/"+String(*perms).to_lower()));
  395. perms++;
  396. }
  397. for(int i=0;i<MAX_USER_PERMISSIONS;i++) {
  398. p_list->push_back( PropertyInfo( Variant::STRING, "user_permissions/"+itos(i)));
  399. }
  400. //p_list->push_back( PropertyInfo( Variant::INT, "resources/pack_mode", PROPERTY_HINT_ENUM,"Copy,Single Exec.,Pack (.pck),Bundles (Optical)"));
  401. }
  402. static String _parse_string(const uint8_t *p_bytes,bool p_utf8) {
  403. uint32_t offset=0;
  404. uint32_t len = decode_uint16(&p_bytes[offset]);
  405. if (p_utf8) {
  406. //don't know how to read extended utf8, this will have to be for now
  407. len>>=8;
  408. }
  409. offset+=2;
  410. //printf("len %i, unicode: %i\n",len,int(p_utf8));
  411. if (p_utf8) {
  412. Vector<uint8_t> str8;
  413. str8.resize(len+1);
  414. for(int i=0;i<len;i++) {
  415. str8[i]=p_bytes[offset+i];
  416. }
  417. str8[len]=0;
  418. String str;
  419. str.parse_utf8((const char*)str8.ptr());
  420. return str;
  421. } else {
  422. String str;
  423. for(int i=0;i<len;i++) {
  424. CharType c = decode_uint16(&p_bytes[offset+i*2]);
  425. if (c==0)
  426. break;
  427. str += String::chr(c);
  428. }
  429. return str;
  430. }
  431. }
  432. void EditorExportPlatformAndroid::_fix_resources(Vector<uint8_t>& p_manifest) {
  433. const int UTF8_FLAG = 0x00000100;
  434. print_line("*******************GORRRGLE***********************");
  435. uint32_t header = decode_uint32(&p_manifest[0]);
  436. uint32_t filesize = decode_uint32(&p_manifest[4]);
  437. uint32_t string_block_len = decode_uint32(&p_manifest[16]);
  438. uint32_t string_count = decode_uint32(&p_manifest[20]);
  439. uint32_t string_flags = decode_uint32(&p_manifest[28]);
  440. const uint32_t string_table_begins = 40;
  441. Vector<String> string_table;
  442. printf("stirng block len: %i\n",string_block_len);
  443. printf("stirng count: %i\n",string_count);
  444. printf("flags: %x\n",string_flags);
  445. for(int i=0;i<string_count;i++) {
  446. uint32_t offset = decode_uint32(&p_manifest[string_table_begins+i*4]);
  447. offset+=string_table_begins+string_count*4;
  448. String str = _parse_string(&p_manifest[offset],string_flags&UTF8_FLAG);
  449. if (str.begins_with("godot-project-name")) {
  450. if (str=="godot-project-name") {
  451. //project name
  452. str = get_project_name();
  453. } else {
  454. String lang = str.substr(str.find_last("-")+1,str.length()).replace("-","_");
  455. String prop = "application/name_"+lang;
  456. if (Globals::get_singleton()->has(prop)) {
  457. str = Globals::get_singleton()->get(prop);
  458. } else {
  459. str = get_project_name();
  460. }
  461. }
  462. }
  463. string_table.push_back(str);
  464. }
  465. //write a new string table, but use 16 bits
  466. Vector<uint8_t> ret;
  467. ret.resize(string_table_begins+string_table.size()*4);
  468. for(int i=0;i<string_table_begins;i++) {
  469. ret[i]=p_manifest[i];
  470. }
  471. int ofs=0;
  472. for(int i=0;i<string_table.size();i++) {
  473. encode_uint32(ofs,&ret[string_table_begins+i*4]);
  474. ofs+=string_table[i].length()*2+2+2;
  475. }
  476. ret.resize(ret.size()+ofs);
  477. uint8_t *chars=&ret[ret.size()-ofs];
  478. for(int i=0;i<string_table.size();i++) {
  479. String s = string_table[i];
  480. encode_uint16(s.length(),chars);
  481. chars+=2;
  482. for(int j=0;j<s.length();j++) {
  483. encode_uint16(s[j],chars);
  484. chars+=2;
  485. }
  486. encode_uint16(0,chars);
  487. chars+=2;
  488. }
  489. //pad
  490. while(ret.size()%4)
  491. ret.push_back(0);
  492. //change flags to not use utf8
  493. encode_uint32(string_flags&~0x100,&ret[28]);
  494. //change length
  495. encode_uint32(ret.size()-12,&ret[16]);
  496. //append the rest...
  497. int rest_from = 12+string_block_len;
  498. int rest_to = ret.size();
  499. int rest_len = (p_manifest.size() - rest_from);
  500. ret.resize(ret.size() + (p_manifest.size() - rest_from) );
  501. for(int i=0;i<rest_len;i++) {
  502. ret[rest_to+i]=p_manifest[rest_from+i];
  503. }
  504. //finally update the size
  505. encode_uint32(ret.size(),&ret[4]);
  506. p_manifest=ret;
  507. printf("end\n");
  508. }
  509. String EditorExportPlatformAndroid::get_project_name() const {
  510. String aname;
  511. if (this->name!="") {
  512. aname=this->name;
  513. } else {
  514. aname = Globals::get_singleton()->get("application/name");
  515. }
  516. if (aname=="") {
  517. aname=_MKSTR(VERSION_NAME);
  518. }
  519. return aname;
  520. }
  521. void EditorExportPlatformAndroid::_fix_manifest(Vector<uint8_t>& p_manifest,bool p_give_internet) {
  522. const int CHUNK_AXML_FILE = 0x00080003;
  523. const int CHUNK_RESOURCEIDS = 0x00080180;
  524. const int CHUNK_STRINGS = 0x001C0001;
  525. const int CHUNK_XML_END_NAMESPACE = 0x00100101;
  526. const int CHUNK_XML_END_TAG = 0x00100103;
  527. const int CHUNK_XML_START_NAMESPACE = 0x00100100;
  528. const int CHUNK_XML_START_TAG = 0x00100102;
  529. const int CHUNK_XML_TEXT = 0x00100104;
  530. const int UTF8_FLAG = 0x00000100;
  531. Vector<String> string_table;
  532. uint32_t ofs=0;
  533. uint32_t header = decode_uint32(&p_manifest[ofs]);
  534. uint32_t filesize = decode_uint32(&p_manifest[ofs+4]);
  535. ofs+=8;
  536. // print_line("FILESIZE: "+itos(filesize)+" ACTUAL: "+itos(p_manifest.size()));
  537. uint32_t string_count;
  538. uint32_t styles_count;
  539. uint32_t string_flags;
  540. uint32_t string_data_offset;
  541. uint32_t styles_offset;
  542. uint32_t string_table_begins;
  543. uint32_t string_table_ends;
  544. Vector<uint8_t> stable_extra;
  545. while(ofs < p_manifest.size()) {
  546. uint32_t chunk = decode_uint32(&p_manifest[ofs]);
  547. uint32_t size = decode_uint32(&p_manifest[ofs+4]);
  548. switch(chunk) {
  549. case CHUNK_STRINGS: {
  550. int iofs=ofs+8;
  551. string_count=decode_uint32(&p_manifest[iofs]);
  552. styles_count=decode_uint32(&p_manifest[iofs+4]);
  553. uint32_t string_flags=decode_uint32(&p_manifest[iofs+8]);
  554. string_data_offset=decode_uint32(&p_manifest[iofs+12]);
  555. styles_offset=decode_uint32(&p_manifest[iofs+16]);
  556. /*
  557. printf("string count: %i\n",string_count);
  558. printf("flags: %i\n",string_flags);
  559. printf("sdata ofs: %i\n",string_data_offset);
  560. printf("styles ofs: %i\n",styles_offset);
  561. */
  562. uint32_t st_offset=iofs+20;
  563. string_table.resize(string_count);
  564. uint32_t string_end=0;
  565. string_table_begins=st_offset;
  566. for(int i=0;i<string_count;i++) {
  567. uint32_t string_at = decode_uint32(&p_manifest[st_offset+i*4]);
  568. string_at+=st_offset+string_count*4;
  569. ERR_EXPLAIN("Unimplemented, can't read utf8 string table.");
  570. ERR_FAIL_COND(string_flags&UTF8_FLAG);
  571. if (string_flags&UTF8_FLAG) {
  572. } else {
  573. uint32_t len = decode_uint16(&p_manifest[string_at]);
  574. Vector<CharType> ucstring;
  575. ucstring.resize(len+1);
  576. for(int j=0;j<len;j++) {
  577. uint16_t c=decode_uint16(&p_manifest[string_at+2+2*j]);
  578. ucstring[j]=c;
  579. }
  580. string_end=MAX(string_at+2+2*len,string_end);
  581. ucstring[len]=0;
  582. string_table[i]=ucstring.ptr();
  583. }
  584. // print_line("String "+itos(i)+": "+string_table[i]);
  585. }
  586. for(int i=string_end;i<(ofs+size);i++) {
  587. stable_extra.push_back(p_manifest[i]);
  588. }
  589. // printf("stable extra: %i\n",int(stable_extra.size()));
  590. string_table_ends=ofs+size;
  591. // print_line("STABLE SIZE: "+itos(size)+" ACTUAL: "+itos(string_table_ends));
  592. } break;
  593. case CHUNK_XML_START_TAG: {
  594. int iofs=ofs+8;
  595. uint32_t line=decode_uint32(&p_manifest[iofs]);
  596. uint32_t nspace=decode_uint32(&p_manifest[iofs+8]);
  597. uint32_t name=decode_uint32(&p_manifest[iofs+12]);
  598. uint32_t check=decode_uint32(&p_manifest[iofs+16]);
  599. String tname=string_table[name];
  600. // printf("NSPACE: %i\n",nspace);
  601. //printf("NAME: %i (%s)\n",name,tname.utf8().get_data());
  602. //printf("CHECK: %x\n",check);
  603. uint32_t attrcount=decode_uint32(&p_manifest[iofs+20]);
  604. iofs+=28;
  605. //printf("ATTRCOUNT: %x\n",attrcount);
  606. for(int i=0;i<attrcount;i++) {
  607. uint32_t attr_nspace=decode_uint32(&p_manifest[iofs]);
  608. uint32_t attr_name=decode_uint32(&p_manifest[iofs+4]);
  609. uint32_t attr_value=decode_uint32(&p_manifest[iofs+8]);
  610. uint32_t attr_flags=decode_uint32(&p_manifest[iofs+12]);
  611. uint32_t attr_resid=decode_uint32(&p_manifest[iofs+16]);
  612. String value;
  613. if (attr_value!=0xFFFFFFFF)
  614. value=string_table[attr_value];
  615. else
  616. value="Res #"+itos(attr_resid);
  617. String attrname = string_table[attr_name];
  618. String nspace;
  619. if (attr_nspace!=0xFFFFFFFF)
  620. nspace=string_table[attr_nspace];
  621. else
  622. nspace="";
  623. printf("ATTR %i NSPACE: %i\n",i,attr_nspace);
  624. printf("ATTR %i NAME: %i (%s)\n",i,attr_name,attrname.utf8().get_data());
  625. printf("ATTR %i VALUE: %i (%s)\n",i,attr_value,value.utf8().get_data());
  626. printf("ATTR %i FLAGS: %x\n",i,attr_flags);
  627. printf("ATTR %i RESID: %x\n",i,attr_resid);
  628. //replace project information
  629. if (tname=="manifest" && attrname=="package") {
  630. print_line("FOUND PACKAGE");
  631. string_table[attr_value]=get_package_name();
  632. }
  633. //print_line("tname: "+tname);
  634. //print_line("nspace: "+nspace);
  635. //print_line("attrname: "+attrname);
  636. if (tname=="manifest" && /*nspace=="android" &&*/ attrname=="versionCode") {
  637. print_line("FOUND versioncode");
  638. encode_uint32(version_code,&p_manifest[iofs+16]);
  639. }
  640. if (tname=="manifest" && /*nspace=="android" &&*/ attrname=="versionName") {
  641. print_line("FOUND versionname");
  642. if (attr_value==0xFFFFFFFF) {
  643. WARN_PRINT("Version name in a resource, should be plaintext")
  644. } else
  645. string_table[attr_value]=version_name;
  646. }
  647. if (tname=="activity" && /*nspace=="android" &&*/ attrname=="screenOrientation") {
  648. encode_uint32(orientation==0?0:1,&p_manifest[iofs+16]);
  649. /*
  650. print_line("FOUND screen orientation");
  651. if (attr_value==0xFFFFFFFF) {
  652. WARN_PRINT("Version name in a resource, should be plaintext")
  653. } else {
  654. string_table[attr_value]=(orientation==0?"landscape":"portrait");
  655. }*/
  656. }
  657. if (tname=="application" && /*nspace=="android" &&*/ attrname=="label") {
  658. print_line("FOUND application");
  659. if (attr_value==0xFFFFFFFF) {
  660. WARN_PRINT("Application name in a resource, should be plaintext (but you can ignore this).")
  661. } else {
  662. String aname = get_project_name();
  663. string_table[attr_value]=aname;
  664. }
  665. }
  666. if (tname=="activity" && /*nspace=="android" &&*/ attrname=="label") {
  667. print_line("FOUND activity name");
  668. if (attr_value==0xFFFFFFFF) {
  669. WARN_PRINT("Activity name in a resource, should be plaintext (but you can ignore this)")
  670. } else {
  671. String aname;
  672. if (this->name!="") {
  673. aname=this->name;
  674. } else {
  675. aname = Globals::get_singleton()->get("application/name");
  676. }
  677. if (aname=="") {
  678. aname=_MKSTR(VERSION_NAME);
  679. }
  680. print_line("APP NAME IS..."+aname);
  681. string_table[attr_value]=aname;
  682. }
  683. }
  684. if (tname=="uses-permission" && /*nspace=="android" &&*/ attrname=="name") {
  685. if (value.begins_with("godot.custom")) {
  686. int which = value.get_slice(".",2).to_int();
  687. if (which>=0 && which<MAX_USER_PERMISSIONS && user_perms[which].strip_edges()!="") {
  688. string_table[attr_value]=user_perms[which].strip_edges();
  689. }
  690. } else if (value.begins_with("godot.")) {
  691. String perm = value.get_slice(".",1);
  692. print_line("PERM: "+perm+" HAS: "+itos(perms.has(perm)));
  693. if (perms.has(perm) || (p_give_internet && perm=="INTERNET")) {
  694. string_table[attr_value]="android.permission."+perm;
  695. }
  696. }
  697. }
  698. if (tname=="supports-screens" ) {
  699. if (attr_value==0xFFFFFFFF) {
  700. WARN_PRINT("Screen res name in a resource, should be plaintext")
  701. } else if (attrname=="smallScreens") {
  702. encode_uint32(screen_support[SCREEN_SMALL]?0xFFFFFFFF:0,&p_manifest[iofs+16]);
  703. } else if (attrname=="mediumScreens") {
  704. encode_uint32(screen_support[SCREEN_NORMAL]?0xFFFFFFFF:0,&p_manifest[iofs+16]);
  705. } else if (attrname=="largeScreens") {
  706. encode_uint32(screen_support[SCREEN_LARGE]?0xFFFFFFFF:0,&p_manifest[iofs+16]);
  707. } else if (attrname=="xlargeScreens") {
  708. encode_uint32(screen_support[SCREEN_XLARGE]?0xFFFFFFFF:0,&p_manifest[iofs+16]);
  709. }
  710. }
  711. iofs+=20;
  712. }
  713. } break;
  714. }
  715. printf("chunk %x: size: %d\n",chunk,size);
  716. ofs+=size;
  717. }
  718. printf("end\n");
  719. //create new andriodmanifest binary
  720. Vector<uint8_t> ret;
  721. ret.resize(string_table_begins+string_table.size()*4);
  722. for(int i=0;i<string_table_begins;i++) {
  723. ret[i]=p_manifest[i];
  724. }
  725. ofs=0;
  726. for(int i=0;i<string_table.size();i++) {
  727. encode_uint32(ofs,&ret[string_table_begins+i*4]);
  728. ofs+=string_table[i].length()*2+2+2;
  729. print_line("ofs: "+itos(i)+": "+itos(ofs));
  730. }
  731. ret.resize(ret.size()+ofs);
  732. uint8_t *chars=&ret[ret.size()-ofs];
  733. for(int i=0;i<string_table.size();i++) {
  734. String s = string_table[i];
  735. print_line("savint string :"+s);
  736. encode_uint16(s.length(),chars);
  737. chars+=2;
  738. for(int j=0;j<s.length();j++) { //include zero?
  739. encode_uint16(s[j],chars);
  740. chars+=2;
  741. }
  742. encode_uint16(0,chars);
  743. chars+=2;
  744. }
  745. ret.resize(ret.size()+stable_extra.size());
  746. while(ret.size()%4)
  747. ret.push_back(0);
  748. for(int i=0;i<stable_extra.size();i++) {
  749. chars[i]=stable_extra[i];
  750. }
  751. uint32_t new_stable_end=ret.size();
  752. uint32_t extra = (p_manifest.size()-string_table_ends);
  753. ret.resize(new_stable_end + extra);
  754. for(int i=0;i<extra;i++)
  755. ret[new_stable_end+i]=p_manifest[string_table_ends+i];
  756. while(ret.size()%4)
  757. ret.push_back(0);
  758. encode_uint32(ret.size(),&ret[4]); //update new file size
  759. encode_uint32(new_stable_end-8,&ret[12]); //update new string table size
  760. print_line("file size: "+itos(ret.size()));
  761. p_manifest=ret;
  762. #if 0
  763. uint32_t header[9];
  764. for(int i=0;i<9;i++) {
  765. header[i]=decode_uint32(&p_manifest[i*4]);
  766. }
  767. print_line("STO: "+itos(header[3]));
  768. uint32_t st_offset=9*4;
  769. //ERR_FAIL_COND(header[3]!=0x24)
  770. uint32_t string_count=header[4];
  771. string_table.resize(string_count);
  772. for(int i=0;i<string_count;i++) {
  773. uint32_t string_at = decode_uint32(&p_manifest[st_offset+i*4]);
  774. string_at+=st_offset+string_count*4;
  775. uint32_t len = decode_uint16(&p_manifest[string_at]);
  776. Vector<CharType> ucstring;
  777. ucstring.resize(len+1);
  778. for(int j=0;j<len;j++) {
  779. uint16_t c=decode_uint16(&p_manifest[string_at+2+2*j]);
  780. ucstring[j]=c;
  781. }
  782. ucstring[len]=0;
  783. string_table[i]=ucstring.ptr();
  784. }
  785. #endif
  786. }
  787. Error EditorExportPlatformAndroid::save_apk_file(void *p_userdata,const String& p_path, const Vector<uint8_t>& p_data,int p_file,int p_total) {
  788. APKExportData *ed=(APKExportData*)p_userdata;
  789. String dst_path=p_path;
  790. dst_path=dst_path.replace_first("res://","assets/");
  791. zipOpenNewFileInZip(ed->apk,
  792. dst_path.utf8().get_data(),
  793. NULL,
  794. NULL,
  795. 0,
  796. NULL,
  797. 0,
  798. NULL,
  799. _should_compress_asset(p_path,p_data) ? Z_DEFLATED : 0,
  800. Z_DEFAULT_COMPRESSION);
  801. zipWriteInFileInZip(ed->apk,p_data.ptr(),p_data.size());
  802. zipCloseFileInZip(ed->apk);
  803. ed->ep->step("File: "+p_path,3+p_file*100/p_total);
  804. return OK;
  805. }
  806. bool EditorExportPlatformAndroid::_should_compress_asset(const String& p_path, const Vector<uint8_t>& p_data) {
  807. /*
  808. * By not compressing files with little or not benefit in doing so,
  809. * a performance gain is expected at runtime. Moreover, if the APK is
  810. * zip-aligned, assets stored as they are can be efficiently read by
  811. * Android by memory-mapping them.
  812. */
  813. // -- Unconditional uncompress to mimic AAPT plus some other
  814. static const char* unconditional_compress_ext[] = {
  815. // From https://github.com/android/platform_frameworks_base/blob/master/tools/aapt/Package.cpp
  816. // These formats are already compressed, or don't compress well:
  817. ".jpg", ".jpeg", ".png", ".gif",
  818. ".wav", ".mp2", ".mp3", ".ogg", ".aac",
  819. ".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet",
  820. ".rtttl", ".imy", ".xmf", ".mp4", ".m4a",
  821. ".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2",
  822. ".amr", ".awb", ".wma", ".wmv",
  823. // Godot-specific:
  824. ".webp", // Same reasoning as .png
  825. ".cfb", // Don't let small config files slow-down startup
  826. // Trailer for easier processing
  827. NULL
  828. };
  829. for (const char** ext=unconditional_compress_ext; *ext; ++ext) {
  830. if (p_path.to_lower().ends_with(String(*ext))) {
  831. return false;
  832. }
  833. }
  834. // -- Compressed resource?
  835. if (p_data.size() >= 4 && p_data[0]=='R' && p_data[1]=='S' && p_data[2]=='C' && p_data[3]=='C') {
  836. // Already compressed
  837. return false;
  838. }
  839. // --- TODO: Decide on texture resources according to their image compression setting
  840. return true;
  841. }
  842. Error EditorExportPlatformAndroid::export_project(const String& p_path, bool p_debug, int p_flags) {
  843. String src_apk;
  844. EditorProgress ep("export","Exporting for Android",105);
  845. if (p_debug)
  846. src_apk=custom_debug_package;
  847. else
  848. src_apk=custom_release_package;
  849. if (src_apk=="") {
  850. String err;
  851. if (p_debug) {
  852. src_apk=find_export_template("android_debug.apk", &err);
  853. } else {
  854. src_apk=find_export_template("android_release.apk", &err);
  855. }
  856. if (src_apk=="") {
  857. EditorNode::add_io_error(err);
  858. return ERR_FILE_NOT_FOUND;
  859. }
  860. }
  861. FileAccess *src_f=NULL;
  862. zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
  863. ep.step("Creating APK",0);
  864. unzFile pkg = unzOpen2(src_apk.utf8().get_data(), &io);
  865. if (!pkg) {
  866. EditorNode::add_io_error("Could not find template APK to export:\n"+src_apk);
  867. return ERR_FILE_NOT_FOUND;
  868. }
  869. ERR_FAIL_COND_V(!pkg, ERR_CANT_OPEN);
  870. int ret = unzGoToFirstFile(pkg);
  871. zlib_filefunc_def io2=io;
  872. FileAccess *dst_f=NULL;
  873. io2.opaque=&dst_f;
  874. String unaligned_path=EditorSettings::get_singleton()->get_settings_path()+"/tmp/tmpexport-unaligned.apk";
  875. zipFile unaligned_apk=zipOpen2(unaligned_path.utf8().get_data(),APPEND_STATUS_CREATE,NULL,&io2);
  876. while(ret==UNZ_OK) {
  877. //get filename
  878. unz_file_info info;
  879. char fname[16384];
  880. ret = unzGetCurrentFileInfo(pkg,&info,fname,16384,NULL,0,NULL,0);
  881. bool skip=false;
  882. String file=fname;
  883. Vector<uint8_t> data;
  884. data.resize(info.uncompressed_size);
  885. //read
  886. unzOpenCurrentFile(pkg);
  887. unzReadCurrentFile(pkg,data.ptr(),data.size());
  888. unzCloseCurrentFile(pkg);
  889. //write
  890. if (file=="AndroidManifest.xml") {
  891. _fix_manifest(data,p_flags&(EXPORT_DUMB_CLIENT|EXPORT_REMOTE_DEBUG));
  892. }
  893. if (file=="resources.arsc") {
  894. _fix_resources(data);
  895. }
  896. if (file=="res/drawable/icon.png") {
  897. bool found=false;
  898. if (this->icon!="" && this->icon.ends_with(".png")) {
  899. FileAccess *f = FileAccess::open(this->icon,FileAccess::READ);
  900. if (f) {
  901. data.resize(f->get_len());
  902. f->get_buffer(data.ptr(),data.size());
  903. memdelete(f);
  904. found=true;
  905. }
  906. }
  907. if (!found) {
  908. String appicon = Globals::get_singleton()->get("application/icon");
  909. if (appicon!="" && appicon.ends_with(".png")) {
  910. FileAccess*f = FileAccess::open(appicon,FileAccess::READ);
  911. if (f) {
  912. data.resize(f->get_len());
  913. f->get_buffer(data.ptr(),data.size());
  914. memdelete(f);
  915. }
  916. }
  917. }
  918. }
  919. if (file=="lib/x86/libgodot_android.so" && !export_x86) {
  920. skip=true;
  921. }
  922. if (file=="lib/armeabi/libgodot_android.so" && !export_arm) {
  923. skip=true;
  924. }
  925. if (file.begins_with("META-INF") && _signed) {
  926. skip=true;
  927. }
  928. print_line("ADDING: "+file);
  929. if (!skip) {
  930. // Respect decision on compression made by AAPT for the export template
  931. const bool uncompressed = info.compression_method == 0;
  932. zipOpenNewFileInZip(unaligned_apk,
  933. file.utf8().get_data(),
  934. NULL,
  935. NULL,
  936. 0,
  937. NULL,
  938. 0,
  939. NULL,
  940. uncompressed ? 0 : Z_DEFLATED,
  941. Z_DEFAULT_COMPRESSION);
  942. zipWriteInFileInZip(unaligned_apk,data.ptr(),data.size());
  943. zipCloseFileInZip(unaligned_apk);
  944. }
  945. ret = unzGoToNextFile(pkg);
  946. }
  947. ep.step("Adding Files..",1);
  948. Error err=OK;
  949. Vector<String> cl = cmdline.strip_edges().split(" ");
  950. for(int i=0;i<cl.size();i++) {
  951. if (cl[i].strip_edges().length()==0) {
  952. cl.remove(i);
  953. i--;
  954. }
  955. }
  956. gen_export_flags(cl,p_flags);
  957. if (p_flags&EXPORT_DUMB_CLIENT) {
  958. /*String host = EditorSettings::get_singleton()->get("file_server/host");
  959. int port = EditorSettings::get_singleton()->get("file_server/post");
  960. String passwd = EditorSettings::get_singleton()->get("file_server/password");
  961. cl.push_back("-rfs");
  962. cl.push_back(host+":"+itos(port));
  963. if (passwd!="") {
  964. cl.push_back("-rfs_pass");
  965. cl.push_back(passwd);
  966. }*/
  967. } else {
  968. //all files
  969. if (apk_expansion) {
  970. String apkfname="main."+itos(version_code)+"."+get_package_name()+".obb";
  971. String fullpath=p_path.get_base_dir().plus_file(apkfname);
  972. FileAccess *pf = FileAccess::open(fullpath,FileAccess::WRITE);
  973. if (!pf) {
  974. EditorNode::add_io_error("Could not write expansion package file: "+apkfname);
  975. return OK;
  976. }
  977. err = save_pack(pf);
  978. memdelete(pf);
  979. cl.push_back("-use_apk_expansion");
  980. cl.push_back("-apk_expansion_md5");
  981. cl.push_back(FileAccess::get_md5(fullpath));
  982. cl.push_back("-apk_expansion_key");
  983. cl.push_back(apk_expansion_pkey.strip_edges());
  984. } else {
  985. APKExportData ed;
  986. ed.ep=&ep;
  987. ed.apk=unaligned_apk;
  988. err = export_project_files(save_apk_file,&ed,false);
  989. }
  990. }
  991. if (use_32_fb)
  992. cl.push_back("-use_depth_32");
  993. if (immersive)
  994. cl.push_back("-use_immersive");
  995. if (cl.size()) {
  996. //add comandline
  997. Vector<uint8_t> clf;
  998. clf.resize(4);
  999. encode_uint32(cl.size(),&clf[0]);
  1000. for(int i=0;i<cl.size();i++) {
  1001. CharString txt = cl[i].utf8();
  1002. int base = clf.size();
  1003. clf.resize(base+4+txt.length());
  1004. encode_uint32(txt.length(),&clf[base]);
  1005. copymem(&clf[base+4],txt.ptr(),txt.length());
  1006. print_line(itos(i)+" param: "+cl[i]);
  1007. }
  1008. zipOpenNewFileInZip(unaligned_apk,
  1009. "assets/_cl_",
  1010. NULL,
  1011. NULL,
  1012. 0,
  1013. NULL,
  1014. 0,
  1015. NULL,
  1016. 0, // No compress (little size gain and potentially slower startup)
  1017. Z_DEFAULT_COMPRESSION);
  1018. zipWriteInFileInZip(unaligned_apk,clf.ptr(),clf.size());
  1019. zipCloseFileInZip(unaligned_apk);
  1020. }
  1021. zipClose(unaligned_apk,NULL);
  1022. unzClose(pkg);
  1023. if (err) {
  1024. return err;
  1025. }
  1026. if (_signed) {
  1027. String jarsigner=EditorSettings::get_singleton()->get("android/jarsigner");
  1028. if (!FileAccess::exists(jarsigner)) {
  1029. EditorNode::add_io_error("'jarsigner' could not be found.\nPlease supply a path in the editor settings.\nResulting apk is unsigned.");
  1030. return OK;
  1031. }
  1032. String keystore;
  1033. String password;
  1034. String user;
  1035. if (p_debug) {
  1036. keystore=EditorSettings::get_singleton()->get("android/debug_keystore");
  1037. password=EditorSettings::get_singleton()->get("android/debug_keystore_pass");
  1038. user=EditorSettings::get_singleton()->get("android/debug_keystore_user");
  1039. ep.step("Signing Debug APK..",103);
  1040. } else {
  1041. keystore=release_keystore;
  1042. password=release_password;
  1043. user=release_username;
  1044. ep.step("Signing Release APK..",103);
  1045. }
  1046. if (!FileAccess::exists(keystore)) {
  1047. EditorNode::add_io_error("Could not find keystore, unable to export.");
  1048. return ERR_FILE_CANT_OPEN;
  1049. }
  1050. List<String> args;
  1051. args.push_back("-digestalg");
  1052. args.push_back("SHA1");
  1053. args.push_back("-sigalg");
  1054. args.push_back("MD5withRSA");
  1055. String tsa_url=EditorSettings::get_singleton()->get("android/timestamping_authority_url");
  1056. if (tsa_url != "") {
  1057. args.push_back("-tsa");
  1058. args.push_back(tsa_url);
  1059. }
  1060. args.push_back("-verbose");
  1061. args.push_back("-keystore");
  1062. args.push_back(keystore);
  1063. args.push_back("-storepass");
  1064. args.push_back(password);
  1065. args.push_back(unaligned_path);
  1066. args.push_back(user);
  1067. int retval;
  1068. int err = OS::get_singleton()->execute(jarsigner,args,true,NULL,NULL,&retval);
  1069. if (retval) {
  1070. EditorNode::add_io_error("'jarsigner' returned with error #"+itos(retval));
  1071. return ERR_CANT_CREATE;
  1072. }
  1073. ep.step("Verifying APK..",104);
  1074. args.clear();
  1075. args.push_back("-verify");
  1076. args.push_back(unaligned_path);
  1077. args.push_back("-verbose");
  1078. err = OS::get_singleton()->execute(jarsigner,args,true,NULL,NULL,&retval);
  1079. if (retval) {
  1080. EditorNode::add_io_error("'jarsigner' verification of APK failed. Make sure to use jarsigner from Java 6.");
  1081. return ERR_CANT_CREATE;
  1082. }
  1083. }
  1084. // Let's zip-align (must be done after signing)
  1085. static const int ZIP_ALIGNMENT = 4;
  1086. ep.step("Aligning APK..",105);
  1087. unzFile tmp_unaligned = unzOpen2(unaligned_path.utf8().get_data(), &io);
  1088. if (!tmp_unaligned) {
  1089. EditorNode::add_io_error("Could not find temp unaligned APK.");
  1090. return ERR_FILE_NOT_FOUND;
  1091. }
  1092. ERR_FAIL_COND_V(!tmp_unaligned, ERR_CANT_OPEN);
  1093. ret = unzGoToFirstFile(tmp_unaligned);
  1094. io2=io;
  1095. dst_f=NULL;
  1096. io2.opaque=&dst_f;
  1097. zipFile final_apk=zipOpen2(p_path.utf8().get_data(),APPEND_STATUS_CREATE,NULL,&io2);
  1098. // Take files from the unaligned APK and write them out to the aligned one
  1099. // in raw mode, i.e. not uncompressing and recompressing, aligning them as needed,
  1100. // following what is done in https://github.com/android/platform_build/blob/master/tools/zipalign/ZipAlign.cpp
  1101. int bias = 0;
  1102. while(ret==UNZ_OK) {
  1103. unz_file_info info;
  1104. memset(&info, 0, sizeof(info));
  1105. char fname[16384];
  1106. char extra[16384];
  1107. ret = unzGetCurrentFileInfo(tmp_unaligned,&info,fname,16384,extra,16384-ZIP_ALIGNMENT,NULL,0);
  1108. String file=fname;
  1109. Vector<uint8_t> data;
  1110. data.resize(info.compressed_size);
  1111. // read
  1112. int method, level;
  1113. unzOpenCurrentFile2(tmp_unaligned, &method, &level, 1); // raw read
  1114. long file_offset = unzGetCurrentFileZStreamPos64(tmp_unaligned);
  1115. unzReadCurrentFile(tmp_unaligned,data.ptr(),data.size());
  1116. unzCloseCurrentFile(tmp_unaligned);
  1117. // align
  1118. int padding = 0;
  1119. if (!info.compression_method) {
  1120. // Uncompressed file => Align
  1121. long new_offset = file_offset + bias;
  1122. padding = (ZIP_ALIGNMENT - (new_offset % ZIP_ALIGNMENT)) % ZIP_ALIGNMENT;
  1123. }
  1124. memset(extra + info.size_file_extra, 0, padding);
  1125. // write
  1126. zipOpenNewFileInZip2(final_apk,
  1127. file.utf8().get_data(),
  1128. NULL,
  1129. extra,
  1130. info.size_file_extra + padding,
  1131. NULL,
  1132. 0,
  1133. NULL,
  1134. method,
  1135. level,
  1136. 1); // raw write
  1137. zipWriteInFileInZip(final_apk,data.ptr(),data.size());
  1138. zipCloseFileInZipRaw(final_apk,info.uncompressed_size,info.crc);
  1139. bias += padding;
  1140. ret = unzGoToNextFile(tmp_unaligned);
  1141. }
  1142. zipClose(final_apk,NULL);
  1143. unzClose(tmp_unaligned);
  1144. if (err) {
  1145. return err;
  1146. }
  1147. return OK;
  1148. }
  1149. bool EditorExportPlatformAndroid::poll_devices() {
  1150. bool dc=devices_changed;
  1151. devices_changed=false;
  1152. return dc;
  1153. }
  1154. int EditorExportPlatformAndroid::get_device_count() const {
  1155. device_lock->lock();
  1156. int dc=devices.size();
  1157. device_lock->unlock();
  1158. return dc;
  1159. }
  1160. String EditorExportPlatformAndroid::get_device_name(int p_device) const {
  1161. ERR_FAIL_INDEX_V(p_device,devices.size(),"");
  1162. device_lock->lock();
  1163. String s=devices[p_device].name;
  1164. device_lock->unlock();
  1165. return s;
  1166. }
  1167. String EditorExportPlatformAndroid::get_device_info(int p_device) const {
  1168. ERR_FAIL_INDEX_V(p_device,devices.size(),"");
  1169. device_lock->lock();
  1170. String s=devices[p_device].description;
  1171. device_lock->unlock();
  1172. return s;
  1173. }
  1174. void EditorExportPlatformAndroid::_device_poll_thread(void *ud) {
  1175. EditorExportPlatformAndroid *ea=(EditorExportPlatformAndroid *)ud;
  1176. while(!ea->quit_request) {
  1177. String adb=EditorSettings::get_singleton()->get("android/adb");
  1178. if (FileAccess::exists(adb)) {
  1179. String devices;
  1180. List<String> args;
  1181. args.push_back("devices");
  1182. int ec;
  1183. Error err = OS::get_singleton()->execute(adb,args,true,NULL,&devices,&ec);
  1184. Vector<String> ds = devices.split("\n");
  1185. Vector<String> ldevices;
  1186. for(int i=1;i<ds.size();i++) {
  1187. String d = ds[i];
  1188. int dpos = d.find("device");
  1189. if (dpos==-1)
  1190. continue;
  1191. d=d.substr(0,dpos).strip_edges();
  1192. // print_line("found devuce: "+d);
  1193. ldevices.push_back(d);
  1194. }
  1195. ea->device_lock->lock();
  1196. bool different=false;
  1197. if (devices.size()!=ldevices.size()) {
  1198. different=true;
  1199. } else {
  1200. for(int i=0;i<ea->devices.size();i++) {
  1201. if (ea->devices[i].id!=ldevices[i]) {
  1202. different=true;
  1203. break;
  1204. }
  1205. }
  1206. }
  1207. if (different) {
  1208. Vector<Device> ndevices;
  1209. for(int i=0;i<ldevices.size();i++) {
  1210. Device d;
  1211. d.id=ldevices[i];
  1212. for(int j=0;j<ea->devices.size();j++) {
  1213. if (ea->devices[j].id==ldevices[i]) {
  1214. d.description=ea->devices[j].description;
  1215. d.name=ea->devices[j].name;
  1216. }
  1217. }
  1218. if (d.description=="") {
  1219. //in the oven, request!
  1220. args.clear();
  1221. args.push_back("-s");
  1222. args.push_back(d.id);
  1223. args.push_back("shell");
  1224. args.push_back("cat");
  1225. args.push_back("/system/build.prop");
  1226. int ec;
  1227. String dp;
  1228. Error err = OS::get_singleton()->execute(adb,args,true,NULL,&dp,&ec);
  1229. print_line("RV: "+itos(ec));
  1230. Vector<String> props = dp.split("\n");
  1231. String vendor;
  1232. String device;
  1233. d.description+"Device ID: "+d.id+"\n";
  1234. for(int j=0;j<props.size();j++) {
  1235. String p = props[j];
  1236. if (p.begins_with("ro.product.model=")) {
  1237. device=p.get_slice("=",1).strip_edges();
  1238. } else if (p.begins_with("ro.product.brand=")) {
  1239. vendor=p.get_slice("=",1).strip_edges().capitalize();
  1240. } else if (p.begins_with("ro.build.display.id=")) {
  1241. d.description+="Build: "+p.get_slice("=",1).strip_edges()+"\n";
  1242. } else if (p.begins_with("ro.build.version.release=")) {
  1243. d.description+="Release: "+p.get_slice("=",1).strip_edges()+"\n";
  1244. } else if (p.begins_with("ro.product.cpu.abi=")) {
  1245. d.description+="CPU: "+p.get_slice("=",1).strip_edges()+"\n";
  1246. } else if (p.begins_with("ro.product.manufacturer=")) {
  1247. d.description+="Manufacturer: "+p.get_slice("=",1).strip_edges()+"\n";
  1248. } else if (p.begins_with("ro.board.platform=")) {
  1249. d.description+="Chipset: "+p.get_slice("=",1).strip_edges()+"\n";
  1250. } else if (p.begins_with("ro.opengles.version=")) {
  1251. uint32_t opengl = p.get_slice("=",1).to_int();
  1252. d.description+="OpenGL: "+itos(opengl>>16)+"."+itos((opengl>>8)&0xFF)+"."+itos((opengl)&0xFF)+"\n";
  1253. }
  1254. }
  1255. d.name=vendor+" "+device;
  1256. // print_line("name: "+d.name);
  1257. // print_line("description: "+d.description);
  1258. }
  1259. ndevices.push_back(d);
  1260. }
  1261. ea->devices=ndevices;
  1262. ea->devices_changed=true;
  1263. }
  1264. ea->device_lock->unlock();
  1265. }
  1266. uint64_t wait = 3000000;
  1267. uint64_t time = OS::get_singleton()->get_ticks_usec();
  1268. while(OS::get_singleton()->get_ticks_usec() - time < wait ) {
  1269. OS::get_singleton()->delay_usec(1000);
  1270. if (ea->quit_request)
  1271. break;
  1272. }
  1273. }
  1274. if (EditorSettings::get_singleton()->get("android/shutdown_adb_on_exit")) {
  1275. String adb=EditorSettings::get_singleton()->get("android/adb");
  1276. if (!FileAccess::exists(adb)) {
  1277. return; //adb not configured
  1278. }
  1279. List<String> args;
  1280. args.push_back("kill-server");
  1281. OS::get_singleton()->execute(adb,args,true);
  1282. };
  1283. }
  1284. Error EditorExportPlatformAndroid::run(int p_device, int p_flags) {
  1285. ERR_FAIL_INDEX_V(p_device,devices.size(),ERR_INVALID_PARAMETER);
  1286. device_lock->lock();
  1287. EditorProgress ep("run","Running on "+devices[p_device].name,3);
  1288. String adb=EditorSettings::get_singleton()->get("android/adb");
  1289. if (adb=="") {
  1290. EditorNode::add_io_error("ADB executable not configured in settings, can't run.");
  1291. device_lock->unlock();
  1292. return ERR_UNCONFIGURED;
  1293. }
  1294. //export_temp
  1295. ep.step("Exporting APK",0);
  1296. bool use_adb_over_usb = bool(EDITOR_DEF("android/use_remote_debug_over_adb",true));
  1297. if (use_adb_over_usb) {
  1298. p_flags|=EXPORT_REMOTE_DEBUG_LOCALHOST;
  1299. }
  1300. String export_to=EditorSettings::get_singleton()->get_settings_path()+"/tmp/tmpexport.apk";
  1301. Error err = export_project(export_to,true,p_flags);
  1302. if (err) {
  1303. device_lock->unlock();
  1304. return err;
  1305. }
  1306. List<String> args;
  1307. int rv;
  1308. if (remove_prev) {
  1309. ep.step("Uninstalling..",1);
  1310. print_line("Uninstalling previous version: "+devices[p_device].name);
  1311. args.push_back("-s");
  1312. args.push_back(devices[p_device].id);
  1313. args.push_back("uninstall");
  1314. args.push_back(get_package_name());
  1315. err = OS::get_singleton()->execute(adb,args,true,NULL,NULL,&rv);
  1316. #if 0
  1317. if (err || rv!=0) {
  1318. EditorNode::add_io_error("Could not install to device.");
  1319. device_lock->unlock();
  1320. return ERR_CANT_CREATE;
  1321. }
  1322. #endif
  1323. }
  1324. print_line("Installing into device (please wait..): "+devices[p_device].name);
  1325. ep.step("Installing to Device (please wait..)..",2);
  1326. args.clear();
  1327. args.push_back("-s");
  1328. args.push_back(devices[p_device].id);
  1329. args.push_back("install");
  1330. args.push_back("-r");
  1331. args.push_back(export_to);
  1332. err = OS::get_singleton()->execute(adb,args,true,NULL,NULL,&rv);
  1333. if (err || rv!=0) {
  1334. EditorNode::add_io_error("Could not install to device.");
  1335. device_lock->unlock();
  1336. return ERR_CANT_CREATE;
  1337. }
  1338. if (use_adb_over_usb) {
  1339. args.clear();
  1340. args.push_back("reverse");
  1341. args.push_back("--remove-all");
  1342. err = OS::get_singleton()->execute(adb,args,true,NULL,NULL,&rv);
  1343. int port = Globals::get_singleton()->get("debug/debug_port");
  1344. args.clear();
  1345. args.push_back("reverse");
  1346. args.push_back("tcp:"+itos(port));
  1347. args.push_back("tcp:"+itos(port));
  1348. err = OS::get_singleton()->execute(adb,args,true,NULL,NULL,&rv);
  1349. print_line("Reverse result: "+itos(rv));
  1350. int fs_port = EditorSettings::get_singleton()->get("file_server/port");
  1351. args.clear();
  1352. args.push_back("reverse");
  1353. args.push_back("tcp:"+itos(fs_port));
  1354. args.push_back("tcp:"+itos(fs_port));
  1355. err = OS::get_singleton()->execute(adb,args,true,NULL,NULL,&rv);
  1356. print_line("Reverse result2: "+itos(rv));
  1357. }
  1358. ep.step("Running on Device..",3);
  1359. args.clear();
  1360. args.push_back("-s");
  1361. args.push_back(devices[p_device].id);
  1362. args.push_back("shell");
  1363. args.push_back("am");
  1364. args.push_back("start");
  1365. args.push_back("-a");
  1366. args.push_back("android.intent.action.MAIN");
  1367. args.push_back("-n");
  1368. args.push_back(get_package_name()+"/org.godotengine.godot.Godot");
  1369. err = OS::get_singleton()->execute(adb,args,true,NULL,NULL,&rv);
  1370. if (err || rv!=0) {
  1371. EditorNode::add_io_error("Could not execute ondevice.");
  1372. device_lock->unlock();
  1373. return ERR_CANT_CREATE;
  1374. }
  1375. device_lock->unlock();
  1376. return OK;
  1377. }
  1378. String EditorExportPlatformAndroid::get_package_name() {
  1379. String pname = package;
  1380. String basename = Globals::get_singleton()->get("application/name");
  1381. basename=basename.to_lower();
  1382. String name;
  1383. bool first=true;
  1384. for(int i=0;i<basename.length();i++) {
  1385. CharType c = basename[i];
  1386. if (c>='0' && c<='9' && first) {
  1387. continue;
  1388. }
  1389. if ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9')) {
  1390. name+=String::chr(c);
  1391. first=false;
  1392. }
  1393. }
  1394. if (name=="")
  1395. name="noname";
  1396. pname=pname.replace("$genname",name);
  1397. return pname;
  1398. }
  1399. EditorExportPlatformAndroid::EditorExportPlatformAndroid() {
  1400. version_code=1;
  1401. version_name="1.0";
  1402. package="org.godotengine.$genname";
  1403. name="";
  1404. _signed=true;
  1405. apk_expansion=false;
  1406. device_lock = Mutex::create();
  1407. quit_request=false;
  1408. orientation=0;
  1409. remove_prev=true;
  1410. use_32_fb=true;
  1411. immersive=true;
  1412. export_arm=true;
  1413. export_x86=false;
  1414. device_thread=Thread::create(_device_poll_thread,this);
  1415. devices_changed=true;
  1416. Image img( _android_logo );
  1417. logo = Ref<ImageTexture>( memnew( ImageTexture ));
  1418. logo->create_from_image(img);
  1419. for(int i=0;i<4;i++)
  1420. screen_support[i]=true;
  1421. }
  1422. bool EditorExportPlatformAndroid::can_export(String *r_error) const {
  1423. bool valid=true;
  1424. String adb=EditorSettings::get_singleton()->get("android/adb");
  1425. String err;
  1426. if (!FileAccess::exists(adb)) {
  1427. valid=false;
  1428. err+="ADB executable not configured in editor settings.\n";
  1429. }
  1430. String js = EditorSettings::get_singleton()->get("android/jarsigner");
  1431. if (!FileAccess::exists(js)) {
  1432. valid=false;
  1433. err+="OpenJDK 6 jarsigner not configured in editor settings.\n";
  1434. }
  1435. String dk = EditorSettings::get_singleton()->get("android/debug_keystore");
  1436. if (!FileAccess::exists(dk)) {
  1437. valid=false;
  1438. err+="Debug Keystore not configured in editor settings.\n";
  1439. }
  1440. if (!exists_export_template("android_debug.apk") || !exists_export_template("android_release.apk")) {
  1441. valid=false;
  1442. err+="No export templates found.\nDownload and install export templates.\n";
  1443. }
  1444. if (custom_debug_package!="" && !FileAccess::exists(custom_debug_package)) {
  1445. valid=false;
  1446. err+="Custom debug package not found.\n";
  1447. }
  1448. if (custom_release_package!="" && !FileAccess::exists(custom_release_package)) {
  1449. valid=false;
  1450. err+="Custom release package not found.\n";
  1451. }
  1452. if (apk_expansion) {
  1453. //if (apk_expansion_salt=="") {
  1454. // valid=false;
  1455. // err+="Invalid SALT for apk expansion.\n";
  1456. //}
  1457. if (apk_expansion_pkey=="") {
  1458. valid=false;
  1459. err+="Invalid public key for apk expansion.\n";
  1460. }
  1461. }
  1462. if (r_error)
  1463. *r_error=err;
  1464. return valid;
  1465. }
  1466. EditorExportPlatformAndroid::~EditorExportPlatformAndroid() {
  1467. quit_request=true;
  1468. Thread::wait_to_finish(device_thread);
  1469. memdelete(device_lock);
  1470. memdelete(device_thread);
  1471. }
  1472. void register_android_exporter() {
  1473. String exe_ext=OS::get_singleton()->get_name()=="Windows"?"exe":"";
  1474. EDITOR_DEF("android/adb","");
  1475. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"android/adb",PROPERTY_HINT_GLOBAL_FILE,exe_ext));
  1476. EDITOR_DEF("android/jarsigner","");
  1477. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"android/jarsigner",PROPERTY_HINT_GLOBAL_FILE,exe_ext));
  1478. EDITOR_DEF("android/debug_keystore","");
  1479. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"android/debug_keystore",PROPERTY_HINT_GLOBAL_FILE,"keystore"));
  1480. EDITOR_DEF("android/debug_keystore_user","androiddebugkey");
  1481. EDITOR_DEF("android/debug_keystore_pass","android");
  1482. //EDITOR_DEF("android/release_keystore","");
  1483. //EDITOR_DEF("android/release_username","");
  1484. //EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"android/release_keystore",PROPERTY_HINT_GLOBAL_FILE,"*.keystore"));
  1485. EDITOR_DEF("android/timestamping_authority_url","");
  1486. EDITOR_DEF("android/use_remote_debug_over_adb",false);
  1487. EDITOR_DEF("android/shutdown_adb_on_exit",true);
  1488. Ref<EditorExportPlatformAndroid> exporter = Ref<EditorExportPlatformAndroid>( memnew(EditorExportPlatformAndroid) );
  1489. EditorImportExport::get_singleton()->add_export_platform(exporter);
  1490. }