mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 15:27:55 -04:00
Updated compilation rules. Now working and tested
This commit is contained in:
parent
3317a36e31
commit
c75fff74ca
29
JNIKiwix.h
29
JNIKiwix.h
@ -1,29 +0,0 @@
|
|||||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
|
||||||
#include <jni.h>
|
|
||||||
/* Header for class JNIKiwix */
|
|
||||||
|
|
||||||
#ifndef _Included_JNIKiwix
|
|
||||||
#define _Included_JNIKiwix
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
/*
|
|
||||||
* Class: JNIKiwix
|
|
||||||
* Method: nativeLoadZIM
|
|
||||||
* Signature: (Ljava/lang/String;)Z
|
|
||||||
*/
|
|
||||||
JNIEXPORT jboolean JNICALL Java_JNIKiwix_nativeLoadZIM
|
|
||||||
(JNIEnv *, jobject, jstring);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: JNIKiwix
|
|
||||||
* Method: nativeGetContent
|
|
||||||
* Signature: (Ljava/lang/String;LJNIKiwixString;LJNIKiwixInt;)[B
|
|
||||||
*/
|
|
||||||
JNIEXPORT jbyteArray JNICALL Java_JNIKiwix_nativeGetContent
|
|
||||||
(JNIEnv *, jobject, jstring, jobject, jobject);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
@ -1,41 +0,0 @@
|
|||||||
public class JNIKiwix {
|
|
||||||
public native boolean nativeLoadZIM(String path);
|
|
||||||
public native byte[] nativeGetContent(String url, JNIKiwixString mimeType, JNIKiwixInt size);
|
|
||||||
|
|
||||||
static {
|
|
||||||
System.loadLibrary("kiwix");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
JNIKiwix self = new JNIKiwix();
|
|
||||||
|
|
||||||
try {
|
|
||||||
self.nativeLoadZIM("test.zim");
|
|
||||||
|
|
||||||
JNIKiwixString mimeTypeObj = new JNIKiwixString();
|
|
||||||
JNIKiwixInt sizeObj = new JNIKiwixInt();
|
|
||||||
byte[] data = self.nativeGetContent("/A/Wikipedia.html", mimeTypeObj, sizeObj);
|
|
||||||
System.out.println(mimeTypeObj.value);
|
|
||||||
System.out.println(sizeObj.value);
|
|
||||||
System.out.println(data[0]);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
System.out.println("Message " + e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class JNIKiwixString {
|
|
||||||
String value;
|
|
||||||
}
|
|
||||||
|
|
||||||
class JNIKiwixInt {
|
|
||||||
int value;
|
|
||||||
}
|
|
||||||
|
|
||||||
class JNIKiwixBool {
|
|
||||||
boolean value;
|
|
||||||
}
|
|
@ -26,11 +26,16 @@ ORIGINAL_ENVIRON = copy.deepcopy(os.environ)
|
|||||||
# the directory of this file for relative referencing
|
# the directory of this file for relative referencing
|
||||||
CURRENT_PATH = os.path.dirname(os.path.abspath(__file__))
|
CURRENT_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
PLATFORMS = {
|
ARCHS_FULL_NAMES = {
|
||||||
'arm-linux-androideabi': 'arm-linux-androideabi',
|
'arm-linux-androideabi': 'arm-linux-androideabi',
|
||||||
'mipsel-linux-android': 'mipsel-linux-android',
|
'mipsel-linux-android': 'mipsel-linux-android',
|
||||||
'x86': 'i686-linux-android'}
|
'x86': 'i686-linux-android'}
|
||||||
|
|
||||||
|
ARCHS_SHORT_NAMES = {
|
||||||
|
'arm-linux-androideabi': 'armeabi',
|
||||||
|
'mipsel-linux-android': 'mips',
|
||||||
|
'x86': 'x86'}
|
||||||
|
|
||||||
# store host machine name
|
# store host machine name
|
||||||
UNAME = check_output(['uname', '-s']).strip()
|
UNAME = check_output(['uname', '-s']).strip()
|
||||||
|
|
||||||
@ -119,9 +124,11 @@ for path in REQUIRED_PATHS:
|
|||||||
|
|
||||||
for arch in ARCHS:
|
for arch in ARCHS:
|
||||||
# second name of the platform ; used as subfolder in platform/
|
# second name of the platform ; used as subfolder in platform/
|
||||||
arch_full = PLATFORMS.get(arch)
|
arch_full = ARCHS_FULL_NAMES.get(arch)
|
||||||
|
arch_short = ARCHS_SHORT_NAMES.get(arch)
|
||||||
|
|
||||||
# store where we are so we can go back
|
# store where we are so we can go back
|
||||||
|
|
||||||
curdir = os.getcwd()
|
curdir = os.getcwd()
|
||||||
|
|
||||||
# platform contains the toolchain
|
# platform contains the toolchain
|
||||||
@ -241,8 +248,10 @@ for arch in ARCHS:
|
|||||||
os.remove(src.replace('.cpp', '.o'))
|
os.remove(src.replace('.cpp', '.o'))
|
||||||
|
|
||||||
# compile JNI header
|
# compile JNI header
|
||||||
|
os.chdir(os.path.join(curdir, 'org', 'kiwix', 'kiwixmobile'))
|
||||||
syscall('javac JNIKiwix.java')
|
syscall('javac JNIKiwix.java')
|
||||||
syscall('javah -jni JNIKiwix')
|
os.chdir(curdir)
|
||||||
|
syscall('javah -jni org.kiwix.kiwixmobile.JNIKiwix')
|
||||||
|
|
||||||
# create libkiwix.so
|
# create libkiwix.so
|
||||||
os.chdir(curdir)
|
os.chdir(curdir)
|
||||||
@ -268,13 +277,17 @@ for arch in ARCHS:
|
|||||||
'kiwix.o reader.o stringTools.o '
|
'kiwix.o reader.o stringTools.o '
|
||||||
'%(platform)s/lib/libzim.a %(platform)s/lib/liblzma.a '
|
'%(platform)s/lib/libzim.a %(platform)s/lib/liblzma.a '
|
||||||
'-L%(platform)s/%(arch_full)s/lib '
|
'-L%(platform)s/%(arch_full)s/lib '
|
||||||
# '-lgnustl_shared -llog -landroid -lstdc++ '
|
'%(NDK_PATH)s/sources/cxx-stl/gnu-libstdc++/%(gccver)s'
|
||||||
|
'/libs/%(arch_short)s/libgnustl_static.a '
|
||||||
|
'-llog -landroid -lstdc++ -lc '
|
||||||
'%(platform)s/lib/gcc/%(arch_full)s/%(gccver)s/libgcc.a '
|
'%(platform)s/lib/gcc/%(arch_full)s/%(gccver)s/libgcc.a '
|
||||||
'-o %(platform)s/lib/libkiwix.so'
|
'-o %(platform)s/lib/libkiwix.so'
|
||||||
% {'kwsrc': LIBKIWIX_SRC,
|
% {'kwsrc': LIBKIWIX_SRC,
|
||||||
'platform': platform,
|
'platform': platform,
|
||||||
'arch_full': arch_full,
|
'arch_full': arch_full,
|
||||||
'gccver': COMPILER_VERSION})
|
'gccver': COMPILER_VERSION,
|
||||||
|
'NDK_PATH': NDK_PATH,
|
||||||
|
'arch_short': arch_short})
|
||||||
|
|
||||||
if COMPILE_LIBKIWIX:
|
if COMPILE_LIBKIWIX:
|
||||||
syscall(compile_cmd)
|
syscall(compile_cmd)
|
||||||
@ -291,3 +304,5 @@ for arch in ARCHS:
|
|||||||
|
|
||||||
os.chdir(curdir)
|
os.chdir(curdir)
|
||||||
change_env(ORIGINAL_ENVIRON)
|
change_env(ORIGINAL_ENVIRON)
|
||||||
|
|
||||||
|
break
|
17
kiwix.c
17
kiwix.c
@ -1,5 +1,5 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include "JNIKiwix.h"
|
#include "org_kiwix_kiwixmobile_JNIKiwix.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -59,13 +59,21 @@ void setBoolObjValue(const bool value, const jobject obj, JNIEnv *env) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Kiwix library functions */
|
/* Kiwix library functions */
|
||||||
JNIEXPORT jboolean JNICALL Java_JNIKiwix_nativeLoadZIM(JNIEnv *env, jobject obj, jstring path) {
|
JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getMainPage(JNIEnv *env, jobject obj) {
|
||||||
// kiwix::Reader reader = kiwix::Reader("42.zim");
|
|
||||||
|
std::string cpath = "/mnt/sdcard/test.zim";
|
||||||
|
kiwix::Reader reader = kiwix::Reader(cpath);
|
||||||
|
std::string mainp = reader.getMainPageUrl();
|
||||||
|
|
||||||
|
return c2jni(mainp, env);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_nativeLoadZIM(JNIEnv *env, jobject obj, jstring path) {
|
||||||
|
|
||||||
return c2jni(true);
|
return c2jni(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jbyteArray JNICALL Java_JNIKiwix_nativeGetContent(JNIEnv *env, jobject obj, jstring url,
|
JNIEXPORT jbyteArray JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_nativeGetContent(JNIEnv *env, jobject obj, jstring url,
|
||||||
jobject mimeTypeObj, jobject sizeObj) {
|
jobject mimeTypeObj, jobject sizeObj) {
|
||||||
setStringObjValue("42", mimeTypeObj, env);
|
setStringObjValue("42", mimeTypeObj, env);
|
||||||
setIntObjValue(42, sizeObj, env);
|
setIntObjValue(42, sizeObj, env);
|
||||||
@ -78,4 +86,3 @@ JNIEXPORT jbyteArray JNICALL Java_JNIKiwix_nativeGetContent(JNIEnv *env, jobject
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user