So close. We can do it without the .so.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4214 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-03-11 03:47:01 +00:00
parent f74f4f6da9
commit 2a3b1a1e33
2 changed files with 49 additions and 18 deletions

View File

@ -26,12 +26,11 @@ ANDROID_PLATFORM := $(ANDROID_SDK)/platforms/android-23
ANDROID_NDK ?= /usr/lib/android-sdk/ndk-bundle
ANDROID_NDK_API_VERSION := 30
ANDROID_NDK_TARGET_TRIPLE := aarch64-linux-android
ANDROID_MIN_SDK_VERSION := 26
ANDROID_TARGETS := \
out/androiddebug/tildefriends \
out/androiddebug/libtildefriends.so \
out/androidrelease/tildefriends \
out/androidrelease/libtildefriends.so
out/androidrelease/tildefriends
debug windebug $(ANDROID_TARGETS): CFLAGS += -Og
debug release androidrelease: LDFLAGS += -rdynamic
@ -370,15 +369,9 @@ DEPS = $(ALL_APP_OBJS:.o=.d)
-include $(DEPS)
define build_rules
$(1): $(BUILD_DIR)/$(1)/$(if $(filter android%,$(1)),lib)$(PROJECT)$(if $(filter win%,$(1)),.exe)$(if $(filter android%,$(1)),.so)
$(1): $(BUILD_DIR)/$(1)/$(PROJECT)$(if $(filter win%,$(1)),.exe)
.PHONY: $(1)
ifeq ($(filter android%,$(1)),$(1))
$(BUILD_DIR)/$(1)/lib$(PROJECT).so: $(filter $(BUILD_DIR)/$(1)/%,$(ALL_APP_OBJS))
@echo [link] $$@
@$$(CC) -o $$@ $$^ $$(LDFLAGS) -shared
endif
$(BUILD_DIR)/$(1)/$(PROJECT)$(if $(filter win%,$(1)),.exe): $(filter $(BUILD_DIR)/$(1)/%,$(ALL_APP_OBJS))
@echo [link] $$@
@$$(CC) -o $$@ $$^ $$(LDFLAGS)
@ -407,12 +400,12 @@ CLASS_FILES := $(foreach src,$(JAVA_FILES),out/classes/com/unprompted/tildefrien
$(CLASS_FILES) &: $(JAVA_FILES)
@echo [javac] $(CLASS_FILES)
@javac --release 9 -classpath $(ANDROID_PLATFORM)/android.jar -d out/classes $(JAVA_FILES)
@javac --release 8 -classpath $(ANDROID_PLATFORM)/android.jar -d out/classes $(JAVA_FILES)
out/apk/classes.dex: $(CLASS_FILES)
@mkdir -p $(dir $@)
@echo [dx] $@
@$(ANDROID_BUILD_TOOLS)/dx --dex --output=$@ out/classes/
@$(ANDROID_BUILD_TOOLS)/dx --dex --min-sdk-version=$(ANDROID_MIN_SDK_VERSION) --output=$@ out/classes/
PACKAGE_DIRS := \
apps/ \
@ -424,11 +417,10 @@ PACKAGE_DIRS := \
RAW_FILES := $(shell find $(PACKAGE_DIRS) -type f)
out/TildeFriends.unsigned.apk: out/apk/classes.dex out/androiddebug/tildefriends out/androiddebug/libtildefriends.so $(RAW_FILES)
out/TildeFriends.unsigned.apk: out/apk/classes.dex out/androiddebug/tildefriends $(RAW_FILES)
@mkdir -p $(dir $@) out/apk/lib/arm64-v8a/
@echo [aapt] $@
@cp out/androiddebug/tildefriends out/apk/lib/arm64-v8a/
@cp out/androiddebug/libtildefriends.so out/apk/lib/arm64-v8a/
@$(ANDROID_BUILD_TOOLS)/aapt package -f -M src/android/AndroidManifest.xml -S src/android/res/ -I $(ANDROID_PLATFORM)/android.jar -F $@ out/apk/
@zip -u $@ -q -r $(PACKAGE_DIRS)

View File

@ -9,8 +9,16 @@ import android.os.SystemClock;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import java.lang.Process;
import java.lang.Thread;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.BufferedInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -20,8 +28,41 @@ public class MainActivity extends Activity {
WebView web = (WebView)findViewById(R.id.web);
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("getPackageCodePath() is %s", getPackageCodePath().toString()));
setFilesPath(getFilesDir().toString(), getPackageResourcePath().toString());
try {
ZipInputStream zip = new ZipInputStream(new BufferedInputStream(new FileInputStream(getPackageResourcePath().toString())));
ZipEntry entry = null;
while ((entry = zip.getNextEntry()) != null) {
if (entry.getName().equals("lib/arm64-v8a/tildefriends")) {
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());
}
ProcessBuilder builder = new ProcessBuilder(getFilesDir().toString() + "/tildefriends", "run", "-z", getPackageResourcePath().toString());
Log.w("tildefriends", "files = " + getFilesDir().toString());
builder.directory(getFilesDir());
builder.inheritIO();
try {
builder.start();
} catch (java.io.IOException e) {
Log.w("tildefriends", "IOException starting process: " + e.toString());
}
try {
Thread.sleep(1000);
} catch (java.lang.InterruptedException e) {
@ -43,8 +84,6 @@ public class MainActivity extends Activity {
web.loadUrl("http://127.0.0.1:12345/~core/apps/");
}
public native void setFilesPath(String files_path, String apk_path);
static {
System.loadLibrary("tildefriends");
}