- Home /
Include .so native file in an Android .aar file
I have a situation where I am building an android .aar file with android studio, and the java files reference some external native methods in the .so. However any effort I make to include the .so file in the aar file, whenever I do and try to use classes that reference the .so functions, my app crashes on load without error or any way for me to track what the issue is.
This is my gradle build file..
apply plugin: 'com.android.library'
def NATIVE_LIB_DIR = 'jniLibs/armeabi-v7a/'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
sourceSets {
main {
jniLibs.srcDirs = ["jniLibs"]
}
}
defaultConfig {
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
arm {
ndk {
abiFilters "armeabi-v7a", "armeabi"
}
}
}
}
dependencies {
provided fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.0'
}
android.libraryVariants.all { variant ->
// Task names.
String variantName = "${variant.name.capitalize()}"; // Like 'Debug'
String deployTaskGroup = "plugin";
String deployTaskName = "deploy${variantName}PluginArchive"; // Like 'deployDebugPluginArchive'
String dependencyTaskName = "assemble${variantName}"; // Like 'assembleDebug'
// Source.
String sourceAARFolder = "${buildDir.getPath()}/outputs/aar/";
String sourceAARName = "${project.name}-${variant.name}.aar";
// Target.
String targetAssetFolder = "Assets/Plugins/Android";
String targetAARFolder = "${rootDir.getPath()}/../${targetAssetFolder}"; // Navigate into 'Assets'
String targetAARName = "SrvrRemote.aar"; // The form you ship your plugin
// Create task.
task(deployTaskName, dependsOn: dependencyTaskName, type: Copy) {
logger.lifecycle("${variant.name.capitalize()} AAR Folder: ${sourceAARFolder}")
logger.lifecycle("${variant.name.capitalize()} Target AAR Folder: ${targetAARFolder}")
logger.lifecycle("${variant.name.capitalize()} Target AAR name: ${targetAARName}")
from(sourceAARFolder)
into(targetAARFolder)
include(sourceAARName)
rename(sourceAARName, targetAARName)
}.group = deployTaskGroup;
}
you should include the runtime code (how you're attempting to load the native library and call it), as well as the actual crash message.
Your answer
Follow this Question
Related Questions
Can handheld.PlayfullScreenMovie() work with Vr view to play 360 degree video using google vr sdk? 0 Answers
Sending information from android game to android app via Bluetooth/Wifi-Direct 0 Answers
How to suppress system bars on Android? 2 Answers
Many problems using the new Cardboard unity3D integration 0 Answers
[BUG] Can't use postprocessing with single-pass stereo rendering enabled (5.6, GearVR) 2 Answers