Build native library in JNI folder?

2019-08-08 21:58发布

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条回答
ら.Afraid
2楼-- · 2019-08-08 22:24

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.

查看更多
登录 后发表回答