aboutsummaryrefslogtreecommitdiff
path: root/platform/android/export/export.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/export/export.cpp')
-rw-r--r--platform/android/export/export.cpp156
1 files changed, 140 insertions, 16 deletions
diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp
index 51db77595..aef223470 100644
--- a/platform/android/export/export.cpp
+++ b/platform/android/export/export.cpp
@@ -181,10 +181,15 @@ 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;
+ String release_password;
String release_username;
struct APKExportData {
@@ -237,11 +242,11 @@ public:
virtual int get_device_count() const;
virtual String get_device_name(int p_device) const;
virtual String get_device_info(int p_device) const;
- virtual Error run(int p_device);
+ virtual Error run(int p_device,bool p_dumb=false);
virtual bool requieres_password(bool p_debug) const { return !p_debug; }
virtual String get_binary_extension() const { return "apk"; }
- virtual Error export_project(const String& p_path,bool p_debug,const String& p_password="");
+ virtual Error export_project(const String& p_path,bool p_debug,bool p_dumb=false);
virtual bool can_export(String *r_error=NULL) const;
@@ -253,10 +258,16 @@ bool EditorExportPlatformAndroid::_set(const StringName& p_name, const Variant&
String n=p_name;
- if (n=="version/code")
+ 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")
@@ -279,6 +290,14 @@ 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=="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;
else if (n.begins_with("permissions/")) {
String what = n.get_slice("/",1).to_upper();
@@ -302,11 +321,16 @@ bool EditorExportPlatformAndroid::_set(const StringName& p_name, const Variant&
bool EditorExportPlatformAndroid::_get(const StringName& p_name,Variant &r_ret) const{
String n=p_name;
-
- if (n=="version/code")
+ 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")
@@ -329,6 +353,14 @@ 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=="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;
else if (n.begins_with("permissions/")) {
String what = n.get_slice("/",1).to_upper();
@@ -346,8 +378,9 @@ bool EditorExportPlatformAndroid::_get(const StringName& p_name,Variant &r_ret)
void EditorExportPlatformAndroid::_get_property_list( List<PropertyInfo> *p_list) const{
- 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, "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") );
@@ -361,6 +394,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/public_key",PROPERTY_HINT_MULTILINE_TEXT ) );
const char **perms = android_perms;
while(*perms) {
@@ -390,7 +426,7 @@ static String _parse_string(const uint8_t *p_bytes,bool p_utf8) {
}
offset+=2;
- printf("len %i, unicode: %i\n",len,int(p_utf8));
+ //printf("len %i, unicode: %i\n",len,int(p_utf8));
if (p_utf8) {
@@ -944,7 +980,7 @@ Error EditorExportPlatformAndroid::save_apk_file(void *p_userdata,const String&
-Error EditorExportPlatformAndroid::export_project(const String& p_path,bool p_debug,const String& p_password) {
+Error EditorExportPlatformAndroid::export_project(const String& p_path, bool p_debug, bool p_dumb) {
String src_apk;
@@ -1064,14 +1100,89 @@ 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(" ");
+ for(int i=0;i<cl.size();i++) {
+ if (cl[i].strip_edges().length()==0) {
+ cl.remove(i);
+ i--;
+ }
+ }
+
+ if (p_dumb) {
+
+ String host = EditorSettings::get_singleton()->get("file_server/host");
+ 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);
+ }
+
+
+ } else {
+ //all files
+
+ 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("-use_apk_expansion");
+ cl.push_back("-apk_expansion_md5");
+ cl.push_back(FileAccess::get_md5(fullpath));
+ cl.push_back("-apk_expansion_key");
+ cl.push_back(apk_expansion_pkey.strip_edges());
+
+ } 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);
@@ -1103,7 +1214,7 @@ Error EditorExportPlatformAndroid::export_project(const String& p_path,bool p_de
} else {
keystore=release_keystore;
- password=p_password;
+ password=release_password;
user=release_username;
ep.step("Signing Release APK..",103);
@@ -1312,7 +1423,7 @@ void EditorExportPlatformAndroid::_device_poll_thread(void *ud) {
}
-Error EditorExportPlatformAndroid::run(int p_device) {
+Error EditorExportPlatformAndroid::run(int p_device, bool p_dumb) {
ERR_FAIL_INDEX_V(p_device,devices.size(),ERR_INVALID_PARAMETER);
device_lock->lock();
@@ -1331,7 +1442,7 @@ Error EditorExportPlatformAndroid::run(int p_device) {
ep.step("Exporting APK",0);
String export_to=EditorSettings::get_singleton()->get_settings_path()+"/tmp/tmpexport.apk";
- Error err = export_project(export_to,true);
+ Error err = export_project(export_to,true,p_dumb);
if (err) {
device_lock->unlock();
return err;
@@ -1400,6 +1511,7 @@ EditorExportPlatformAndroid::EditorExportPlatformAndroid() {
package="com.android.noname";
name="";
_signed=true;
+ apk_expansion=false;
device_lock = Mutex::create();
quit_request=false;
orientation=0;
@@ -1461,6 +1573,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;