diff --git a/jni/Android.mk b/jni/Android.mk index e6a087556..6417e1e96 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -35,6 +35,7 @@ LOCAL_LDLIBS := -lz LOCAL_STATIC_LIBRARIES := expat LOCAL_SRC_FILES := \ + NativeFormats/main.cpp \ NativeFormats/JavaNativeFormatPlugin.cpp \ NativeFormats/JavaPluginCollection.cpp \ NativeFormats/util/AndroidUtil.cpp \ diff --git a/jni/NativeFormats/main.cpp b/jni/NativeFormats/main.cpp new file mode 100644 index 000000000..dd91021f4 --- /dev/null +++ b/jni/NativeFormats/main.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2011-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include + +#include + +extern "C" +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { + AndroidUtil::init(jvm); + return JNI_VERSION_1_2; +} diff --git a/jni/NativeFormats/util/AndroidUtil.cpp b/jni/NativeFormats/util/AndroidUtil.cpp index 148bb79bb..de4eb2aa8 100644 --- a/jni/NativeFormats/util/AndroidUtil.cpp +++ b/jni/NativeFormats/util/AndroidUtil.cpp @@ -66,7 +66,7 @@ JNIEnv *AndroidUtil::getEnv() { return env; } -#define CHECK_NULL(value) if ((value) == 0) { return false; } +#define CHECK_NULL(value) if ((value) == 0) { throwRuntimeException(env, #value); } bool AndroidUtil::init(JavaVM* jvm) { ourJavaVM = jvm; @@ -167,3 +167,8 @@ std::string AndroidUtil::convertNonUtfString(const std::string &str) { return result; } + +void AndroidUtil::throwRuntimeException(JNIEnv *env, const std::string &message) { + jclass cls = env->FindClass("java/lang/RuntimeException"); + env->ThrowNew(cls, message.c_str()); +} diff --git a/jni/NativeFormats/util/AndroidUtil.h b/jni/NativeFormats/util/AndroidUtil.h index cafcfc676..d05f636cf 100644 --- a/jni/NativeFormats/util/AndroidUtil.h +++ b/jni/NativeFormats/util/AndroidUtil.h @@ -77,6 +77,8 @@ public: static bool extractJavaString(JNIEnv *env, jstring from, std::string &to); static jstring createJavaString(JNIEnv* env, const std::string &str); static std::string convertNonUtfString(const std::string &str); + + static void throwRuntimeException(JNIEnv *env, const std::string &message); }; #endif /* __ANDROIDUTIL_H__ */ diff --git a/project.properties b/project.properties index 3aa40afdc..c4a39de92 100644 --- a/project.properties +++ b/project.properties @@ -8,6 +8,6 @@ # project structure. java.encoding=utf-8 -proguard.config=proguard.cfg +#proguard.config=proguard.cfg # Project target. target=android-8