我正在尝试基于Miracl crypto lib(C / C ++)构建一个Android应用程序。我已将他们的资源和我的资源添加到jni文件夹中。并编写了对函数的简单调用,该函数加载shared_library并返回字符串(withoud调用c ++函数,只返回一个字符串)。但是应用程序崩溃了 A / libc的?致命信号11(SIGSEGV),代码1,tid 17711中的故障地址0x0
在Windows 7 / x64上工作 Android Studio 1.1.0 Android r10d NDK
Application.mk
APP_PLATFORM := android-17
APP_ABI := armeabi-v7a
APP_STL := stlport_static
Android.mk
LOCAL_PATH := $(call my-dir)
# final lib, which will depend on others
include $(CLEAR_VARS)
LOCAL_CPPFLAGS := --std=c++11 -DMR_PAIRING_BLS
LOCAL_MODULE := CryptoLib
#find all the file recursively under jni/
LOCAL_C_INCLUDES := $(LOCAL_PATH)/miraclsources
LOCAL_CPP_EXTENSION := .cpp .c
LOCAL_SRC_FILES := miraclsources/mrcore.c \
miraclsources/mrarth0.c \
miraclsources/mrarth1.c \
miraclsources/mrarth2.c \
miraclsources/mralloc.c \
miraclsources/mrsmall.c \
miraclsources/mrio1.c \
miraclsources/mrio2.c \
miraclsources/mrgcd.c \
miraclsources/mrjack.c \
miraclsources/mrxgcd.c \
miraclsources/mrarth3.c \
miraclsources/mrbits.c \
miraclsources/mrrand.c \
miraclsources/mrprime.c \
miraclsources/mrcrt.c \
miraclsources/mrscrt.c \
miraclsources/mrmonty.c \
miraclsources/mrpower.c \
miraclsources/mrsroot.c \
miraclsources/mrcurve.c \
miraclsources/mrfast.c \
miraclsources/mrshs.c \
miraclsources/mrshs256.c \
miraclsources/mrshs512.c \
miraclsources/mrsha3.c \
miraclsources/mrfpe.c \
miraclsources/mraes.c \
miraclsources/mrgcm.c \
miraclsources/mrlucas.c \
miraclsources/mrzzn2.c \
miraclsources/mrzzn2b.c \
miraclsources/mrzzn3.c \
miraclsources/mrzzn4.c \
miraclsources/mrecn2.c \
miraclsources/mrstrong.c \
miraclsources/mrbrick.c \
miraclsources/mrebrick.c \
miraclsources/mrec2m.c \
miraclsources/mrgf2m.c \
miraclsources/mrflash.c \
miraclsources/mrfrnd.c \
miraclsources/mrdouble.c \
miraclsources/mrround.c \
miraclsources/mrbuild.c \
miraclsources/mrflsh1.c \
miraclsources/mrpi.c \
miraclsources/mrflsh2.c \
miraclsources/mrflsh3.c \
miraclsources/mrflsh4.c \
miraclsources/mrmuldv_android.c \
miraclsources/big.cpp \
miraclsources/zzn.cpp \
miraclsources/ecn.cpp \
miraclsources/ec2.cpp \
miraclsources/flash.cpp \
miraclsources/crt.cpp
LOCAL_SRC_FILES += miraclsources/zzn2.cpp \
miraclsources/zzn4.cpp \
miraclsources/zzn8.cpp \
miraclsources/zzn24.cpp \
miraclsources/bls_pair.cpp \
miraclsources/ecn4.cpp
LOCAL_SRC_FILES += sample.c
FILE_LIST := $(wildcard $(LOCAL_PATH)/*.cpp)
LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%)
LOCAL_LDLIBS := -llog
#LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
include $(BUILD_SHARED_LIBRARY)
main.cpp
#include "com_testproxy_NativeInterface.h"
#include <android/log.h>
/* Header for class com_testproxy_NativeInterface */
JNIEXPORT jstring JNICALL Java_com_testproxy_NativeInterface_getStringFromNative(JNIEnv *env, jobject obj)
{
return env -> NewStringUTF("Hello from JNI");
}
com_testproxy_NativeInterface.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_testproxy_NativeInterface */
#ifndef _Included_com_testproxy_NativeInterface
#define _Included_com_testproxy_NativeInterface
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_testproxy_NativeInterface
* Method: getStringFromNative
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_testproxy_NativeInterface_getStringFromNative
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
gradle part
ndk {
moduleName "CryptoLib"
}
}
sourceSets.main {
jni.srcDirs = [] //disable automatic ndk-build call (call ndk-build.cmd from terminal)
jniLibs.srcDir 'src/main/libs'
}
Java part
public class NativeInterface {
static {
System.loadLibrary("CryptoLib");
}
public native String getStringFromNative();
}
NativeInterface nativeInterface = new NativeInterface();
TextView textView = (TextView) findViewById(R.id.textview);
textView.setText(nativeInterface.getStringFromNative());
我使用命令构建ndk-build.cmd NDK_DEBUG = 1 NDK_LOG = 1
NDK stack trace is:
04-21 19:13:27.410 17711-17711/com.testproxy A/libc? Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 17711 (com.testproxy)
04-21 19:13:27.514 186-186/? I/DEBUG? *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
04-21 19:13:27.516 186-186/? I/DEBUG? Build fingerprint: 'google/hammerhead/hammerhead:5.1/LMY47I/1767468:user/release-keys'
04-21 19:13:27.517 186-186/? I/DEBUG? Revision: '11'
04-21 19:13:27.517 186-186/? I/DEBUG? ABI: 'arm'
04-21 19:13:27.517 186-186/? I/DEBUG? pid: 17711, tid: 17711, name: com.testproxy >>> com.testproxy <<<
04-21 19:13:27.517 186-186/? I/DEBUG? signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
04-21 19:13:27.558 186-186/? I/DEBUG? r0 00000000 r1 00000000 r2 00000000 r3 00000000
04-21 19:13:27.560 186-186/? I/DEBUG? r4 b4a32a60 r5 b4803128 r6 b47fe7e4 r7 b6fe9396
04-21 19:13:27.561 186-186/? I/DEBUG? r8 00000004 r9 b6fee714 sl 00000001 fp bea7c734
04-21 19:13:27.562 186-186/? I/DEBUG? ip 0000000d sp bea7c728 lr b358d820 pc b358d824 cpsr 60070010
04-21 19:13:27.564 186-186/? I/DEBUG? backtrace:
04-21 19:13:27.566 186-186/? I/DEBUG? #00 pc 00014824 /data/app/com.testproxy-1/lib/arm/libCryptoLib.so (negify(bigtype*, bigtype*)+36)
04-21 19:13:27.567 186-186/? I/DEBUG? #01 pc 00067650 /data/app/com.testproxy-1/lib/arm/libCryptoLib.so (operator-(int, Big const&)+88)
04-21 19:13:27.568 186-186/? I/DEBUG? #02 pc 0007b6f4 /data/app/com.testproxy-1/lib/arm/libCryptoLib.so (PFC::PFC(int, csprng*)+1336)
04-21 19:13:27.569 186-186/? I/DEBUG? #03 pc 000839e0 /data/app/com.testproxy-1/lib/arm/libCryptoLib.so (GeneralConstants::GeneralConstants(char*, int)+116)
04-21 19:13:27.569 186-186/? I/DEBUG? #04 pc 00084b90 /data/app/com.testproxy-1/lib/arm/libCryptoLib.so
04-21 19:13:27.570 186-186/? I/DEBUG? #05 pc 00084be4 /data/app/com.testproxy-1/lib/arm/libCryptoLib.so
04-21 19:13:27.570 186-186/? I/DEBUG? #06 pc 000015b5 /system/bin/linker (__dl__ZN6soinfo12CallFunctionEPKcPFvvE+44)
04-21 19:13:27.570 186-186/? I/DEBUG? #07 pc 00001689 /system/bin/linker (__dl__ZN6soinfo9CallArrayEPKcPPFvvEjb+140)
04-21 19:13:27.570 186-186/? I/DEBUG? #08 pc 0000185f /system/bin/linker (__dl__ZN6soinfo16CallConstructorsEv+142)
04-21 19:13:27.570 186-186/? I/DEBUG? #09 pc 00003259 /system/bin/linker (__dl__Z9do_dlopenPKciPK17android_dlextinfo+192)
04-21 19:13:27.571 186-186/? I/DEBUG? #10 pc 00000f1d /system/bin/linker (__dl__ZL10dlopen_extPKciPK17android_dlextinfo+24)
04-21 19:13:27.571 186-186/? I/DEBUG? #11 pc 001e102d /system/lib/libart.so (art::JavaVMExt::LoadNativeLibrary(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, art::Handle<art::mirror::ClassLoader>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)+544)
04-21 19:13:27.572 186-186/? I/DEBUG? #12 pc 00207b13 /system/lib/libart.so (art::Runtime_nativeLoad(_JNIEnv*, _jclass*, _jstring*, _jobject*, _jstring*)+514)
04-21 19:13:27.573 186-186/? I/DEBUG? #13 pc 000797f5 /data/dalvik-cache/arm/system@framework@boot.oat
04-21 19:13:27.910 186-186/? I/DEBUG? Tombstone written to: /data/tombstones/tombstone_06
04-21 19:13:27.916 724-815/? I/BootReceiver? Copying /data/tombstones/tombstone_06 to DropBox (SYSTEM_TOMBSTONE)
04-21 19:13:27.924 200-200/? I/Zygote? Process 17711 exited due to signal (11)
但我甚至不打电话给这些功能。编译没问题,有一些警告。 如何调试?