How to introduce the third-party so file? However, the third-party official only gives the integration mode in ADT environment.
Android studio uses gradle compiling mode by default, which is different from ADT editing mode, so how should so files be introduced?
It's very simple. Here, take the integrated JPUSH as an example to see how the so file can be introduced into the compilation environment, and finally can be called directly by JNI.
First, create the libs directory in the root directory of our Module, and copy the so files in the jpush integration SDK, as shown in the screenshot:
Then we write our build.gradle file.
The configuration of so file is very simple. The code configuration is as follows:
- 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)
- }
Customize a task to specify the directory of so files that the project depends on. Here * * / *. So is used to write. In order to save time, specify the directory to be copied into into "lib". Then the dynamic runtime will be copied into the Lib directory.
The complete build.gradle file is as follows:
- apply plugin: 'com.android.application'
- android {
- compileSdkVersion 21
- buildToolsVersion "21.1.0"
- defaultConfig {
- applicationId "com.wujay.footerballstar"
- minSdkVersion 8
- targetSdkVersion 21
- versionCode 1
- versionName "1.0"
- }
- buildTypes {
- release {
- runProguard false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
- 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 {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'com.android.support:appcompat-v7:21.0.0'
- compile files('libs/jpush-sdk-release1.7.2.jar')
- compile files('libs/umeng_sdk.jar')
- compile files('libs/libammsdk.jar')
- }
Based on someone's questions in the comment area, here's a quick way to configure
In the build.gradle configuration, configure the following information:
sourceSets { main { jniLibs.srcDirs = ['libs'] } }
Your so package can be placed in the same directory as the jar package, such as lib/armeabi/libjpush172.so.