How can I add .so files to an android library project using gradle 0.7+
In the end I didnt need to use product flavours.
For the library project I added the following:
android {
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}
The libs folder had a folder inside called "armeabi-v7a" and as this is my only target it worked a treat.
The ndk files (.so) are propagated into the android project that is using the android library project.
Add pre-built .so files in project using Android Gradle plugin 0.7.3
So how you can add the pre-built .so files ?
1) Upgrade your android studio to 0.4.0
2) Replace "distributionUrl=" in gradle-wrapper.properties with "distributionUrl=http://services.gradle.org/distributions/gradle-1.9-all.zip"
3) Add/Replace your 'buildscript' section build.gradle with:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.3'
}
}
4)
5) Add the following in your build.gradle:
android {
compileSdkVersion 18
buildToolsVersion "18.1.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
productFlavors {
x86 {
ndk {
abiFilter "x86"
}
}
arm {
ndk {
abiFilters "armeabi-v7a", "armeabi"
}
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
}
}
6) Build your project.
Adding a .so file in Android Studio
You can add pre built *.so files in Android Studio using gradle 0.7.2+. First create the jniLibs at this location /app/src/main/ location and copy the all the folder with *.so files (armeabi, armeabi-v7a, mips, x86) in the jniLibs.
Include .so library in apk in android studio
I had the same problem. Check out the comment in https://gist.github.com/khernyo/4226923#comment-812526
It says:
for gradle android plugin v0.3 use "com.android.build.gradle.tasks.PackageApplication"
That should fix your problem.
Android Studio - include and consume .so library
Thank you guys for helping but it was a stupid problem. When I imported my .so
files under jniLibs
, they were named like libSONAME.so
. In these lines of code:
static {
System.loadLibrary("libSONAME");
}
we should not use System.loadLibrary("libSONAME");
, but just System.loadLibrary("SONAME");
.
Then, just build the project and everything was OK.
Thank you all for helping. I hope this will save time to someone else.
Related Topics
How to Enable and Disable a Component
Cannot Create an Instance of Class Viewmodel
Asynctask, Must It Take Such a Performance Penalty Hit...
Fragmentactivity Cannot Be Resolved to a Type
Android Maps API V2 Draw Circle
Android: Onsaveinstancestate Not Being Called from Activity
Android - Getting from a Uri to an Inputstream to a Byte Array
How to Force a Cache Clearing Using Universal Image Loader Android
Screen Overlay Detected Blocks Android Permissions
In Espresso, How to Avoid Ambiguousviewmatcherexception When Multiple Views Match
How to Use Data Binding and Kotlin in Android Studio 3.0.0
How to Get the Battery Level After Connect to the Ble Device
Hax Kernel Module Is Not Installed
Android Dialog, Keep Dialog Open When Button Is Pressed
Start Google Hangout from Intent in New Hangouts Android App
After Update of as to 1.0, Getting "Method Id Not in [0, 0Xffff]: 65536" Error in Project