Android studio uses Gradle compilation method by default, which is different from ADT editing method. so how should the SO file be imported?
It's actually quite simple. Here, taking the integrated JPUSH as an example, let's see how the so file is introduced into the compilation environment. Finally, the so file can be directly called to JNI.
Firstly, establish the libs directory under the root directory of our module, and copy the so files in the jpush integrated SDK respectively. The screenshot is as follows:
Then write our build.gradle file.
The configuration introduced by the so file is very simple, and the code configuration is as follows:
[html]? View the plain? Copy? Print?
Mission? NativeLibsToJar (type:? Zip? Description:? "Create? Answer? A jar? Archive? Yes? That? Native? libs”)? {?
destinationDir? File ("$projectDir/libs")?
baseName? “Native_Libs2”?
Extension? "jar"
From where? File tree (directory:? “libs”,? Including:? "* */*. So")?
Become? “lib”?
}?
tasks.withType(JavaCompile)? {?
compileTask? -& gt; ? compile task . dependson(nativeLibsToJar)?
}?
Custom task, in which you specify the directory of so files on which the project depends. Here, you use * */*. So write it. To save trouble, you specify the directory to be copied to "lib", and then the dynamic runtime will be copied to the lib directory.
The complete build.gradle file is as follows:
[html]? View the plain? Copy? Print?
Apply? Plug-in:? ' com.android.application '?
Android? {?
compileSdkVersion? 2 1?
buildToolsVersion? "2 1. 1.0"?
defaultConfig? {?
applicationId? " com.wujay.footerballstar "?
minSdkVersion? 8?
targetSdkVersion? 2 1?
versionCode? 1?
versionName? " 1.0"?
}?
Build type? {?
Release? {?
runProguard? Fake?
proguardFiles? getDefaultProguardFile(' proguard-Android . txt '),? proguard-rules.pro?
}?
}?
Mission? NativeLibsToJar (type:? Zip? Description:? "Create? Answer? A jar? Archive? Yes? That? Native? libs”)? {?
destinationDir? File ("$projectDir/libs")?
baseName? “Native_Libs2”?
Extension? "jar"
From where? File tree (directory:? “libs”,? Including:? "* */*. So")?
Become? “lib”?
}?
tasks.withType(JavaCompile)? {?
compileTask? -& gt; ? compile task . dependson(nativeLibsToJar)?
}?
}?
Dependence? {?
Compile? File tree (directory:? libs ',? Including:? ['*.jar'])?
Compile? com . Android . support:app compat-V7:2 1 . 0 . 0 '?
Compile? File ('libs/jpush-SDK-release1.7.2.jar')?
Compile? files('libs/umeng_sdk.jar ')?
Compile? File ('libs/libammsdk.jar')?
}?