Unable to build GStreamer tutorials using Android Studio - android

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.

Related

NDK messes with external dependency in Android Studio

I have been working on an app which uses an external library packaged in a .aar file. In the gradle file I only had to add
compile project(':empalink-2.0')
And it worked ok so far. Now I wanted to add a port of the libSVM library, which makes me to copy the jni directory into my app/src/main and then add some code from their gradle file, which ends up like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.csic.iiia.ActivityRecognition"
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
moduleName "jnilibsvm" // <-- This is the name of my C++ module!
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets.main {
jniLibs.srcDir 'src\\main\\libs'
jni.srcDirs = []
}
task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir\\ndk-build.cmd",
'-C', file('src\\main\\jni').absolutePath, // Change src/main/jni the relative path to your jni source
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_DEBUG=1'
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir\\ndk-build.cmd",
'-C', file('src\\main\\jni').absolutePath, // Change src/main/jni the relative path to your jni source
'clean'
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.loopj.android:android-async-http:1.4.6'
compile project(':empalink-2.0')
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
compile 'org.apache.commons:commons-math3:3.6.1'
}
The added parts are the defaultConfig.ndk and the build/cleanNative stuff.
Now when trying to execute the application, I receive the following error:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.csic.iiia.ActivityRecognition-1/base.apk"],nativeLibraryDirectories=[/data/app/com.csic.iiia.ActivityRecognition-1/lib/arm64, /data/app/com.csic.iiia.ActivityRecognition-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]] couldn't find "libempac.so"
That lilbempac.so is the .so file that comes in the .aar file that was working ok until I added the libSVM to the project. I guess that enabling NDK compilation somehow affected the linkage with the external dependency :empalink-2.0.
This is maybe a late answer but ...
Empatica only provides the armeabi version of libempac.so. But if you add other native libraries, gradle will compute other architectures like armeabi-v7a, mips, mips64, etc. And so the libempac will be available only for one this architectures.
So you need to disable compilation for other architecture than armeabi. You can do this by adding this in app build.gradle file :
android {
[...]
splits {
abi {
enable true
reset()
include 'armeabi'
universalApk false
}
}
}

Android M API 23 error to load lib .so files

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()

Superpowered SDK: Error:Execution failed for task ':app:ndkBuild'. A dikkat occurred starting process 'command 'null/ndk-build''

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

Android Studio NDK Build trouble Error:Execution failed for task ':app:buildNative'

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.

Can't build project with android-ndk and Android Studio

I have an android project with FFmpeg and other external libraries. I downloaded the latest version of the ndk (ndk-r10) and am running Android Studio 0.8.0. I am also running Windows 8 64bit with the latest version of cygwin.
My project builds without issue and I added the ndk.dir to local.properties. When I try to run I get this error message:
The System cannot find the path specified
Error:Execution failed for task ':app:compileDebugNdk'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\John1\AppData\Local\Android\android-ndk-r10\ndk-build.cmd
NDK_PROJECT_PATH=null
APP_BUILD_SCRIPT=C:\Users\John1\AndroidstudioProjects\android-project\app\build\intermediates\ndk\debug\Android.mk
APP_PLATFORM=android-18
NDK_OUT=C:\Users\John1\AndroidstudioProjects\android-project\app\build\intermediates\ndk\debug\obj
NDK_LIBS_OUT=C:\Users\John1\AndroidstudioProjects\android-project\app\build\intermediates\ndk\debug\lib
APP_ABI=all
Error Code:
1
Output:
The system cannot find the path specified.
Looking for advice. Thank you.
with Android Studio, NDK support is preliminary and your *.mk files are ignored.
You can make Android Studio/gradle reuse them by deactivating the default NDK integration, make it call ndk-build(.cmd) by itself, and use standard libs/ location for integrating .so files:
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig{
minSdkVersion 15
targetSdkVersion 19
versionCode 101
versionName "1.0.1"
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
// 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
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
If you need more information, here is my blog post on this topic: http://ph0b.com/android-studio-gradle-and-ndk-integration/

Categories

Resources