hello guys i have aac decoder in my app
it was working great when i was on API level 22 ..
but when i was using API level 23 .. my app goes crash and gives me an error unable to lib files
java.lang.UnsatisfiedLinkError: dlopen failed:
i was search lots of pages but nothing helping found ..
problem was only on latest version of android .. app was working great in older version of android ..
here is my libs
aacdecoder-android-libs-0.8.zip
|---src
|---main
|---jniLibs
> aacdecoder-android-0.8.jar
> armeabi
> libaacdecoder.so
> armeabi-v7a
> libaacdecoder.so
> mips
> libaacdecoder.so
> x86
> libaacdecoder.so
how i can load libs in latest version of android M
i also tried
System.loadLibrary("src/main/amn/armeabi/libaacdecoder.so");
System.loadLibrary("src/main/amn/armeabi-v7a/libaacdecoder.so");
System.loadLibrary("src/main/amn/mips/libaacdecoder.so");
System.loadLibrary("src/main/amn/x86/libaacdecoder.so");
System.loadLibrary("src/main/amn/aacdecoder-android-0.8.jar");
but nothings works :(
thank you in advance .. m waiting
I have fixed this problem for api 26 So:
1- you need to implments this new library :
https://github.com/hichemcesar24/AACDecoder
2- you need to change in gradle I am using below this code:
android {
compileSdkVersion 26
buildToolsVersion '26.0.1'
defaultConfig {
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "0.8"
group = 'com.spoledge.aacdecoder'
version = '0.8-SNAPSHOT'
ndk { stl "gnustl_static" }
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = []
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
task ndkBuild(type: Exec) {
// def ndkDir =plugins.getPlugin('com.android.library').sdkHandler.getNdkFolder()
def ndkDir = project.android.ndkDirectory.absolutePath
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine "$ndkDir/ndk-build.cmd", '-C', file('src/main/jni').absolutePath
} else {
commandLine "$ndkDir/ndk-build", '-C', file('src/main/jni').absolutePath
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
3- change classpath of build gradle to :
classpath 'com.android.tools.build:gradle:2.2.2'
4- if have problem in gradle So you need to delete :
def ndkDir = project.android.ndkDirectory.absolutePath
and changed with this:
def ndkDir =plugins.getPlugin('com.android.library').sdkHandler.getNdkFolder()
Related
I'm working on a PDF viewer application using ebookdroid & MuPDF CPP files. I am having lots of problem with NDK integration in Gradle. I've gone through many answers but they have not fixed my problem.
Gradle is giving me the following error message:
Error:Execution failed for task ':app:compileDebugNdk'.
Error: Your project contains C++ files but it is not using a supported native build system.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
Edit your build.gradle, add defaultConfig.externalNativeBuild.ndkBuild, externalNativeBuild.ndkBuild and sourceSet.main.jni.srcDir options. See the comments below.
android {
compileSdkVersion 22
buildToolsVersion "27.0.0"
defaultConfig {
minSdkVersion 18
targetSdkVersion 22
versionCode 1
versionName "1.0"
//add arguments passed to ndkBuild
externalNativeBuild {
ndkBuild {
arguments "NDK_TOOLCHAIN_VERSION=clang", "APP_SHORT_COMMANDS=true", "APP_ALLOW_MISSING_DEPS=true"
arguments "-j" + Runtime.runtime.availableProcessors()
cFlags "-fexceptions"
}
}
ndk {
abiFilters "armeabi-v7a"
}
}
//specify jni source file path
sourceSets.main {
java.srcDir "src"
res.srcDir "res"
jni.srcDir "jni"
}
buildTypes {
debug {
debuggable true
jniDebuggable true
}
}
//specify makefile / CMake file
externalNativeBuild {
ndkBuild {
path 'jni/Android.mk'
}
}
}
I am trying to install Superpowered example app on my phone using Android Studio but it's not getting built. It shows an error:
Error:Execution failed for task ':app:ndkBuild'.
> A problem occurred starting process 'command 'null/ndk-build''
build.gradle code is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.superpowered.hlsexample"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = []
}
}
task ndkBuild(type: Exec) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir')
commandLine "$ndkDir/ndk-build", '-B', '-C', file('src/main/jni').absolutePath
// Windows users: commandLine "$ndkDir\\ndk-build.cmd", '-B', '-C', file('src/main/jni').absolutePath
}
lintOptions {
abortOnError false
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
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.2.0'
}
Please help me find the right solution. And/Or guide me on how to add NDK to the current app. Thanks in Advance.
Just had same problem. Solved it by entering "File -> Project Structure". For my case "Android NDK location" was empty as shown. Clicking "Select" fixed it.
Open local.properties. Set ndk.dir to your ndk folder.
Just add
ndk.dir=
with you ndk folder in local.properties
I downloading the Tango C examples and opened point-cloud-jni-example in Android Studio. I have ndk installed and added ndk.dir=E:\Android\sdk\ndk-bundle to my local.properties file. Gradle syncs without errors, but when I run, I get this error:
Error:Execution failed for task ':app:ndkBuild'.
A problem occurred starting process 'command 'E:\Android\sdk\ndk-bundle/ndk-build''
I get the same error with motion-tracking-jni-example and hello-tango-jni-example and I assume the others as well.
What am I doing wrong?
build.gradle (app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.projecttango.experiments.nativepointcloud"
minSdkVersion 19
targetSdkVersion 19
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [];
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task ndkBuild(type: Exec) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkbuild = properties.getProperty('ndk.dir', null)+"/ndk-build"
commandLine ndkbuild, '-C', file('src/main/jni').absolutePath
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
build.gradle (Project):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
My system:
Windows 8.1 64 bit
Android Studio 1.3 (AI-141.2117773)
NDK r10e extracted to E:\Android\sdk\ndk-bundle
Device: Project Tango Tablet with Schur core
You need to append '.cmd' to the ndkbuild command. By that, I mean that the line
def ndkbuild = properties.getProperty('ndk.dir', null)+"/ndk-build"
should read
def ndkbuild = properties.getProperty('ndk.dir', null)+"/ndk-build.cmd"
It was no fault of your own, I noticed the same issue when I went to compile on my Surface.
I am trying to build the tutorials that are bundled with gstreamer-sdk-android-arm-debug-2013.6. The Android.mk file in the src/jni directory (tutorial 1 project) references environment variables such as GSTREAMER_SDK_ROOT. From what I have read, Android Studio does not use/pass environment variables to the build scripts. Is there a best practice for modifying makefiles and for defining/retrieving the key/value pairs required by the build scripts?
Ok, I have a working solution. You CAN pass environment variables to ndk-build (or any other process spawned by gradle Exec). In my case, I wanted to set these for both the clean and build tasks. This is is done using tasks.withType(Exec). The environment parameter is set here for all Exec tasks.
For GSTREAMER_SDK_ROOT, I added an entry to local.properties:
gst.dir=/Users/svenyonson/sdk/gstreamer-sdk-android-arm-debug-2013.6
For PATH, I used the default for the spawned process and added in what I needed.
Here is a working version of build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.gst_sdk_tutorials.tutorial_1"
minSdkVersion 19
targetSdkVersion 19
}
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir 'src/main/libs'
java.srcDirs += 'src/main/jni/src'
}
tasks.withType(Exec) {
def localProperties = new Properties()
localProperties.load(project.rootProject.file('local.properties').newDataInputStream())
def gstDir = localProperties.getProperty('gst.dir')
environment = [:]
environment['PATH'] = System.getenv("PATH")+ ":/usr/local/bin"
environment['GSTREAMER_SDK_ROOT'] = gstDir
}
task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = project.plugins.findPlugin('com.android.application').getNdkFolder()
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath,
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_DEBUG=1',
'V=1',
'APP_PLATFORM=android-19'
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = project.plugins.findPlugin('com.android.application').getNdkFolder()
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath,
'clean'
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
The project now builds and runs. The only other things you will need to do is add ndk.dir to local.properties:
sdk.dir=/Users/svenyonson/sdk/android-sdk
ndk.dir=/Users/svenyonson/sdk/android-ndk-r9d
gst.dir=/Users/svenyonson/sdk/gstreamer-sdk-android-arm-debug-2013.6
One more thing: These examples will not build using android-ndk-r10d. Be sure to use android-ndk-r9d.
Hi. I'm in Android Studio NDK Build trouble. I've not used native library. just java classes for library use and JNI c or header files.
So I've confused how to write gradle file for my project(saskin library ; I'm studying it).
Please help me~!
Error message
Error:Execution failed for task ':app:buildNative'.
A problem occurred starting process 'command 'C:\NDK/ndk-build''
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 8
buildToolsVersion "21.1.1"
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets {
main {
jni.srcDirs = []
//jniLibs.srcDir 'src/main/libs'
}
}
defaultConfig {
applicationId "com.sasken.player"
minSdkVersion 8
targetSdkVersion 8
ndk {
moduleName "equalizer"
}
}
// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
commandLine 'ndk-build', '-C', file('src/main/jni').absolutePath
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
dependencies {
}
since you're using Windows, you should call ndk-build.cmd instead of ndk-build, from your ndkBuild task.
To make your gradle file work on windows and unix-compatible systems you can modify your task this way:
import org.apache.tools.ant.taskdefs.condition.Os
// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
} else {
commandLine 'ndk-build', '-C', file('src/main').absolutePath
}
}
Also, as you're using ndk-build directly, the ndk will generate your libraries inside the libs folder, so you should uncomment jniLibs.srcDir 'src/main/libs' inside your gradle file, in order for your generated libs to be taken in account.