From 7fc23dc085e620b639c75811aca29be3d00eab8a Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sat, 7 Oct 2023 13:01:21 +0000 Subject: [PATCH] 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 --- Makefile | 6 +- .../unprompted/tildefriends/MainActivity.java | 64 +++++++++++-------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index d460bc26..255237a3 100644 --- a/Makefile +++ b/Makefile @@ -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/%.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] $@ - @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/tildefriends out/apk$(BUILD_TYPE)/bin/i686/ #@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/x86_64/tildefriends #@$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk$(BUILD_TYPE)/bin/i686/tildefriends diff --git a/src/android/com/unprompted/tildefriends/MainActivity.java b/src/android/com/unprompted/tildefriends/MainActivity.java index 9adb27f4..3174c36f 100644 --- a/src/android/com/unprompted/tildefriends/MainActivity.java +++ b/src/android/com/unprompted/tildefriends/MainActivity.java @@ -54,36 +54,11 @@ public class MainActivity extends Activity { setContentView(R.layout.activity_main); 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("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())))) { - ZipEntry entry = null; - 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()); + if (!extract_executable()) { + Log.w("tildefriends", "Failed to extract a compatible executable."); } 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 protected void onDestroy() {