Build native library in JNI folder?

心不动则不痛 提交于 2019-12-24 15:21:13

问题


I'm testing JNI on Android in Eclipse.

I have a simple Android project with one activity. In Eclipse's project explorer, I added:

  • jni/ folder
  • Android.mk in the jni/ folder
  • prng.c in the jni/ folder

The source file is named prng.c because it wraps Crypto++'s random number generator. Crypto++ is already cross-compiled for ARMv7, so I have libcryptopp.so standing by.

When I select Project → Build Project, the library is not built. I've confirmed its not built after cleaning the project, too.

Android-PRNG$ find . -iname *.so
Android-PRNG$

Question: Why is Eclipse not building the shared object? What else need to be done?


Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := prng
LOCAL_SRC_FILES := prng.c

include $(BUILD_SHARED_LIBRARY)

prng.c

Its basically empty at the moment because I can't get javah to run on the Java class file that calls the native methods. I hope to fix that problem next.

#include <string.h>
#include <jni.h>

#include <cryptopp/osrandom.h>

static RandomNumberGenerator& GetPRNG()
{
    static AutoSeededRandomPool prng;

    return prng;
}

回答1:


It's actually very easy with ADT for the last couple of years; it was much worse before. The plugin described in the linked post are coming preinstalled; you still need to

1 install NDK

2 set the path to it in Preferences/Android/NDK menu

3 right click on your Android project, Android Tools/Add Native Support

... and now you are all set.



来源:https://stackoverflow.com/questions/25582835/build-native-library-in-jni-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!