GStreamer Android SDK error for tutorial-5 - android

We have taken clone of a project and made all settings as per instruction still not able to build app due to following error:
Error:(7, 10) fatal error: 'gst/gst.h' file not found
above error is in tutorial.c file:
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/video/videooverlay.h>
#include <pthread.h>
GST_DEBUG_CATEGORY_STATIC (debug_category);
#define GST_CAT_DEFAULT debug_category
Please find below gradle and Android.mk file which I have added to my project:
Gradle
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.ndktest"
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
arguments '-DANDROID_TOOLCHAIN=clang',
'-DANDROID_PLATFORM=android-19',
'-DANDROID_STL=gnustl_static',
'-DANDROID_ARM_NEON=TRUE',
'-DANDROID_CPP_FEATURES=exceptions rtti'
}
}
ndk {
moduleName "tutorial-5"
}
}
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir new File(buildDir, 'lib')
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
Android.mk
LOCAL_PATH := $(call my-dir)
GSTREAMER_ROOT_ANDROID := D:\ndk-gst1.9.1
SHELL := PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin /bin/bash
include $(CLEAR_VARS)
LOCAL_MODULE := tutorial-5
LOCAL_SRC_FILES := tutorial-5.c
LOCAL_SHARED_LIBRARIES := gstreamer_android
LOCAL_LDLIBS := -llog -landroid
include $(BUILD_SHARED_LIBRARY)
ifndef GSTREAMER_ROOT
ifndef GSTREAMER_ROOT_ANDROID
$(error GSTREAMER_ROOT_ANDROID is not defined!)
endif
GSTREAMER_ROOT := $(GSTREAMER_ROOT_ANDROID)
endif
GSTREAMER_NDK_BUILD_PATH := $(GSTREAMER_ROOT)/share/gst-android/ndk-build
include $(GSTREAMER_NDK_BUILD_PATH)/plugins.mk
GSTREAMER_PLUGINS := $(GSTREAMER_PLUGINS_CORE) $(GSTREAMER_PLUGINS_PLAYBACK) $(GSTREAMER_PLUGINS_CODECS) $(GSTREAMER_PLUGINS_NET) $(GSTREAMER_PLUGINS_SYS) $(GSTREAMER_PLUGINS_CODECS_RESTRICTED)
G_IO_MODULES := gnutls
GSTREAMER_EXTRA_DEPS := gstreamer-video-1.0
include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer-1.0.mk
Please suggest what changes need to be done in above code to make it run.

I already answered a similar question... The problem with the official tutorials from the Gstreamer site is that they are old and made for Eclipse. Maybe your error is because you didn't link your Android Studio project to the C++ files... to do it follow the second step from this answer: Gstreamer examples in Android Studio
Since the linking with C++ files ins't the only error that will occurs I also suggest that you follow all other steps. There's a link for gitlab project with "turorial 5" working in the link above.

Related

What is the equivalent of target_link_libraries in Android.mk

