NOTE:这个答案已被弃用,因为 Android Studio 不再提供explored-aar
目录。
为了获得更好的解决方案,使用来自aar
,检查库androidNativeBundle https://github.com/howardpang/androidNativeBundle
Here https://github.com/WanghongLin/OpenCV4Android是一个基于的可行示例OpenCV
,你可以为你做同样的事情first lib
.
准备第一个库如下
包装jar
, *.so
,并导出headers
(参见文件OpenCV4Android/opencv/build.gradle
在链接的项目中如何将标题附加到 aar)。
You get first.aar
例如从建筑物first lib
.
在其他项目中使用第一个库
Add the first.aar
当您需要时,可以在您的其他项目中使用。
allprojects {
repositories {
jcenter()
flatDir {
dirs '/path/to/aar'
}
}
}
// in your app's build.gradle
dependencies {
// ...
compile 'com.example:example-with-header@aar'
// ...
}
链接到您的本机库first.aar
来自您的本机构建系统。
如果你使用CMake
,它应该看起来像这样
add_library(first
SHARED
IMPORTED)
set_target_properties(
first
PROPERTIES IMPORTED_LOCATION
../../../../build/intermediates/exploded-aar/org.example/example-debug/jni/${ANDROID_ABI}/libfirst.so
# use find command to figure out the location of the first lib before use it, not sure if it's different in different build environment
# for android studio gradle plugin latest version use
# ../../../../build/intermediates/transforms/mergeJniLibs/debug/folders/2000/1f/main/lib/${ANDROID_ABI}/libfirst.so
)
# also use find command to figure the actual location of the exported header from aar
# this might be different in your environment for different version of gradle plugin
include_directories(build/intermediates/exploded-aar/com.example/example-debug/cpp/include)
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
first
${log-lib} )