Files
loongoffice/android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java
Michael Weghorn 7084da45dd android: Explicitly load libc++_shared
While it works just fine without that in newer
Android versions, trying to open any doc in an
x86 AVD with API level 16 failed like this:

> E/AndroidRuntime( 2999): java.lang.ExceptionInInitializerError
> E/AndroidRuntime( 2999):        at org.libreoffice.TileProviderFactory.initialize(TileProviderFactory.java:23)
> E/AndroidRuntime( 2999):        at org.libreoffice.LOKitThread.<init>(LOKitThread.java:39)
> E/AndroidRuntime( 2999):        at org.libreoffice.LibreOfficeMainActivity.onCreate(LibreOfficeMainActivity.java:149)
> E/AndroidRuntime( 2999):        at android.app.Activity.performCreate(Activity.java:5008)
> E/AndroidRuntime( 2999):        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
> E/AndroidRuntime( 2999):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
> E/AndroidRuntime( 2999):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
> E/AndroidRuntime( 2999):        at android.app.ActivityThread.access$600(ActivityThread.java:130)
> E/AndroidRuntime( 2999):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
> E/AndroidRuntime( 2999):        at android.os.Handler.dispatchMessage(Handler.java:99)
> E/AndroidRuntime( 2999):        at android.os.Looper.loop(Looper.java:137)
> E/AndroidRuntime( 2999):        at android.app.ActivityThread.main(ActivityThread.java:4745)
> E/AndroidRuntime( 2999):        at java.lang.reflect.Method.invokeNative(Native Method)
> E/AndroidRuntime( 2999):        at java.lang.reflect.Method.invoke(Method.java:511)
> E/AndroidRuntime( 2999):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
> E/AndroidRuntime( 2999):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
> E/AndroidRuntime( 2999):        at dalvik.system.NativeStart.main(Native Method)
> E/AndroidRuntime( 2999): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1891]:  1176 could not load needed library 'libc++_shared.so' for 'liblo-native-code.so' (load_library[1093]: Library 'libc++_shared.so' not found)
> E/AndroidRuntime( 2999):        at java.lang.Runtime.loadLibrary(Runtime.java:370)
> E/AndroidRuntime( 2999):        at java.lang.System.loadLibrary(System.java:535)
> E/AndroidRuntime( 2999):        at org.libreoffice.kit.NativeLibLoader.load(LibreOfficeKit.java:105)
> E/AndroidRuntime( 2999):        at org.libreoffice.kit.LibreOfficeKit.<clinit>(LibreOfficeKit.java:82)
> E/AndroidRuntime( 2999):        ... 17 more
> W/ActivityManager( 1421):   Force finishing activity org.libreoffice/.LibreOfficeMainActivity
> W/ActivityManager( 1421):   Force finishing activity org.libreoffice/.ui.LibreOfficeUIActivity

Change-Id: I6e383e624b9e66c0daa9ecfda4a3b176c8fa0d94
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133263
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
2022-04-21 20:57:55 +02:00

112 lines
3.9 KiB
Java

/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.libreoffice.kit;
import android.app.Activity;
import android.content.pm.ApplicationInfo;
import android.content.res.AssetManager;
import android.util.Log;
import java.io.InputStream;
import java.nio.ByteBuffer;
// Native methods in this class are all implemented in
// sal/android/lo-bootstrap.c as the lo-bootstrap library is loaded with
// System.loadLibrary() and Android's JNI works only to such libraries, it
// seems.
public final class LibreOfficeKit
{
private static String LOGTAG = LibreOfficeKit.class.getSimpleName();
private static AssetManager mgr;
// private constructor because instantiating would be meaningless
private LibreOfficeKit() {
}
// Trigger library initialization - as this is done automatically by executing the "static" block, this method remains empty. However we need this to manually (at the right time) can force library initialization.
public static void initializeLibrary() {
}
// Trigger initialization on the JNI - LOKit side.
private static native boolean initializeNative(String dataDir, String cacheDir, String apkFile, AssetManager mgr);
public static native ByteBuffer getLibreOfficeKitHandle();
// Wrapper for putenv()
public static native void putenv(String string);
// A method that starts a thread to redirect stdout and stderr writes to
// the Android logging mechanism, or stops the redirection.
public static native void redirectStdio(boolean state);
static boolean initializeDone = false;
// This init() method should be called from the upper Java level of
// LO-based apps.
public static synchronized void init(Activity activity)
{
if (initializeDone) {
return;
}
mgr = activity.getResources().getAssets();
ApplicationInfo applicationInfo = activity.getApplicationInfo();
String dataDir = applicationInfo.dataDir;
Log.i(LOGTAG, String.format("Initializing LibreOfficeKit, dataDir=%s\n", dataDir));
redirectStdio(true);
String cacheDir = activity.getApplication().getCacheDir().getAbsolutePath();
String apkFile = activity.getApplication().getPackageResourcePath();
if (!initializeNative(dataDir, cacheDir, apkFile, mgr)) {
Log.e(LOGTAG, "Initialize native failed!");
return;
}
initializeDone = true;
}
// Now with static loading we always have all native code in one native
// library which we always call liblo-native-code.so, regardless of the
// app. The library has already been unpacked into /data/data/<app
// name>/lib at installation time by the package manager.
static {
NativeLibLoader.load();
}
}
class NativeLibLoader {
private static boolean done = false;
protected static synchronized void load() {
if (done)
return;
System.loadLibrary("nspr4");
System.loadLibrary("plds4");
System.loadLibrary("plc4");
System.loadLibrary("nssutil3");
System.loadLibrary("freebl3");
System.loadLibrary("sqlite3");
System.loadLibrary("softokn3");
System.loadLibrary("nss3");
System.loadLibrary("nssckbi");
System.loadLibrary("nssdbm3");
System.loadLibrary("smime3");
System.loadLibrary("ssl3");
System.loadLibrary("c++_shared");
System.loadLibrary("lo-native-code");
done = true;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */