方法一:html
將libs文件夾下的so文件,經過gradle配置任務編譯成jar文件。java
apply plugin: 'com.android.library' android { compileSdkVersion rootProject.ext.compileSdkVersion buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion } /** 導入so文件 */ 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) } } dependencies { provided fileTree(dir: 'libs', include: ['*.jar']) }
參考資料:http://blog.csdn.net/wulianghuan/article/details/44567001android
方法二:git
經過插件將so文件依賴到jniLibs文件夾。github
參考資料:http://www.jcodecraeer.com/a/anzhuokaifa/Android_Studio/2015/0804/3256.htmlapp
插件/開源項目 :https://github.com/nhachicha/android-native-dependencieside
方法三:gradle
最佳方法。ui
android { sourceSets.main.jniLibs.srcDirs = ['libs'] compileSdkVersion rootProject.ext.compileSdkVersion buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion } }