建立在JNI文件夹本地库? [英] Build native library in JNI folder?

查看:144
本文介绍了建立在JNI文件夹本地库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Eclipse上的Andr​​oid测试JNI。

我有一个活动的简单的Andr​​oid项目。在Eclipse的项目资源管理器,我说:

  • JNI / 文件夹
  • Android.mk JNI / 文件夹
  • prng.c JNI / 文件夹

源文件被命名为 prng.c ,因为它包装的Crypto ++的随机数发生器。加密++已经是交叉编译的ARMv7的,所以我有 libcryptopp.so 待命。

当我选择的工程→建设项目的,该库未建。我已经证实了它的清洁项目,之后也未建。

  Android的PRNG $发现。 -iname *的.so
Android的PRNG $
 

问题:为什么Eclipse中的没有的构建共享对象?需要什么别的事情要做?


Android.mk

  LOCAL_PATH:= $(叫我-DIR)

包括$(CLEAR_VARS)

LOCAL_MODULE:= PRNG
LOCAL_SRC_FILES:= prng.c

包括$(BUILD_SHARED_LIBRARY)
 

prng.c

其基本空的时刻,因为我不能让 javah的来在调用本地方法的Java类文件运行。我希望下一个解决这个问题。

 的#include< string.h中>
#包括< jni.h>

#包括< cryptopp / osrandom.h>

静态RandomNumberGenerator和放大器; GetPRNG()
{
    静态AutoSeededRandomPool PRNG;

    返回PRNG;
}
 

解决方案

这其实很容易与ADT在过去的几年中;这是大不如前。中介绍的插件链接帖子来了preinstalled;你仍然需要

1安装NDK

2设置路径,它在 preferences /安卓/ NDK 菜单

3右击你的Andr​​oid项目, Android的工具/添加本机支持

...现在你都设置。

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

解决方案

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.

这篇关于建立在JNI文件夹本地库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