I am trying to compile an android project using Android.mk and need to include the following libraries: native-audio-jni android log OpenSLES.
A similar project (https://github.com/googlesamples/android-ndk/tree/master/native-audio), which includes the same libraries but uses CMakeLists.txt instead of Android.mk has this line in the CMakeLists.txt:
target_link_libraries(native-audio-jni android log OpenSLES)
This sample project builds and runs fine.
Based on findings from my online research on the topic, I have tried including the following lines in my Android.mk file, which is in the jni folder:
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lOpenSLES -lnative-audio-jni
LOCAL_LDLIBS += -landroid
ldLibs = ["android", "log", "native-audio-jni", "OpenSLES"]
LOCAL_SHARED_LIBRARIES += libandroid
LOCAL_LDLIBS := -llog
However, I still get errors like:
undefined reference to `AAssetManager_fromJava'
undefined reference to `AAssetManager_open'
undefined reference to `SL_IID_SEEK'
undefined reference to `SL_IID_MUTESOLO' ...
I also have the following includes in my .c file where the errors are generated:
// for native audio
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>
// for native asset manager
#include <sys/types.h>
#include <android/asset_manager.h>
#include <android/asset_manager_jni.h>
#include <android/log.h>
So my question is: How to add these libraries to my Android.mk or in other words: What is the equivalent of target_link_libraries(native-audio-jni android log OpenSLES) in Android.mk? For a number of reasons I need to use Android.mk instead of CMakeLists.txt in my project.
Here also is my build.gradle if this is of any help:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.google.ar.sceneform.samples.drawing"
// 24 is the minimum since ARCore only works with 24 and higher.
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
ndk {
//ldLibs "android", "log", "native-audio-jni", "OpenSLES" // Not helping
/*
* Sceneform is available for the following ABIs: arm64-v8a, armv7a,
* x86_64 and x86. This sample app enables arm64-v8a to run on
* devices and x86 to run on the emulator. Your application should
* list the ABIs most appropriate to minimize APK size (arm64-v8a recommended).
*/
abiFilters 'arm64-v8a' ,'x86' // , 'armeabi-v7a'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
ndkBuild {
path '../jni/Android.mk'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
//implementation fileTree(dir: 'libs', include: ['*.jar']) // NOT helping
implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.7.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation files('Libs/YouTubeAndroidPlayerApi.jar')
implementation 'com.github.barteksc:android-pdf-viewer:2.0.3'
implementation 'com.xw.repo:bubbleseekbar:3.19-lite'
}
repositories {
mavenCentral()
}
apply plugin: 'com.google.ar.sceneform.plugin'
sceneform.asset('sampledata/models/andy.obj',
'default',
'sampledata/models/andy.sfa',
'src/main/res/raw/andy')
And my Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include $(CLEAR_VARS)
LOCAL_MODULE := aubio
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libaubio.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := pitch
LOCAL_SRC_FILES := pitch.c
LOCAL_SHARED_LIBRARIES := aubio
include $(BUILD_SHARED_LIBRARY)
LOCAL_LDLIBS := -llog -lOpenSLES -lnative-audio-jni -landroid
An this is a screenshot of the built error:
enter image description here
Your Android.mk got some unnecessary definitions that ruin happen to hide he correct one:
LOCAL_LDLIBS := -llog -lOpenSLES -lnative-audio-jni -landroid
instead of all the lines that you posted. NDK knows where to find these libraries, therefore -L$(SYSROOT)/… is not necessary, but only can hurt. The other lines probably come from frustration.

Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined?

recently (3 days ago) started learning Android Studio. I bought an Eclipse game project to play with, but I am getting errors. And when I fix that error, I get a new error. The current error is as following:
Build command failed. Error while executing process
C:\Users\user\AppData\Local\Android\Sdk\ndk-bundle\ndk-build.cmd with
arguments {NDK_PROJECT_PATH=null
APP_BUILD_SCRIPT=C:\APPS\app\src\main\jni\Android.mk
NDK_APPLICATION_MK=C:\APPS\app\src\main\jni\Application.mk
APP_ABI=armeabi NDK_ALL_ABIS=armeabi NDK_DEBUG=0
APP_PLATFORM=android-15
NDK_OUT=C:/APPS/app/build/intermediates/ndkBuild/release/obj
NDK_LIBS_OUT=C:\APPS\app\build\intermediates\ndkBuild\release\lib
APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n} Android
NDK: C:\APPS\app\src\main\jni\Android.mk: Cannot find module
with tag 'box2D' in import path Android NDK: Are you sure your
NDK_MODULE_PATH variable is properly defined ? Android NDK: The
following directories were searched: Android NDK:
process_begin: CreateProcess(NULL, "", ...) failed.
I have googled and I saw a few other people had asked this question on this forum, but I didn't understand how to fix it (again, I'm a complete beginner)
Here's my build.gradle (Module: app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.getemplate.catadventure"
minSdkVersion 15
targetSdkVersion 26
ndk {
moduleName "player_shared"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:+'
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
}
And here is my Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := player_shared
LOCAL_MODULE_FILENAME := libplayer
LOCAL_SRC_FILES := main.cpp
LOCAL_WHOLE_STATIC_LIBRARIES := core_static cocos2dx_static box2d_static
GOOGLE_PLAY_STORE := true
include $(BUILD_SHARED_LIBRARY)
$(call import-module, box2D)
$(call import-module, core)
$(call import-module, cocos2dx)
$(call import-module,android-ndk-profiler/jni)
Thanks in advance.

Unable to reach a break point in C++ using Android Studio and ndkBuild

I'm trying to reach a break point in a simple C++ code:
Here the .cpp
#include <jni.h>
#include <string>
extern "C"
{
jstring Java_com_comscore_android_app_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++ lalalaaaaaa";
return env->NewStringUTF(hello.c_str());
}
}
here the gradle file:
android {
compileSdkVersion 23
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.comscore"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
ndkBuild {
arguments "NDK_APPLICATION_MK:=src/main/jni/Application.mk"
}
}
}
externalNativeBuild{
ndkBuild{
path "src/main/jni/Android.mk"
}
}
...
}
The Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_MODULE := native-lib
LOCAL_LDLIBS := -llog
LOCAL_CPPFLAGS += -fsigned-char -fexceptions -frtti -g -O0 -std=c++0x -std=gnu++0x
LOCAL_CFLAGS += -fsigned-char -fexceptions -frtti -g -O0 -std=c++0x -std=gnu++0x
include $(BUILD_SHARED_LIBRARY)
And the Application.mk
APP_ABI := all
APP_STL := gnustl_static
The application compiles and works but I'm not able to stop in any breakpoint in the C++ code while running the debugger. I can see how it loads the native libraries but it doesn't stop any where and Android studio is telling me that the break point has been attached.
I'm using Android Studio 2.2 Preview 6
Can anybody help me?
In my case I have two modules, one with the C++ code (library) and an other one with the application that consumes the library module.
The problem was that I tried to debug the library module uaing the app module, so I just need to specify the folder where the debug symbols are:
Run->Edit configurations... -> Debuggerand in the symbol directories tab add the right path. For instance:
/path_to_my_project/lib_module/build/intermediates/ndkBuild/flavor/debug/obj/local/x86
app.imp file contains "<"facet type="native_android_gradle">", , option=SELECTED_BUILD_VARIANT..
check if value="debug"

