包括使用NDK pre-编译静态库 [英] Include Pre-compiled Static LIbrary using NDK
问题描述
我期待有一个静态库,pre-编译在我的Android NDK工作室项目。我使用的是Android 1.0.1工作室,并尝试在所以这个问题的任何解决方案似乎已经过时(或包括创建库项目,包括它)。
的结构如下:
应用
/ - SRC
/ - 主要
/ - java的
+ - JNI
+ - jniLibs
/ - armeabi
/--libpng.a
--armeabiv7
/--libpng.a
...(每个ABI)
我试图包含库的libpng。我尝试创建jniLibs(按照 ph0b (真棒指导,顺便说一句),并加入libpng.a ,到相应的文件夹ABI这仍然给我的错误 - 找不到-llibpng 的,当我尝试编译下面code:
NDK {
MODULENAME游戏
CFLAGS-std = C ++ 11 -fexceptions -DANDROID -I $ {project.buildDir} /../钢骨混凝土/主/ JNI /包括\
-I $ {project.buildDir} /../钢骨混凝土/主/ JNI /有/ PNG
LDLIBS东瀛,GLESv3,DL,日志,机器人,的libpng
STLgnustl_static
}
你不能只包含.so文件,你还需要有在src的文件夹,实际上提供接口来访问这些方法在那些.so文件。我会建议对连接您的项目库的方式。
最好的办法是将它作为从机器人工作室库模块并丢弃JNI文件夹禁用ndkbuild并通过添加以下到build.gradle文件指向jnilib到/ libs文件夹
jni.srcDirs = [] //禁用自动NDK建造通话
jniLibs.srcDirs = ['库'] //不需要的.so文件从/库复制到/ jniLibs文件夹
(检查库目录也已导入正确用机器人工作室与.so文件)
导入库作为一个模块将自动以下的护理
A)的 yourlibrary 的根据摇篮会议库文件夹中的项目文件夹和调整 在settings.gradle)和照片:二)进口项目(包括'的 yourlibrary 的' C)创建的依赖关系(文件 - >项目结构 - >从左边的子窗口中,选择主要的应用程序模块 - >相关性(最后一个标签) - > preSS绿色的+你的右键 - > yourlibrary 的作为模块依赖关系 - >确定)
I am looking to include a static library that is pre-compiled in my Android Studio NDK project. I am using Android Studio 1.0.1, and any solutions that attempt this problem on SO seem outdated (or involves creating a library project and including it).
The structure is as follows:
app
/--src
/--main
/--java
+--jni
+--jniLibs
/--armeabi
/--libpng.a
--armeabiv7
/--libpng.a
...(for each abi)
I am attempting to include the library libpng. I tried creating jniLibs (as per ph0b (awesome guide, btw) and adding libpng.a to the respective ABI folder. This still gives me the error - cannot find -llibpng when I try to compile with the below code:
ndk {
moduleName "game"
cFlags "-std=c++11 -fexceptions -DANDROID -I${project.buildDir}/../src/main/jni/include \
-I${project.buildDir}/../src/main/jni/include/png"
ldLibs "EGL", "GLESv3", "dl", "log", "android", "libpng"
stl "gnustl_static"
}
you cannot just include the .so files, you also need to have the src folders that actually provide the interface to access the methods in those .so files. I would recommend against coupling your project to the library that way.
The best way is to include it as a library module from android studio and discard the jni folders to disable ndkbuild and point the jnilib to the /libs folder by adding following to the build.gradle file
jni.srcDirs = [] //disable automatic ndk-build call
jniLibs.srcDirs = [ 'libs' ] //no need to copy the .so files from /libs to /jniLibs folder
(check that the libs directory has also been imported correctly by android studio with .so files)
importing the library as a module takes care of following automatically
a)yourlibrary library folder in your project folder and restructured according to gradle convention b)imported the project(include ':yourlibrary' in settings.gradle) and
c)created the dependencies ("File -> Project Structure -> Select main app module from the left subwindow -> Dependencies (last tab) -> Press the green "+" on your right -> yourlibrary as Module Dependency -> OK")
这篇关于包括使用NDK pre-编译静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!