You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
main-executable: extract native libs before instantiating the Application class
This commit is contained in:
@@ -90,7 +90,7 @@ void set_up_handle_cache(JNIEnv *env)
|
||||
handle_cache.view_group.dispatchTouchEvent = _METHOD(handle_cache.view_group.class, "dispatchTouchEvent", "(Landroid/view/MotionEvent;)Z");
|
||||
|
||||
handle_cache.asset_manager.class = _REF((*env)->FindClass(env, "android/content/res/AssetManager"));
|
||||
handle_cache.asset_manager.extractFromAPK = _STATIC_METHOD(handle_cache.asset_manager.class, "extractFromAPK", "(Ljava/lang/String;Ljava/lang/String;)V");
|
||||
handle_cache.asset_manager.extractFromAPK = _STATIC_METHOD(handle_cache.asset_manager.class, "extractFromAPK", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
|
||||
handle_cache.context.class = _REF((*env)->FindClass(env, "android/content/Context"));
|
||||
if((*env)->ExceptionCheck(env))
|
||||
|
||||
@@ -59,9 +59,10 @@ void _gdb_force_java_stack_trace(void)
|
||||
(*env)->ExceptionClear(env);
|
||||
}
|
||||
|
||||
extern char *apk_path;
|
||||
void extract_from_apk(const char *path, const char *target) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
(*env)->CallStaticVoidMethod(env, handle_cache.asset_manager.class, handle_cache.asset_manager.extractFromAPK, _JSTRING(path), _JSTRING(target));
|
||||
(*env)->CallStaticVoidMethod(env, handle_cache.asset_manager.class, handle_cache.asset_manager.extractFromAPK, _JSTRING(apk_path), _JSTRING(path), _JSTRING(target));
|
||||
}
|
||||
|
||||
/* logging with fallback to stderr */
|
||||
|
||||
@@ -612,14 +612,14 @@ public final class AssetManager {
|
||||
|
||||
private native final int addAssetPathNative(String path);
|
||||
|
||||
public static void extractFromAPK(String path, String target) throws IOException {
|
||||
public static void extractFromAPK(String apk_path, String path, String target) throws IOException {
|
||||
if (path.endsWith("/")) { // directory
|
||||
try (JarFile apk = new JarFile(Context.this_application.getPackageCodePath())) {
|
||||
try (JarFile apk = new JarFile(apk_path)) {
|
||||
Enumeration<JarEntry> entries = apk.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry entry = entries.nextElement();
|
||||
if (entry.getName().startsWith(path)) {
|
||||
extractFromAPK(entry.getName(), entry.getName().replace(path, target));
|
||||
extractFromAPK(apk_path, entry.getName(), entry.getName().replace(path, target));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package android.media;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.content.res.AssetManager;
|
||||
|
||||
@@ -25,7 +26,7 @@ public class SoundPool {
|
||||
}
|
||||
|
||||
public int load(AssetFileDescriptor afd, int priority) throws IOException {
|
||||
AssetManager.extractFromAPK(afd.fileName, afd.fileName);
|
||||
AssetManager.extractFromAPK(Context.this_application.getPackageCodePath(), afd.fileName, afd.fileName);
|
||||
return nativeLoad(nativePool, android.os.Environment.getExternalStorageDirectory().getPath() + "/" + afd.fileName);
|
||||
}
|
||||
|
||||
|
||||
@@ -532,16 +532,16 @@ static void open(GtkApplication *app, GFile **files, gint nfiles, const gchar *h
|
||||
|
||||
prepare_main_looper(env);
|
||||
|
||||
/* extract native libraries from apk*/
|
||||
if (!getenv("ATL_SKIP_NATIVES_EXTRACTION"))
|
||||
extract_from_apk("lib/" NATIVE_ARCH "/", "lib/");
|
||||
|
||||
// construct Application
|
||||
application_object = (*env)->CallStaticObjectMethod(env, handle_cache.context.class,
|
||||
_STATIC_METHOD(handle_cache.context.class, "createApplication", "(J)Landroid/app/Application;"), window);
|
||||
if ((*env)->ExceptionCheck(env))
|
||||
(*env)->ExceptionDescribe(env);
|
||||
|
||||
/* extract native libraries from apk*/
|
||||
if (!getenv("ATL_SKIP_NATIVES_EXTRACTION"))
|
||||
extract_from_apk("lib/" NATIVE_ARCH "/", "lib/");
|
||||
|
||||
jclass content_provider = (*env)->FindClass(env, "android/content/ContentProvider");
|
||||
(*env)->CallStaticVoidMethod(env, content_provider, _STATIC_METHOD(content_provider, "createContentProviders", "()V"));
|
||||
if ((*env)->ExceptionCheck(env))
|
||||
|
||||
Reference in New Issue
Block a user