Gradle is not compiling using ndkBuild

I have an android project configured in eclipse that works good with ant and ndk-build with some customized Android.mk and Application.mk files. I need to move them to Android Studio and I don't want to use CMake that comes with it, so I just want to keep my old .mk files. To do so I started with a simple hello world example with the following code:
Here the native-lib.cpp:
#include <jni.h>
#include <string>
extern "C"
{
jstring Java_com_comscore_android_app_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++ lalalaaaaaa";
return env->NewStringUTF(hello.c_str());
}
}
and here my gradle file:
android {
compileSdkVersion 23
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.comscore"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
ndkBuild {
arguments "NDK_APPLICATION_MK:=src/main/jni/Application.mk"
}
}
}
externalNativeBuild{
ndkBuild{
path "src/main/jni/Android.mk"
}
}
...
}
Here the Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_MODULE := native-lib
LOCAL_LDLIBS := -llog
LOCAL_CPPFLAGS += -fsigned-char -fexceptions -frtti -g -O0 -std=c++0x -std=gnu++0x
LOCAL_CFLAGS += -fsigned-char -fexceptions -frtti -g -O0 -std=c++0x -std=gnu++0x
include $(BUILD_SHARED_LIBRARY)
And finally the Application.mk:
APP_ABI := all
APP_STL := gnustl_static
But the C code is never compiled, could any body help me with this issue?
Thanks!
it was not compiling anything, that was the problem. Now I solved after cleaning up the build folder manually

OpenCV undefined reference to `cv::fastFree(void*)'

I try to build project with OpenCV, i downloaded OpenCV SDK 3.1 from official website, however during building i get error
/Users/Mario/Downloads/OpenCV-android-sdk/sdk/native/jni/include/opencv2/core/mat.inl.hpp
Error:(571) undefined reference to 'cv::fastFree(void*)'
Error:(663) undefined reference to 'cv::Mat::create(int, int const*, int)'
Error:(682) undefined reference to 'cv::Mat::deallocate()'
here is my gradle.build, i use gradle-experimental:0.4.0
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
applicationId = "pl.mariusz.opencv"
minSdkVersion.apiLevel = 17
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "1.0"
}
task ndkBuild(type: Exec) {
commandLine '/Users/Mario/Library/Android/android-ndk-r10e/ndk-build', '-C', file('src/main').absolutePath
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
android.ndk {
moduleName = "source_file"
cppFlags.add("-std=c++11")
cppFlags.add("-fexceptions")
cppFlags.add("-I${file("/Users/Mario/Downloads/OpenCV-android-sdk/sdk/native/jni/include")}".toString())
cppFlags.add("-I${file("/Users/Mario/Downloads/OpenCV-android-sdk/sdk/native/jni/include/opencv")}".toString())
stl = "gnustl_static"//"gnustl_static"//"gnustl_shared"//"stlport_static"
}
android.sources {
main {
jni{
source{
srcDirs = []
}
}
jniLibs {
source {
srcDirs = ['src/main/Libs']
}
}
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
}
}
}
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCVROOT:= /Users/Mario/Downloads/OpenCV-android-sdk
OPENCV_LIB_TYPE=STATIC
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk
LOCAL_SRC_FILES := source_file.cpp
LOCAL_LDLIBS += -llog -ldl
LOCAL_MODULE := source_file
include $(BUILD_SHARED_LIBRARY)
and Application.mk
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-17
i tried mix it with shared,static STL with still same error, how can i fix it?
[EDIT]
[SOLUTION]
its more like compromise not real solution, but i changed gradle-experimental:0.4.0 back to classpath 'com.android.tools.build:gradle:1.5.0' and added file gradle.properties to project root directory with
android.useDeprecatedNdk=true
You have to add opencv libraries to your linker. To do that, you have to do 2 things: 1. add the library files; 2. add the library directory.
Try
LOCAL_LDLIBS += -llog -ldl -LlibPath -lopencv_calib3d -lopencv_core
and so an, add all the opencv libraries (or at least the ones you'll need) in this way. -l will automatically assume the "lib" in the filename and the suffix.
The -L will tell the linker where to find libraries, so instead of libPath please add the absolute path of your opencv library folder. See how to mention path of libraries in Android.mk file or Application.mk file?
Try it and tell me the new error message.

Categories

Resources