I have added the Gradle tag to this thread since I feel my build.gradle file is missing a needed configuration. Below is a copy of my file. The issue I am having is I don't know why my shared library files do not make it into my apks. And I think I see the tell tell signs of what I need in this file from reading the Gradle manual but I want to be sure.
sansari@ubuntu:~/AndroidStudioProjects/ThirdNDK/app$ more build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.sansari.thirdndk"
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk
{
moduleName "HelloJNI"
}
}
sourceSets.main
{
jni.srcDirs = [] // ndk-build.cmd needs to be invoked from command line
jniLibs.srcDirs '/src/main/libs'
}
productFlavors
{
x86
{
ndk
{
abiFilter "x86"
}
}
armv7a
{
ndk
{
abiFilter "armeabi-v7a"
}
}
arm {
//flavorDimension "abi"
ndk
{
abiFilter "armeabi"
versionCode = 1;
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
}
I am trying a native code project in Android Studio, and I get the following error. But I don't know why the loader is looking in that directory. Or why the folder is called com.example.sansari.thiredndk-1. I just called my project thirdndk. I am not sure how -1 is added. I wanted to know how can I fix this, and learn why the loader is looking in that directory? My /libs folder is in the main directory of the project.
java.lang.UnsatisfiedLinkError: Couldn't load HelloJNI from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.example.sansari.thirdndk-1.apk,libraryPath=/data/app-lib/com.example.sansari.thirdndk-1]: findLibrary returned null
@Preethi. Thanks; I'll have a look. I typed it rather quickly.
@Preethi or anyone else; I don't seem to have any luck with this. Here is the apk:
Thank you all for your help. It finally worked. I googled "how to add library files to apk with gradle", and this little gem came up: "Include .so library in apk in android studio [duplicate]" It is on stackoverflow. I am not sure if I have permission to post urls yet. In it, there was comments about a bug in earlier versions of Gradle for including libraries. One of the links in it had a comment about using the jniLibs folder as the directory to put shared libraries in. So I took a chance and copied all of my shared libraries files from libs to jniLibs. I created jniLibs and copied the files and voila. Thank you again to all of you. You guys rock.
if your .so files are now generated inside libs/<abi>, the only remaining step is to make Android Studio integrate these files from the libs folder.
By default, it looks for .so files inside jniLibs, but you can change it so integrates the files from your libs folder:
android {
...
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With