首先,在我们的Module的根目录中建立libs目录,将jpush集成SDK中的so文件分别拷入,截图如下:
然后就是编写我们的build.gradle文件。
关于so文件引入的配置很简单,代码配置如下:
[html] view plain copy print?
task nativeLibsToJar(type: Zip, description: "create a jar archive of the native libs") {
destinationDir file("$projectDir/libs")
baseName "Native_Libs2"
extension "jar"
from fileTree(dir: "libs", include: "**/*.so")
into "lib"
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
自定义一个任务,在其中指定项目所依赖的so文件的目录,这里用了**/*.so来写,为了省事,指定需要拷入的目录 into "lib",那么动态运行库就被拷入到lib目录中。
build.gradle中sourceSets->main加入jniLibs.srcDirs = ['libs']然后把so文件放到libs目录下即可sourceSets {main {manifest.srcFile 'AndroidManifest.xml'java.srcDirs = ['src']resources.srcDirs = ['src']aidl.srcDirs = ['src']renderscript.srcDirs = ['src']res.srcDirs = ['res']assets.srcDirs = ['assets']jniLibs.srcDirs = ['libs']}// Move the tests to tests/java, tests/res, etc...instrumentTest.setRoot('tests')// Move the build types to build-types/<type>// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...// This moves them out of them default location under src/<type>/... which would// conflict with src/ being used by the main source set.// Adding new build types or product flavors should be accompanied// by a similar customization.debug.setRoot('build-types/debug')release.setRoot('build-types/release')}在src/main中添加 jniLibs文件夹 ,把.so复制进去在build.gradle中就添加这么几行
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
然后make project
切换到android结构下,你会看到 jniLibs 中.so已经变成了.jar文件,证明已经成功
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)