Try all supported ABIs for the executable on Android.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4496 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-10-07 13:01:21 +00:00
parent c741cc06b2
commit 7fc23dc085
2 changed files with 40 additions and 30 deletions

View File

@ -584,13 +584,13 @@ out/apk/TildeFriends-debug.unsigned.apk: out/apk/classes.dex out/androiddebug/ti
out/apk/TildeFriends-release.unsigned.apk: out/apk/classes.dex out/androidrelease/tildefriends out/androidrelease-x86_64/tildefriends out/androidrelease-x86/tildefriends out/androidrelease-armv7a/tildefriends $(RAW_FILES) out/apk/res.apk out/apk/TildeFriends-release.unsigned.apk: out/apk/classes.dex out/androidrelease/tildefriends out/androidrelease-x86_64/tildefriends out/androidrelease-x86/tildefriends out/androidrelease-armv7a/tildefriends $(RAW_FILES) out/apk/res.apk
out/%.unsigned.apk: out/%.unsigned.apk:
@mkdir -p $(dir $@) out/apk$(BUILD_TYPE)/bin/aarch64/ out/apk$(BUILD_TYPE)/bin/x86_64/ out/apk$(BUILD_TYPE)/bin/i686/ out/apk$(BUILD_TYPE)/bin/armv7a/ @mkdir -p $(dir $@) out/apk$(BUILD_TYPE)/bin/arm64-v8a/ out/apk$(BUILD_TYPE)/bin/x86_64/ out/apk$(BUILD_TYPE)/bin/i686/ out/apk$(BUILD_TYPE)/bin/armv7a/
@echo [aapt] $@ @echo [aapt] $@
@cp out/android$(BUILD_TYPE)/tildefriends out/apk$(BUILD_TYPE)/bin/aarch64/ @cp out/android$(BUILD_TYPE)/tildefriends out/apk$(BUILD_TYPE)/bin/arm64-v8a/
@cp out/android$(BUILD_TYPE)-x86_64/tildefriends out/apk$(BUILD_TYPE)/bin/x86_64/ @cp out/android$(BUILD_TYPE)-x86_64/tildefriends out/apk$(BUILD_TYPE)/bin/x86_64/
#@cp out/android$(BUILD_TYPE)-x86/tildefriends out/apk$(BUILD_TYPE)/bin/i686/ #@cp out/android$(BUILD_TYPE)-x86/tildefriends out/apk$(BUILD_TYPE)/bin/i686/
#@cp out/android$(BUILD_TYPE)-armv7a/tildefriends out/apk$(BUILD_TYPE)/bin/armv7a/ #@cp out/android$(BUILD_TYPE)-armv7a/tildefriends out/apk$(BUILD_TYPE)/bin/armv7a/
@$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk$(BUILD_TYPE)/bin/aarch64/tildefriends @$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk$(BUILD_TYPE)/bin/arm64-v8a/tildefriends
#@$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk$(BUILD_TYPE)/bin/armv7a/tildefriends #@$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk$(BUILD_TYPE)/bin/armv7a/tildefriends
@$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk$(BUILD_TYPE)/bin/x86_64/tildefriends @$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk$(BUILD_TYPE)/bin/x86_64/tildefriends
#@$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk$(BUILD_TYPE)/bin/i686/tildefriends #@$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk$(BUILD_TYPE)/bin/i686/tildefriends

View File

@ -54,36 +54,11 @@ public class MainActivity extends Activity {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
web_view = (WebView)findViewById(R.id.web); web_view = (WebView)findViewById(R.id.web);
String arch = System.getProperty("os.arch");
Log.w("tildefriends", String.format("getFilesDir() is %s", getFilesDir().toString())); Log.w("tildefriends", String.format("getFilesDir() is %s", getFilesDir().toString()));
Log.w("tildefriends", String.format("getPackageResourcePath() is %s", getPackageResourcePath().toString())); Log.w("tildefriends", String.format("getPackageResourcePath() is %s", getPackageResourcePath().toString()));
Log.w("tildefriends", String.format("os.arch is %s", arch));
try (ZipInputStream zip = new ZipInputStream(new BufferedInputStream(new FileInputStream(getPackageResourcePath().toString())))) { if (!extract_executable()) {
ZipEntry entry = null; Log.w("tildefriends", "Failed to extract a compatible executable.");
String lookup = String.format("bin/%s/tildefriends", arch);
Log.w("tildefriends", "Looking for " + lookup);
while ((entry = zip.getNextEntry()) != null) {
if (entry.getName().equals(lookup)) {
Log.w("tildefriends", "Extracting " + entry.getName());
try (FileOutputStream out = new FileOutputStream(getFilesDir().toString().concat("/tildefriends"))) {
byte[] buffer = new byte[32768];
int count;
while ((count = zip.read(buffer)) != -1) {
out.write(buffer, 0, count);
}
out.close();
new File(getFilesDir().toString() + "/tildefriends").setExecutable(true);
}
}
zip.closeEntry();
}
} catch (java.io.FileNotFoundException e) {
Log.w("tildefriends", "FileNotFoundException extracting executable");
Log.w("tildefriends", e.toString());
} catch (java.io.IOException e) {
Log.w("tildefriends", "IOException extracting executable");
Log.w("tildefriends", e.toString());
} }
String port_file_path = getFilesDir().toString() + "/port.txt"; String port_file_path = getFilesDir().toString() + "/port.txt";
@ -198,6 +173,41 @@ public class MainActivity extends Activity {
}); });
} }
private boolean extract_executable()
{
try (ZipInputStream zip = new ZipInputStream(new BufferedInputStream(new FileInputStream(getPackageResourcePath().toString())))) {
ZipEntry entry = null;
for (String abi : android.os.Build.SUPPORTED_ABIS)
{
String lookup = String.format("bin/%s/tildefriends", abi);
Log.w("tildefriends", "Looking for " + lookup);
while ((entry = zip.getNextEntry()) != null) {
if (entry.getName().equals(lookup)) {
Log.w("tildefriends", "Extracting " + entry.getName());
try (FileOutputStream out = new FileOutputStream(getFilesDir().toString().concat("/tildefriends"))) {
byte[] buffer = new byte[32768];
int count;
while ((count = zip.read(buffer)) != -1) {
out.write(buffer, 0, count);
}
out.close();
new File(getFilesDir().toString() + "/tildefriends").setExecutable(true);
return true;
}
}
zip.closeEntry();
}
}
} catch (java.io.FileNotFoundException e) {
Log.w("tildefriends", "FileNotFoundException extracting executable");
Log.w("tildefriends", e.toString());
} catch (java.io.IOException e) {
Log.w("tildefriends", "IOException extracting executable");
Log.w("tildefriends", e.toString());
}
return false;
}
@Override @Override
protected void onDestroy() protected void onDestroy()
{ {