[Libreoffice-commits] online.git: 8 commits - android/app android/.gitignore configure.ac kit/Kit.cpp

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Feb 15 15:53:59 UTC 2019


 android/.gitignore                                                     |    9 
 android/app/build.gradle                                               |  182 ++++++++++
 android/app/liboSettings.gradle.in                                     |   19 +
 android/app/src/main/cpp/CMakeLists.txt.in                             |   52 ++
 android/app/src/main/cpp/androidapp.cpp                                |    6 
 android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java |  108 +++++
 configure.ac                                                           |    1 
 kit/Kit.cpp                                                            |    2 
 8 files changed, 373 insertions(+), 6 deletions(-)

New commits:
commit 427c5ea219d43cb45369038defc8e17f1092493f
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Fri Feb 15 16:19:46 2019 +0100
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Fri Feb 15 16:53:35 2019 +0100

    android: Settings for the build.gradle.
    
    Change-Id: I457a7fb8a80106c0474ee03229e712a557cf799b

diff --git a/android/.gitignore b/android/.gitignore
index 34f7d7552..290fd83d8 100644
--- a/android/.gitignore
+++ b/android/.gitignore
@@ -3,4 +3,12 @@
 /android.iml
 /gradle
 /local.properties
+/app/src/main/assets/etc/
+/app/src/main/assets/example.odt
+/app/src/main/assets/license.txt
+/app/src/main/assets/notice.txt
+/app/src/main/assets/program/
+/app/src/main/assets/share/
+/app/src/main/assets/unpack/
+/app/src/main/assets/user/
 /app/src/main/cpp/lib
