Updated compilation rules. Now working and tested

This commit is contained in:
renaud gaudin 2013-04-04 14:22:21 +02:00
parent 3317a36e31
commit c75fff74ca
4 changed files with 33 additions and 81 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -26,11 +26,16 @@ ORIGINAL_ENVIRON = copy.deepcopy(os.environ)
# the directory of this file for relative referencing
CURRENT_PATH = os.path.dirname(os.path.abspath(__file__))
PLATFORMS = {
ARCHS_FULL_NAMES = {
'arm-linux-androideabi': 'arm-linux-androideabi',
'mipsel-linux-android': 'mipsel-linux-android',
'x86': 'i686-linux-android'}
ARCHS_SHORT_NAMES = {
'arm-linux-androideabi': 'armeabi',
'mipsel-linux-android': 'mips',
'x86': 'x86'}
# store host machine name
UNAME = check_output(['uname', '-s']).strip()
@ -119,9 +124,11 @@ for path in REQUIRED_PATHS:
for arch in ARCHS:
# 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
curdir = os.getcwd()
# platform contains the toolchain
@ -241,8 +248,10 @@ for arch in ARCHS:
os.remove(src.replace('.cpp', '.o'))
# compile JNI header
os.chdir(os.path.join(curdir, 'org', 'kiwix', 'kiwixmobile'))
syscall('javac JNIKiwix.java')
syscall('javah -jni JNIKiwix')
os.chdir(curdir)
syscall('javah -jni org.kiwix.kiwixmobile.JNIKiwix')
# create libkiwix.so
os.chdir(curdir)
@ -268,13 +277,17 @@ for arch in ARCHS:
'kiwix.o reader.o stringTools.o '
'%(platform)s/lib/libzim.a %(platform)s/lib/liblzma.a '
'-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 '
'-o %(platform)s/lib/libkiwix.so'
% {'kwsrc': LIBKIWIX_SRC,
'platform': platform,
'arch_full': arch_full,
'gccver': COMPILER_VERSION})
'gccver': COMPILER_VERSION,
'NDK_PATH': NDK_PATH,
'arch_short': arch_short})
if COMPILE_LIBKIWIX:
syscall(compile_cmd)
@ -291,3 +304,5 @@ for arch in ARCHS:
os.chdir(curdir)
change_env(ORIGINAL_ENVIRON)
break

19
kiwix.c
View File

@ -1,5 +1,5 @@
#include <jni.h>
#include "JNIKiwix.h"
#include "org_kiwix_kiwixmobile_JNIKiwix.h"
#include <stdio.h>
#include <string.h>
@ -59,13 +59,21 @@ void setBoolObjValue(const bool value, const jobject obj, JNIEnv *env) {
}
/* Kiwix library functions */
JNIEXPORT jboolean JNICALL Java_JNIKiwix_nativeLoadZIM(JNIEnv *env, jobject obj, jstring path) {
// kiwix::Reader reader = kiwix::Reader("42.zim");
JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getMainPage(JNIEnv *env, jobject obj) {
return c2jni(true);
std::string cpath = "/mnt/sdcard/test.zim";
kiwix::Reader reader = kiwix::Reader(cpath);
std::string mainp = reader.getMainPageUrl();
return c2jni(mainp, env);
}
JNIEXPORT jbyteArray JNICALL Java_JNIKiwix_nativeGetContent(JNIEnv *env, jobject obj, jstring url,
JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_nativeLoadZIM(JNIEnv *env, jobject obj, jstring path) {
return c2jni(true);
}
JNIEXPORT jbyteArray JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_nativeGetContent(JNIEnv *env, jobject obj, jstring url,
jobject mimeTypeObj, jobject sizeObj) {
setStringObjValue("42", mimeTypeObj, env);
setIntObjValue(42, sizeObj, env);
@ -78,4 +86,3 @@ JNIEXPORT jbyteArray JNICALL Java_JNIKiwix_nativeGetContent(JNIEnv *env, jobject
return data;
}