更改 ndk-build 输出位置 [英] Change ndk-build output locations
问题描述
我的应用程序具有以下结构
My app has the following structure
Android
|
|-> app
| |
| |-> build [1]
| |-> src
| | |-> main
| | | |-> assets
| | | |-> java
| | | |-> jni
| | | | |-> Android.mk
| | | | |-> Application.mk
| | | |
| | | |-> jniLibs
| | | | |-> armeabi
| | | | |-> armeabi-v7a
| | | |
| | | |-> res
| | | |-> AndroidManifest.xml
|
|-> build [2]
我正在 Linux 机器上使用 ndk-build
命令构建我的 .so
库.我像这样使用它:
I am building my .so
libraries with ndk-build
command in a linux machine. I use it like:
<my_ndk_path>/ndk-build -C <my_project_path>/Android/app/src/main/
构建过程工作正常,生成的输出文件没有错误.
The build process works fine and output files are produced with no errors.
我的问题是结果文件没有指向正确的位置"
My problem is that the result files are not "directed to the proper position"
libs
生成于:
.app/src/main/libs/armeabi-v7a/libMyGeneratedLibrary.so
.app/src/main/libs/armeabi/libMyGeneratedLibrary.so
和 obj
文件位于:
.app/src/main/obj/local/armeabi-v7a/libMyGeneratedLibrary.so
.app/src/main/obj/local/armeabi/libMyGeneratedLibrary.so
我希望在不同位置生成输出:
I would like the output to produced in different locations:
jniLibs
中的libs
.IE../app/src/main/jniLibs/armeabi*
- 构建文件夹之一下的
obj
.IE.build
[1] 或build
[2].
- The
libs
atjniLibs
. ie../app/src/main/jniLibs/armeabi*
- The
obj
under one of the build folders. ie.build
[1] orbuild
[2].
是否有任何可能的方法可以通过将某些参数更改为 .mk
文件或构建命令来实现?
Is there any possible way to achieve that by changing some parameter to the .mk
files or to the build command?
编辑
TARGET_OUT
在 NDK r6b 中似乎不起作用
TARGET_OUT
does not seem to work in NDK r6b
执行命令ndk-build -C Android/app/src/main/TARGET_OUT='Android/app/src/main/jniLibs/$(TARGET_ARCH_ABI)'
每个生成的文件都会出现如下警告.
Warnings as the following appear for each generated file.
android-ndk-r6b/build/core/build-binary.mk:217: warning: overriding commands for target 'Android/app/src/main/jniLibs//objs/***/****.o'
android-ndk-r6b/build/core/build-binary.mk:217: warning: ignoring old commands for target 'Android/app/src/main/jniLibs//objs/***/****.o'
推荐答案
编辑(适用于使用较新 NDK 版本涉足此主题的任何人):
Edit (for anyone that step on this topic with newer NDK versions):
- 使用
NDK_LIBS_OUT
更改库输出(需要 NDK r9 及更高版本) - 使用
NDK_OUT
改变obj输出(需要NDK r7c及以上)
- Use
NDK_LIBS_OUT
to change libs output (requires NDK r9 and above) - Use
NDK_OUT
to change obj output (requires NDK r7c and above)
构建命令是:
ndk-build NDK_LIBS_OUT=./jniLibs NDK_OUT=./obj
上一个答案(适用于任何情况):
我是怎么解决的.不是很优雅,但至少它有效.
How I solve it. Not really elegant but at least it works.
因为我的构建机制非常复杂,所以我也有几个自定义的 gradle 任务和脚本,所以构建的单个命令对我来说并不重要.
Because my building mechanism is quite complicated so I had a couple of custom gradle tasks and scripts too, it doesn't really matter to me the single command for the build.
所以我按原样保留了构建命令
So I kept build command as is
<my_ndk_path>/ndk-build -C <my_project_path>/Android/app/src/main/
添加文件夹创建(-p 如果存在则不产生错误)
Add a the folder creation (-p don't generate error if it exists)
mkdir -p <my_project_path>/Android/app/src/main/jniLibs/
然后我使用同步命令将 .so 文件移动到最终位置.
Then I move the .so files to the final location with the sync command.
rsync -avh --remove-source-files \
<my_project_path>/Android/app/src/main/libs/* \
<my_project_path>/Android/app/src/main/jniLibs/
您可以对 obj
文件夹执行类似的操作.我刚刚修改了我的 .gitignore,所以我保持原样.
You can do something similar for the obj
folder. I just modified my .gitignore so I left it as is.
这篇关于更改 ndk-build 输出位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!