diff options
Diffstat (limited to 'platform/android/export/export.cpp')
-rw-r--r-- | platform/android/export/export.cpp | 97 |
1 files changed, 93 insertions, 4 deletions
diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 51db77595b..3b6a62898e 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -181,7 +181,11 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { String package; String name; String icon; + String cmdline; bool _signed; + bool apk_expansion; + String apk_expansion_salt; + String apk_expansion_pkey; int orientation; String release_keystore; @@ -257,6 +261,8 @@ bool EditorExportPlatformAndroid::_set(const StringName& p_name, const Variant& 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") @@ -279,6 +285,12 @@ bool EditorExportPlatformAndroid::_set(const StringName& p_name, const Variant& release_keystore=p_value; else if (n=="keystore/release_user") release_username=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; else if (n.begins_with("permissions/")) { String what = n.get_slice("/",1).to_upper(); @@ -307,6 +319,8 @@ bool EditorExportPlatformAndroid::_get(const StringName& p_name,Variant &r_ret) 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") @@ -329,6 +343,12 @@ bool EditorExportPlatformAndroid::_get(const StringName& p_name,Variant &r_ret) r_ret=release_keystore; else if (n=="keystore/release_user") r_ret=release_username; + 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; else if (n.begins_with("permissions/")) { String what = n.get_slice("/",1).to_upper(); @@ -348,6 +368,7 @@ void EditorExportPlatformAndroid::_get_property_list( List<PropertyInfo> *p_list p_list->push_back( PropertyInfo( Variant::STRING, "custom_package/debug", PROPERTY_HINT_FILE,"apk")); p_list->push_back( PropertyInfo( Variant::STRING, "custom_package/release", PROPERTY_HINT_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") ); @@ -361,6 +382,9 @@ void EditorExportPlatformAndroid::_get_property_list( List<PropertyInfo> *p_list p_list->push_back( PropertyInfo( Variant::BOOL, "screen/support_xlarge") ); p_list->push_back( PropertyInfo( Variant::STRING, "keystore/release",PROPERTY_HINT_FILE,"keystore") ); p_list->push_back( PropertyInfo( Variant::STRING, "keystore/release_user" ) ); + 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/pubic_key" ) ); const char **perms = android_perms; while(*perms) { @@ -1065,13 +1089,65 @@ Error EditorExportPlatformAndroid::export_project(const String& p_path,bool p_de ep.step("Adding Files..",1); + Error err=OK; + Vector<String> cl = cmdline.strip_edges().split(" "); + if (apk_expansion) { + String apkfname="main."+itos(version_code)+"."+package+".obb"; + String fullpath=p_path.get_base_dir().plus_file(apkfname); + FileAccess *pf = FileAccess::open(fullpath,FileAccess::WRITE); + if (!pf) { + EditorNode::add_io_error("Could not write expansion package file: "+apkfname); + return OK; + } + err = save_pack(pf); + memdelete(pf); + cl.push_back("-main_pack"); + cl.push_back(apkfname); + cl.push_back("-main_pack_md5"); + cl.push_back(FileAccess::get_md5(fullpath)); + cl.push_back("-main_pack_cfg"); + cl.push_back(apk_expansion_salt+","+apk_expansion_pkey); + + } else { + + APKExportData ed; + ed.ep=&ep; + ed.apk=apk; + + err = export_project_files(save_apk_file,&ed,false); + } + + if (cl.size()) { + //add comandline + Vector<uint8_t> clf; + clf.resize(4); + encode_uint32(cl.size(),&clf[0]); + for(int i=0;i<cl.size();i++) { + + CharString txt = cl[i].utf8(); + int base = clf.size(); + 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]); + } + + zipOpenNewFileInZip(apk, + "assets/_cl_", + NULL, + NULL, + 0, + NULL, + 0, + NULL, + Z_DEFLATED, + Z_DEFAULT_COMPRESSION); - APKExportData ed; - ed.ep=&ep; - ed.apk=apk; + zipWriteInFileInZip(apk,clf.ptr(),clf.size()); + zipCloseFileInZip(apk); - Error err = export_project_files(save_apk_file,&ed,false); + } zipClose(apk,NULL); unzClose(pkg); @@ -1400,6 +1476,7 @@ EditorExportPlatformAndroid::EditorExportPlatformAndroid() { package="com.android.noname"; name=""; _signed=true; + apk_expansion=false; device_lock = Mutex::create(); quit_request=false; orientation=0; @@ -1461,6 +1538,18 @@ bool EditorExportPlatformAndroid::can_export(String *r_error) const { err+="Custom release package not found.\n"; } + if (apk_expansion) { + + if (apk_expansion_salt=="") { + valid=false; + err+="Invalid SALT for apk expansion.\n"; + } + if (apk_expansion_pkey=="") { + valid=false; + err+="Invalid public key for apk expansion.\n"; + } + } + if (r_error) *r_error=err; |