diff --git a/android/app/liboSettings.gradle.in b/android/app/liboSettings.gradle.in
new file mode 100644
index 000000000..325b9b933
--- /dev/null
+++ b/android/app/liboSettings.gradle.in
@@ -0,0 +1,19 @@
+ext {
+    liboSrcRoot         = '@LOBUILDDIR@'
+    liboWorkdir         = '@LOBUILDDIR@/workdir'
+    liboInstdir         = '@LOBUILDDIR@/instdir'
+    liboEtcFolder       = 'program'
+    liboUreMiscFolder   = 'program'
+    liboSharedResFolder = 'program/resource'
+    liboUREJavaFolder   = 'program/classes'
+    liboShareJavaFolder = 'program/classes'
+    liboExampleDocument = '@LOBUILDDIR@/android/default-document/example.odt'
+    liboVersionMajor    = '@LOOLWSD_VERSION_MAJOR@'
+    liboVersionMinor    = '@LOOLWSD_VERSION_MAJOR@'
+    liboGitFullCommit   = '@LOOLWSD_VERSION_HASH@'
+}
+android.defaultConfig {
+    applicationId 'org.libreoffice.androidapp'
+    //versionCode project.hasProperty('cmdVersionCode') ? cmdVersionCode.toInteger() : 1
+    versionName '@LOOLWSD_VERSION@'
+}
diff --git a/configure.ac b/configure.ac
index 34db534e8..b5dfc2ca6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -687,6 +687,7 @@ AS_IF([test "$ENABLE_IOSAPP" = "true"],
 AC_SUBST(IOSAPP_FONTS)
 
 AC_CONFIG_FILES([Makefile
+                 android/app/liboSettings.gradle
                  android/app/src/main/cpp/CMakeLists.txt
                  gtk/Makefile
                  ios/config.h
commit a362bdec096c2f76c5c8c494829c7a62cacb066a
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Fri Feb 15 16:09:57 2019 +0100
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Fri Feb 15 16:53:35 2019 +0100

    android: Some pieces have to be unpacked out of the APK.
    
    Mostly copied from the core.git.
    
    Change-Id: I87472037c48d69a904440fd8008b515d604bb84b

diff --git a/android/app/build.gradle b/android/app/build.gradle
index af66460e5..e9728cfcc 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -57,7 +57,7 @@ dependencies {
 
 task copyUnpackAssets(type: Copy) {
     description "copies assets that need to be extracted on the device"
-    into 'src/main/assets'
+    into 'src/main/assets/unpack'
     into('program') {
         from("${liboInstdir}/${liboEtcFolder}/types") {
             includes = [
@@ -164,7 +164,7 @@ task createStrippedConfigRegistry(type: Exec) {
 task createRCfiles {
     inputs.file "liboSettings.gradle"
     dependsOn copyUnpackAssets, copyAssets
-    def sofficerc     = file('src/main/assets/program/sofficerc')
+    def sofficerc     = file('src/main/assets/unpack/program/sofficerc')
     def fundamentalrc = file('src/main/assets/program/fundamentalrc')
     def bootstraprc   = file('src/main/assets/program/bootstraprc')
     def unorc         = file('src/main/assets/program/unorc')
@@ -219,7 +219,3 @@ preBuild.dependsOn 'createRCfiles',
         'createStrippedConfigMain',
         'createStrippedConfigRegistry',
         'createFullConfig'
-
-//clean.dependsOn 'cleanCopyAssets',
-//        'cleanCreateStrippedConfig',
-//        'cleanCreateFullConfig'
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
index 5063972c1..bbf038b6f 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
@@ -9,9 +9,11 @@
 
 package org.libreoffice.androidapp;
 
+import android.content.SharedPreferences;
 import android.content.pm.ApplicationInfo;
 import android.content.res.AssetManager;
 import android.os.Bundle;
+import android.preference.PreferenceManager;
 import android.util.Log;
 import android.view.View;
 import android.webkit.JavascriptInterface;
@@ -20,41 +22,109 @@ import android.webkit.WebView;
 import android.webkit.WebViewClient;
 import android.widget.Button;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.FileChannel;
+import java.nio.channels.ReadableByteChannel;
+
 import androidx.appcompat.app.AppCompatActivity;
 
 public class MainActivity extends AppCompatActivity {
     final static String TAG = "MainActivity";
 
+    private static final String ASSETS_EXTRACTED_PREFS_KEY = "ASSETS_EXTRACTED";
+
+    private static boolean copyFromAssets(AssetManager assetManager,
+                                          String fromAssetPath, String targetDir) {
+        try {
+            String[] files = assetManager.list(fromAssetPath);
+
+            boolean res = true;
+            for (String file : files) {
+                String[] dirOrFile = assetManager.list(fromAssetPath + "/" + file);
+                if ( dirOrFile.length == 0) {
+                    // noinspection ResultOfMethodCallIgnored
+                    new File(targetDir).mkdirs();
+                    res &= copyAsset(assetManager,
+                            fromAssetPath + "/" + file,
+                            targetDir + "/" + file);
+                } else
+                    res &= copyFromAssets(assetManager,
+                            fromAssetPath + "/" + file,
+                            targetDir + "/" + file);
+            }
+            return res;
+        } catch (Exception e) {
+            e.printStackTrace();
+            Log.e(TAG, "copyFromAssets failed: " + e.getMessage());
+            return false;
+        }
+    }
+
+    private static boolean copyAsset(AssetManager assetManager, String fromAssetPath, String toPath) {
+        ReadableByteChannel source = null;
+        FileChannel dest = null;
+        try {
+            try {
+                source = Channels.newChannel(assetManager.open(fromAssetPath));
+                dest = new FileOutputStream(toPath).getChannel();
+                long bytesTransferred = 0;
+                // might not copy all at once, so make sure everything gets copied....
+                ByteBuffer buffer = ByteBuffer.allocate(4096);
+                while (source.read(buffer) > 0) {
+                    buffer.flip();
+                    bytesTransferred += dest.write(buffer);
+                    buffer.clear();
+                }
+                Log.v(TAG, "Success copying " + fromAssetPath + " to " + toPath + " bytes: " + bytesTransferred);
+                return true;
+            } finally {
+                if (dest != null) dest.close();
+                if (source != null) source.close();
+            }
+        } catch (FileNotFoundException e) {
+            Log.e(TAG, "file " + fromAssetPath + " not found! " + e.getMessage());
+            return false;
+        } catch (IOException e) {
+            Log.e(TAG, "failed to copy file " + fromAssetPath + " from assets to " + toPath + " - " + e.getMessage());
+            return false;
+        }
+    }
+
+    private void updatePreferences() {
+        SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+        if (sPrefs.getInt(ASSETS_EXTRACTED_PREFS_KEY, 0) != BuildConfig.VERSION_CODE) {
+            if (copyFromAssets(getAssets(), "unpack", getApplicationInfo().dataDir)) {
+                sPrefs.edit().putInt(ASSETS_EXTRACTED_PREFS_KEY, BuildConfig.VERSION_CODE).apply();
+            }
+        }
+    }
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        updatePreferences();
+
         setContentView(R.layout.activity_main);
 
         AssetManager assetManager = getResources().getAssets();
 
+        ApplicationInfo applicationInfo = getApplicationInfo();
+        String dataDir = applicationInfo.dataDir;
+        Log.i(TAG, String.format("Initializing LibreOfficeKit, dataDir=%s\n", dataDir));
+
         //redirectStdio(true);
 
         String cacheDir = getApplication().getCacheDir().getAbsolutePath();
         String apkFile = getApplication().getPackageResourcePath();
 
-        /* TODO
-        // If there is a fonts.conf file in the apk that can be extracted, automatically
-        // set the FONTCONFIG_FILE env var.
-        InputStream inputStream;
-        try {
-            inputStream = activity.getAssets().open("unpack/etc/fonts/fonts.conf");
-        } catch (java.io.IOException exception) {
-            inputStream = null;
-        }
-
-        if (inputStream != null) {
-            putenv("FONTCONFIG_FILE=" + dataDir + "/etc/fonts/fonts.conf");
-        }
-        */
-
         String urlToLoad = "file:///android_asset/dist/hello-world.odt";
 
-        createLOOLWSD("/assets", cacheDir, apkFile, assetManager, urlToLoad);
+        createLOOLWSD(dataDir, cacheDir, apkFile, assetManager, urlToLoad);
 
         final WebView browser = findViewById(R.id.browser);
         browser.setWebViewClient(new WebViewClient());
@@ -78,6 +148,15 @@ public class MainActivity extends AppCompatActivity {
         );
     }
 
+    @Override
+    protected void onResume() {
+        super.onResume();
+        Log.i(TAG, "onResume..");
+
+        // check for config change
+        updatePreferences();
+    }
+
     static {
         System.loadLibrary("androidapp");
     }
commit df3faf45ae3017360f736d502a1f6e72b85f0b68
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Fri Feb 15 14:27:55 2019 +0100
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Fri Feb 15 16:53:35 2019 +0100

    android: Better path for the fonts.conf.
    
    Change-Id: Iaecbec1b24dd4806da3f52e8eb3e1eddd64891b3

diff --git a/android/app/build.gradle b/android/app/build.gradle
index bd42fe2ea..af66460e5 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -83,7 +83,7 @@ task copyUnpackAssets(type: Copy) {
         ]
     }
     into('etc/fonts') {
-        from "./"
+        from "${liboSrcRoot}/android/source/"
         includes = ['fonts.conf']
         filter {
             String line ->
commit 4480a32577a09837b65a79e89def5c32c204346d
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Fri Feb 15 13:49:19 2019 +0100
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Fri Feb 15 16:53:35 2019 +0100

    android: Actually use /assets as the dataDir.
    
    Change-Id: I00a6263644effc6bf20a46c90d811e6fa0cf1e09

diff --git a/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
index 487e29dc7..5063972c1 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
@@ -32,10 +32,6 @@ public class MainActivity extends AppCompatActivity {
 
         AssetManager assetManager = getResources().getAssets();
 
-        ApplicationInfo applicationInfo = getApplicationInfo();
-        String dataDir = applicationInfo.dataDir;
-        Log.i(TAG, String.format("Initializing LibreOfficeKit, dataDir=%s\n", dataDir));
-
         //redirectStdio(true);
 
         String cacheDir = getApplication().getCacheDir().getAbsolutePath();
@@ -58,7 +54,7 @@ public class MainActivity extends AppCompatActivity {
 
         String urlToLoad = "file:///android_asset/dist/hello-world.odt";
 
-        createLOOLWSD(dataDir/*"/assets"*/, cacheDir, apkFile, assetManager, urlToLoad);
+        createLOOLWSD("/assets", cacheDir, apkFile, assetManager, urlToLoad);
 
         final WebView browser = findViewById(R.id.browser);
         browser.setWebViewClient(new WebViewClient());
commit 2d7bb54826bca3270ef657ff1440128fa4f36207
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Fri Feb 15 13:38:32 2019 +0100
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Fri Feb 15 16:53:35 2019 +0100

    android: Add / generarate various bootstrap-related files into the APK.
    
    Mostly taken from core.git.
    
    Change-Id: Idb7c7078cb78b257b04737daa00cf210cbe2cf87

diff --git a/android/app/build.gradle b/android/app/build.gradle
index fb40fe3b9..bd42fe2ea 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -1,5 +1,8 @@
 apply plugin: 'com.android.application'
 
+// buildhost settings - paths and the like
+apply from: 'liboSettings.gradle'
+
 android {
     compileSdkVersion 28
     defaultConfig {
@@ -51,3 +54,172 @@ dependencies {
     implementation 'androidx.appcompat:appcompat:1.0.2'
     implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
 }
+
+task copyUnpackAssets(type: Copy) {
+    description "copies assets that need to be extracted on the device"
+    into 'src/main/assets'
+    into('program') {
+        from("${liboInstdir}/${liboEtcFolder}/types") {
+            includes = [
+                    "offapi.rdb",
+                    "oovbaapi.rdb"
+            ]
+        }
+        from("${liboInstdir}/${liboUreMiscFolder}") {
+            includes = ["types.rdb"]
+            rename 'types.rdb', 'udkapi.rdb'
+        }
+    }
+    into('user/fonts') {
+        from "${liboInstdir}/share/fonts/truetype"
+        // Note: restrict list of fonts due to size considerations - no technical reason anymore
+        // ToDo: fonts would be good candidate for using Expansion Files instead
+        includes = [
+                "Liberation*.ttf",
+                "Caladea-*.ttf",
+                "Carlito-*.ttf",
+                "Gen*.ttf",
+                "opens___.ttf"
+        ]
+    }
+    into('etc/fonts') {
+        from "./"
+        includes = ['fonts.conf']
+        filter {
+            String line ->
+                line.replaceAll(
+                        '@@APPLICATION_ID@@', new String("${android.defaultConfig.applicationId}")
+                )
+        }
+    }
+}
+
+task copyAssets(type: Copy) {
+    description "copies assets that can be accessed within the installed apk"
+    into 'src/main/assets'
+    from("${liboSrcRoot}/readlicense_oo/license/") {
+        includes = ["LICENSE", "NOTICE"]
+        rename "LICENSE", "license.txt"
+        rename "NOTICE", "notice.txt"
+    }
+    from("${liboExampleDocument}") {
+        rename ".*", "example.odt"
+    }
+    into('program') {
+        from "${liboInstdir}/program"
+        includes = ['services.rdb', 'services/services.rdb']
+
+        into('resource') {
+            from "${liboInstdir}/${liboSharedResFolder}"
+            includes = ['*en-US.res']
+        }
+    }
+    into('share') {
+        from "${liboInstdir}/share"
+        // Filter data is needed by e.g. the drawingML preset shape import.
+        includes = ['registry/**', 'filter/**']
+        // those two get processed by mobile-config.py
+        excludes = ['registry/main.xcd', 'registry/res/registry_en-US.xcd']
+    }
+}
+
+task createFullConfig(type: Copy) {
+    into 'src/main/assets/share/config/soffice.cfg'
+    from "${liboInstdir}/share/config/soffice.cfg"
+}
+
+task createStrippedConfig {
+    def preserveDir = file("src/main/assets/share/config/soffice.cfg/empty")
+    outputs.dir "src/main/assets/share/registry/res"
+    outputs.file preserveDir
+
+    doLast {
+        file('src/main/assets/share/registry/res').mkdirs()
+        file("src/main/assets/share/config/soffice.cfg").mkdirs()
+        // just empty file
+        preserveDir.text = ""
+    }
+}
+
+
+task createStrippedConfigMain(type: Exec) {
+    dependsOn 'createStrippedConfig'
+    inputs.files "${liboInstdir}/share/registry/main.xcd", "${liboSrcRoot}/android/mobile-config.py"
+    outputs.file "src/main/assets/share/registry/main.xcd"
+    executable "${liboSrcRoot}/android/mobile-config.py"
+    args = ["${liboInstdir}/share/registry/main.xcd", "src/main/assets/share/registry/main.xcd"]
+}
+
+task createStrippedConfigRegistry(type: Exec) {
+    dependsOn 'createStrippedConfig'
+    inputs.files "${liboInstdir}/share/registry/res/registry_en-US.xcd", "${liboSrcRoot}/android/mobile-config.py"
+    outputs.file "src/main/assets/share/registry/res/registry_en-US.xcd"
+    executable "${liboSrcRoot}/android/mobile-config.py"
+    args = ["${liboInstdir}/share/registry/res/registry_en-US.xcd", "src/main/assets/share/registry/res/registry_en-US.xcd"]
+    doFirst {
+        file('src/main/assets/share/registry/res').mkdirs()
+    }
+}
+
+task createRCfiles {
+    inputs.file "liboSettings.gradle"
+    dependsOn copyUnpackAssets, copyAssets
+    def sofficerc     = file('src/main/assets/program/sofficerc')
+    def fundamentalrc = file('src/main/assets/program/fundamentalrc')
+    def bootstraprc   = file('src/main/assets/program/bootstraprc')
+    def unorc         = file('src/main/assets/program/unorc')
+    def versionrc     = file('src/main/assets/program/versionrc')
+
+    outputs.files sofficerc, fundamentalrc, unorc, bootstraprc, versionrc
+
+    doLast {
+        sofficerc.text = '''\
+            [Bootstrap]
+            Logo=1
+            NativeProgress=1
+            URE_BOOTSTRAP=file:///assets/program/fundamentalrc
+            HOME=$APP_DATA_DIR/cache
+            OSL_SOCKET_PATH=$APP_DATA_DIR/cache
+            '''.stripIndent()
+
+        fundamentalrc.text =  '''\
+            [Bootstrap]
+            LO_LIB_DIR=file://$APP_DATA_DIR/lib/
+            BRAND_BASE_DIR=file:///assets
+            CONFIGURATION_LAYERS=xcsxcu:${BRAND_BASE_DIR}/share/registry res:${BRAND_BASE_DIR}/share/registry
+            URE_BIN_DIR=file:///assets/ure/bin/dir/nothing-here/we-can/exec-anyway
+            '''.stripIndent()
+
+        bootstraprc.text =  '''\
+            [Bootstrap]
+            InstallMode=<installmode>
+            ProductKey=LibreOffice '''+ "${liboVersionMajor}.${liboVersionMinor}" + '''
+            UserInstallation=file://$APP_DATA_DIR
+            '''.stripIndent()
+
+        unorc.text = '''\
+            [Bootstrap]
+            URE_INTERNAL_LIB_DIR=file://$APP_DATA_DIR/lib/
+            UNO_TYPES=file://$APP_DATA_DIR/program/udkapi.rdb file://$APP_DATA_DIR/program/offapi.rdb file://$APP_DATA_DIR/program/oovbaapi.rdb
+            UNO_SERVICES=file:///assets/program/services.rdb file:///assets/program/services/services.rdb
+            '''.stripIndent()
+
+        versionrc.text = '''\
+            [Version]
+            AllLanguages=en-US
+            BuildVersion=
+            buildid=''' + "${liboGitFullCommit}" + '''
+            ReferenceOOoMajorMinor=4.1
+            '''.stripIndent()
+    }
+}
+
+// creating the UI stuff is cheap, don't bother only applying it for the flavor..
+preBuild.dependsOn 'createRCfiles',
+        'createStrippedConfigMain',
+        'createStrippedConfigRegistry',
+        'createFullConfig'
+
+//clean.dependsOn 'cleanCopyAssets',
+//        'cleanCreateStrippedConfig',
+//        'cleanCreateFullConfig'
commit a25b2562825861a3877422c4b494d6f66ab26402
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Fri Feb 15 13:37:18 2019 +0100
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Fri Feb 15 16:53:35 2019 +0100

    android: Package the lo-native-code.so and dependencies into the APK.
    
    Additionally don't strip the debugging symbols when building a debug APK
    for easier debugging in the Android Studio.
    
    Change-Id: I522a91da511a2868a2a07d80b4a25fea0dbd2621

diff --git a/android/.gitignore b/android/.gitignore
index c5b7553a2..34f7d7552 100644
--- a/android/.gitignore
+++ b/android/.gitignore
@@ -3,3 +3,4 @@
 /android.iml
 /gradle
 /local.properties
+/app/src/main/cpp/lib
diff --git a/android/app/build.gradle b/android/app/build.gradle
index c70779866..fb40fe3b9 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -25,11 +25,25 @@ android {
                           'proguard-rules.pro'
         }
     }
+    sourceSets {
+        main {
+            // let gradle pack the shared library into apk
+            jniLibs.srcDirs = ['src/main/cpp/lib']
+        }
+    }
     externalNativeBuild {
         cmake {
             path "src/main/cpp/CMakeLists.txt"
         }
     }
+
+    if (gradle.startParameter.taskNames.contains(":app:assembleDebug")) {
+        // do not strip the .so's in the debug buils to allow convenient
+        // debugging
+        packagingOptions {
+            doNotStrip '**/*.so'
+        }
+    }
 }
 
 dependencies {
commit a98d08fbb3f4b5e9729a117222ca94a5c241a335
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Fri Feb 15 16:19:46 2019 +0100
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Fri Feb 15 16:53:35 2019 +0100

    android: Copy the liblo-native-code.so over from core.git.
    
    Change-Id: I457a7fb8a80106c0474ee03229e712a557cf799b

diff --git a/android/app/src/main/cpp/CMakeLists.txt.in b/android/app/src/main/cpp/CMakeLists.txt.in
index 66d61d0ab..03b1ed7d9 100644
--- a/android/app/src/main/cpp/CMakeLists.txt.in
+++ b/android/app/src/main/cpp/CMakeLists.txt.in
@@ -33,7 +33,54 @@ target_include_directories(androidapp PRIVATE
                            @POCOINCLUDE@         # POCO
                            @LIBPNG_INCLUDES@     # libpng
                            @LOKIT_PATH@          # LibreOfficeKit
-                           )
+)
+
+add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}/liblo-native-code.so"
+                   COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}"
+                   COMMAND ${CMAKE_COMMAND} -E copy @LOBUILDDIR@/instdir/program/libfreebl3.so "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}"
+                   DEPENDS @LOBUILDDIR@/instdir/program/libfreebl3.so
+
+                   COMMAND ${CMAKE_COMMAND} -E copy @LOBUILDDIR@/instdir/program/libnspr4.so "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}"
+                   DEPENDS @LOBUILDDIR@/instdir/program/libnspr4.so
+
+                   COMMAND ${CMAKE_COMMAND} -E copy @LOBUILDDIR@/instdir/program/libnss3.so "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}"
+                   DEPENDS @LOBUILDDIR@/instdir/program/libnss3.so
+
+                   COMMAND ${CMAKE_COMMAND} -E copy @LOBUILDDIR@/instdir/program/libnssckbi.so "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}"
+                   DEPENDS @LOBUILDDIR@/instdir/program/libnssckbi.so
+
+                   COMMAND ${CMAKE_COMMAND} -E copy @LOBUILDDIR@/instdir/program/libnssdbm3.so "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}"
+                   DEPENDS @LOBUILDDIR@/instdir/program/libnssdbm3.so
+
+                   COMMAND ${CMAKE_COMMAND} -E copy @LOBUILDDIR@/instdir/program/libnssutil3.so "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}"
+                   DEPENDS @LOBUILDDIR@/instdir/program/libnssutil3.so
+
+                   COMMAND ${CMAKE_COMMAND} -E copy @LOBUILDDIR@/instdir/program/libplc4.so "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}"
+                   DEPENDS @LOBUILDDIR@/instdir/program/libplc4.so
+
+                   COMMAND ${CMAKE_COMMAND} -E copy @LOBUILDDIR@/instdir/program/libplds4.so "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}"
+                   DEPENDS @LOBUILDDIR@/instdir/program/libplds4.so
+
+                   COMMAND ${CMAKE_COMMAND} -E copy @LOBUILDDIR@/instdir/program/libsmime3.so "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}"
+                   DEPENDS @LOBUILDDIR@/instdir/program/libsmime3.so
+
+                   COMMAND ${CMAKE_COMMAND} -E copy @LOBUILDDIR@/instdir/program/libsoftokn3.so "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}"
+                   DEPENDS @LOBUILDDIR@/instdir/program/libsoftokn3.so
+
+                   COMMAND ${CMAKE_COMMAND} -E copy @LOBUILDDIR@/instdir/program/libsqlite3.so "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}"
+                   DEPENDS @LOBUILDDIR@/instdir/program/libsqlite3.so
+
+                   COMMAND ${CMAKE_COMMAND} -E copy @LOBUILDDIR@/instdir/program/libssl3.so "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}"
+                   DEPENDS @LOBUILDDIR@/instdir/program/libssl3.so
+
+                   COMMAND ${CMAKE_COMMAND} -E copy @LOBUILDDIR@/android/source/obj/local/armeabi-v7a/liblo-native-code.so "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}"
+                   DEPENDS @LOBUILDDIR@/android/source/obj/local/armeabi-v7a/liblo-native-code.so
+
+                   COMMENT "Copied liblo-native-code.so and its dependencies to the tree."
+)
+
+
+add_custom_target(copy_native_code DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}/liblo-native-code.so")
 
 target_link_libraries(androidapp
                       android
@@ -46,4 +93,5 @@ target_link_libraries(androidapp
                       @POCOLIB@/libPocoXML at POCODEBUG@.a
                       @POCOLIB@/libPocoJSON at POCODEBUG@.a
                       @POCOLIB@/libPocoFoundation at POCODEBUG@.a
-                      )
+                      "${CMAKE_CURRENT_SOURCE_DIR}/lib/${ANDROID_ABI}/liblo-native-code.so"
+)
commit 835bb3db355d1940841a528ab1d130487564dd15
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Fri Feb 15 13:34:55 2019 +0100
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Fri Feb 15 16:53:35 2019 +0100

    android: Perform the android-specific setup before initializing the LOK.
    
    Change-Id: I935e6849dd41c5e66b768c7f2a79c139265c901f

diff --git a/android/app/src/main/cpp/androidapp.cpp b/android/app/src/main/cpp/androidapp.cpp
index f8e13260f..763cf672f 100644
--- a/android/app/src/main/cpp/androidapp.cpp
+++ b/android/app/src/main/cpp/androidapp.cpp
@@ -239,10 +239,14 @@ Java_org_libreoffice_androidapp_MainActivity_postMobileMessage(JNIEnv *env, jobj
         LOG_TRC_NOFILE("From JS: lool: some object");
 }
 
+extern "C" jboolean libreofficekit_initialize(JNIEnv* env, jstring dataDir, jstring cacheDir, jstring apkFile, jobject assetManager);
+
 /// Create the LOOLWSD instance.
 extern "C" JNIEXPORT void JNICALL
-Java_org_libreoffice_androidapp_MainActivity_createLOOLWSD(JNIEnv *env, jobject, jstring loadFileURL)
+Java_org_libreoffice_androidapp_MainActivity_createLOOLWSD(JNIEnv *env, jobject, jstring dataDir, jstring cacheDir, jstring apkFile, jobject assetManager, jstring loadFileURL)
 {
+    libreofficekit_initialize(env, dataDir, cacheDir, apkFile, assetManager);
+
     fileURL = std::string(env->GetStringUTFChars(loadFileURL, nullptr));
 
     Log::initialize("Mobile", "trace", false, false, {});
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
index dc594b924..487e29dc7 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
@@ -9,6 +9,8 @@
 
 package org.libreoffice.androidapp;
 
+import android.content.pm.ApplicationInfo;
+import android.content.res.AssetManager;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.View;
@@ -28,8 +30,35 @@ public class MainActivity extends AppCompatActivity {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
 
+        AssetManager assetManager = getResources().getAssets();
+
+        ApplicationInfo applicationInfo = getApplicationInfo();
+        String dataDir = applicationInfo.dataDir;
+        Log.i(TAG, String.format("Initializing LibreOfficeKit, dataDir=%s\n", dataDir));
+
+        //redirectStdio(true);
+
+        String cacheDir = getApplication().getCacheDir().getAbsolutePath();
+        String apkFile = getApplication().getPackageResourcePath();
+
+        /* TODO
+        // If there is a fonts.conf file in the apk that can be extracted, automatically
+        // set the FONTCONFIG_FILE env var.
+        InputStream inputStream;
+        try {
+            inputStream = activity.getAssets().open("unpack/etc/fonts/fonts.conf");
+        } catch (java.io.IOException exception) {
+            inputStream = null;
+        }
+
+        if (inputStream != null) {
+            putenv("FONTCONFIG_FILE=" + dataDir + "/etc/fonts/fonts.conf");
+        }
+        */
+
         String urlToLoad = "file:///android_asset/dist/hello-world.odt";
-        createLOOLWSD(urlToLoad);
+
+        createLOOLWSD(dataDir/*"/assets"*/, cacheDir, apkFile, assetManager, urlToLoad);
 
         final WebView browser = findViewById(R.id.browser);
         browser.setWebViewClient(new WebViewClient());
@@ -58,7 +87,7 @@ public class MainActivity extends AppCompatActivity {
     }
 
     /** Initialize the LOOLWSD to load 'loadFileURL'. */
-    public native void createLOOLWSD(String loadFileURL);
+    public native void createLOOLWSD(String dataDir, String cacheDir, String apkFile, AssetManager assetManager, String loadFileURL);
 
     /** Passing messages from JS (instead of the websocket communication). */
     @JavascriptInterface
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 6cea2e0c4..5de91056c 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -2501,7 +2501,7 @@ void lokit_main(
 
 #else // MOBILEAPP
 
-#ifdef __linux
+#if defined(__linux) && !defined(__ANDROID__)
         Poco::URI userInstallationURI("file", LO_PATH);
         LibreOfficeKit *kit = lok_init_2(LO_PATH "/program", userInstallationURI.toString().c_str());
 #else


More information about the Libreoffice-commits mailing list