Trying to setup GStreamer for Android using Android Studio on Windows. I'm mostly following the tutorial from their site as best I can, as well as looking at this (plus whatever I can find that helps). I get an:
Error:error: invalid linker name in argument '-fuse-ld=gold'
My Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := app
LOCAL_SRC_FILES := app-1.c
LOCAL_SHARED_LIBRARIES := gstreamer_android
LOCAL_LDLIBS := -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
GSTREAMER_PLUGINS := coreelements ogg theora vorbis videoconvert audioconvert audioresample playback glimagesink soup opensles
G_IO_MODULES := gnutls
GSTREAMER_EXTRA_DEPS := gstreamer-video-1.0
include $(GSTREAMER_NDK_BUILD_PATH)\gstreamer-1.0.mk
and app/build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.quant.icarus"
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
ndkBuild {
def gstRoot
if (project.hasProperty('gstAndroidRoot'))
gstRoot = project.gstAndroidRoot
else
gstRoot = System.env.GSTREAMER_ROOT_ANDROID
if (gstRoot == null)
throw new GradleException('GSTREAMER_ROOT_ANDROID must be set, or "gstAndroidRoot" must be defined in your gradle.properties in the top level directory of the unpacked universal GStreamer Android binaries')
arguments "NDK_APPLICATION_MK=src/main/jni/Application.mk", "GSTREAMER_JAVA_SRC_DIR=src/main/java", "GSTREAMER_ROOT_ANDROID=$gstRoot", "GSTREAMER_ASSETS_DIR=src/main/assets"
targets "app", "gstreamer_android"
// All archs except MIPS and MIPS64 are supported
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
}
afterEvaluate {
compileDebugJavaWithJavac.dependsOn 'externalNativeBuildDebug'
compileReleaseJavaWithJavac.dependsOn 'externalNativeBuildRelease'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
Gradle project sync runs without any problems. But Make Project produces the following:
Error:error: invalid linker name in argument '-fuse-ld=gold'
Or more verbose:
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process C:\Users\Quant\AppData\Local\Android\Sdk\ndk-bundle\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\Quant\AndroidStudioProjects\Icarus\app\src\main\jni\Android.mk NDK_APPLICATION_MK=C:\Users\Quant\AndroidStudioProjects\Icarus\app\src\main\jni\Application.mk APP_ABI=arm64-v8a NDK_ALL_ABIS=arm64-v8a NDK_DEBUG=1 APP_PLATFORM=android-23 NDK_OUT=C:/Users/Quant/AndroidStudioProjects/Icarus/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=C:\Users\Quant\AndroidStudioProjects\Icarus\app\build\intermediates\ndkBuild\debug\lib NDK_APPLICATION_MK=src/main/jni/Application.mk GSTREAMER_JAVA_SRC_DIR=src/main/java GSTREAMER_ROOT_ANDROID=C:\Users\Quant\Desktop\GStreamer\arm GSTREAMER_ASSETS_DIR=src/main/assets gst-build-arm64-v8a/libgstreamer_android.so}
GStreamer : [GEN] => gst-build-arm64-v8a/gstreamer_android.c
GStreamer : [COMPILE] => gst-build-arm64-v8a/gstreamer_android.c
GStreamer : [LINK] => gst-build-arm64-v8a/libgstreamer_android.so
clang.exe: error: invalid linker name in argument '-fuse-ld=gold'
make: *** [buildsharedlibrary_arm64-v8a] Error 1
Any ideas on how to fix this? I've seen some threads that say to add flags to make it gold.exe...except no one is saying where the flags are set (and the threads didn't seem all too resolved).
I replaced the 'ld.exe' file as indicated in the gstreamer install guide, even if it seemed dated (I did that after getting the same error - so that's not causing it).
It is a problem with the clang.exe process that tries to link together the libraries. Note, there is no need to change the ld.exe file as in the install instructions from the link in the question.
Fix: you need to change two files per architecture in the GStreamer directory so that the linker gets called as gold.exe and not gold.
For each architecture you're interested in you need to go to (using arm64 as an example):
1)
path\to\Gstreamer\root\arm64\share\gst-android\ndk-build\gstreamer-1.0.mk and change -fuse-ld=gold to -fuse-ld=gold.exe (it only appears once in the file).
Now go to:
2)
path\to\Gstreamer\root\arm64\include\gmp.h and change -fuse-ld=gold to -fuse-ld=gold.exe (again, only one occurrence).
There were some minor fixes to my posted Android.mk and gradle files to get things to fully compile, but that seems outside the scope of this question (added -llog to local ldlibs and used only core plugin).
Related
I'm trying to build AndEngine sample on my MacOS Android Studio 2.3.2.
But get this error. Cannot figure out what is the problem. Strange thing is the same project build normally on Windows, same version of Android Studio.
> FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':andEngine:externalNativeBuildRelease'.
> Build command failed.
Error while executing process /Users/apple/Library/Android/sdk/ndk-bundle/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/apple/Documents/workspace/AndroidStudio/AndEngineExamples-GLES2/andEngine/src/main/jni/Android.mk
NDK_APPLICATION_MK=/Users/apple/Documents/workspace/AndroidStudio/AndEngineExamples-GLES2/andEngine/src/main/jni/Application.mk APP_ABI=mips NDK_ALL_ABIS=mips NDK_DEBUG=0 APP_PLATFORM=android-9 NDK_OUT=/Users/apple/Documents/workspace/AndroidStudio/AndEngineExamples-GLES2/andEngine/build/intermediates/ndkBuild/release/obj NDK_LIBS_OUT=/Users/apple/Documents/workspace/AndroidStudio/AndEngineExamples-GLES2/andEngine/build/intermediates/ndkBuild/release/lib /Users/apple/Documents/workspace/AndroidStudio/AndEngineExamples-GLES2/andEngine/build/intermediates/ndkBuild/release/obj/local/mips/libandengine.so}
Android NDK: android-9 is unsupported. Using minimum supported version android-14.
[mips] Compile++ : andengine_shared <= BufferUtils.cpp
/Users/apple/Documents/workspace/AndroidStudio/AndEngineExamples-GLES2/andEngine/src/main/jni/src/BufferUtils.cpp:13:2: error: use of undeclared identifier 'memcpy'
memcpy(bufferAddress, dataAddress + pOffset, pLength << 2);
^
My Application.mk file:
# Build both ARMv5TE and ARMv7-A and x86 machine code.
APP_ABI := armeabi armeabi-v7a x86
APP_STL := gnustl_shared
And Android.mk:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := andengine_shared
LOCAL_MODULE_FILENAME := libandengine
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := src/GLES20Fix.c \
src/BufferUtils.cpp
LOCAL_LDLIBS := -lGLESv2
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/src
include $(BUILD_SHARED_LIBRARY)
Android NDK: android-9 is unsupported. Using minimum supported version
android-14.
Add APP_PLATFORM := android-14 in Application.mk file
If you do not have that line then version of your SDK is taken from project.properties files.
Android Studio overrides some settings in your Application.mk file. For example, it overrides APP_ABI. You should add
defaultConfig {
...
externalNativeBuild {
ndkBuild {
abiFilters "armeabi", "armeabi-v7a", "x86"
}
}
}
to your app/build.gradle. You should not be worried about the warning that minimum supported version is android-14, but please note that NDK r15, which is currently still in beta.
I am trying to run a NDK and OpenCV related project. The project builds errorless. But when i run the application I get the error:
mips64el-linux-android-g++: error: unrecognized command line option '-mfpu=neon'
My Application.mk file looks like this:
APP_STL := gnustl_shared
APP_CPPFLAGS := -frtti -fexceptions
# NEON
APP_CFLAGS += -mfpu=neon
APP_ABI := armeabi-v7a
APP_PLATFORM := android-18
APP_OPTIM := debug
APP_MODULES := nVisoDemo-1.1
NDK_TOOLCHAIN_VERSION := 4.9
HAVE_LIB_CEVA := false # CUSTOM VARIABLE USED (NOT ANYMORE) IN Android.mk
Android.mk:
# Freeimage
include $(CLEAR_VARS)
LOCAL_MODULE := libfreeimage
LOCAL_ARM_NEON := true
#LOCAL_SRC_FILES := $(NVISO_LIBS_DIR)/libfreeimage-3.14.so
LOCAL_SRC_FILES := D:/Siddharth/StudioProjects/OpenCVDemo/nvsdk/src/main/jni/Framework/nviso/libs/armeabi-v7a/libfreeimage-3.14.so
include $(PREBUILT_SHARED_LIBRARY)
I tried to remove APP_CFLAGS += -mfpu=neon from application.mk file but then it gives all the compilation errors in cpp files..
Also to mention that the above code works flawlessly in Eclipse...but the problem is coming in Android Studio only
Any help would be appreciated..Thanks in advance..
By default you'll build for every NDK ABI: arm5, arm7, arm64, mips, mips64, x86, and x86_64, but -mfpu=neon is only valid for arm7 and arm64.
In general for cases like this you need to protect architecture specific flags by testing against TARGET_ARCH_ABI, but for NEON support there's a flag just for this:
LOCAL_ARM_NEON := true
Add that to each of your modules in your Android.mk.
Hello I solved the issue by the following way:
Actually what #LethalProgrammer said was rite. When I removed the "APP_CFLAGS += -mfpu=neon" line from Application.mk then it should have started working but when i removed the line it give all kind of errors in my cpp files.
So problem was that i was building using commandline and also i had put .so files in jnilibs folder in app so it was building twice..
Thus i removed this from app's build.gradle
externalNativeBuild {
ndkBuild {
path 'D:/Siddharth/StudioProjects/OpenCVDemo/nvsdk/src/main/jni/Android.mk'
}
}
So at last removing the above code from build.gradle and removing -mfpu=neon from application.mk file it started working and the app run..
Thank you all...
Following the tutorial on : http://www.learnopengles.com/calling-opengl-from-android-using-the-ndk/.
Created all the necessary files, but when trying to build I get the errors :
D:\svn-Genicap3D\trunk\frontend_android\Genicap3D\app\src\main\jni\core\game.cpp
Error:(6) undefined reference to 'glClearColor'
Error:(14) undefined reference to `glClear'
game.cpp
#include "game.h"
#include <GLES2/gl2.h>
void on_surface_created() {
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
}
void on_surface_changed() {
// No-op
}
void on_draw_frame() {
glClear(GL_COLOR_BUFFER_BIT);
}
android.mk
LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
# Here we give our module name and source file(s)
LOCAL_MODULE := libgame
LOCAL_CFLAGS := -Wall -Wextra
LOCAL_LDLIBS := -llog -lnativehelper -lGLESv2
LOCAL_CPP_FEATURES += exceptions
LOCAL_SHARED_LIBRARIES := liblog libnativehelper libGLESv2
LOCAL_SRC_FILES := coreBridge.cpp core/game.cpp
# To build the whole .so
FILE_LIST := $(wildcard $(LOCAL_PATH)/../../../core/src/*.cpp)
LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%) LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../core/include
include $(BUILD_SHARED_LIBRARY)
game.cpp and .h are in core map which is in the same map as the .mk files
I have tried to include alot from other answers but none seem to work.
Feel free to ask for more files.
as you're using Android Studio, your Makefiles are ignored by default and new ones are generated on-the-fly, so OpenGL ES2 lib isn't properly referenced.
This feature is how NDK builds are currently supported from Android Studio, but it's deprecated while a better way to do it is in the work.
You can still choose to use it and specify inside your build.gradle that you need to link to OpenGL ES:
android {
...
defaultConfig {
ndk {
moduleName "game"
ldLibs "GLESv2"
}
}
}
But the best for now, in my view, is to deactivate the built-in NDK support and get your Makefiles to be used instead:
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
android {
...
sourceSets.main {
jniLibs.srcDir 'src/main/libs' //set .so files directory to 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
}
}
In Android Studio you can go into the CMakeLists.txt file and add
target_link_libraries(EGL
GLESv2)
I am adding gnustl_static to a external Android module and when I build it I get the following error.
make: *** No rule to make target `prebuilt/ndk/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/libs/armeabi-v7a/libstdc++.a', needed by `out/target/product/msm8960/obj/SHARED_LIBRARIES/liballjoyn_intermediates/LINKED/liballjoyn.so'. Stop.
when I look under "prebuilt/ndk/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/libs/armeabi-v7a/" I can not find the libstdc++.a there is a fild libsupc++.a
the build system is getting this from the binary.mk file found in the "build/core" folder it states
# LOCAL_NDK_STL_VARIANT is gnustl_static
my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/libs/$(TARGET_CPU_ABI)/include \
$(my_ndk_source_root)/cxx-stl/gnu-libstdc++/include
my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/libs/$(TARGET_CPU_ABI)/libstdc++.a
problem is I don't know what to get past this error.
There are many copies of libstdc++ in the prebuilt folder but they are not found in the location listed. The are found in
prebuild/ndk/$(ANDRIOD_NDK_VERSION)/platforms/$(ANDROID_SDK_VERSION)/$(ARCHETECTURE_TYPE)/usr/lib/libstdc++.a
here is a shortened form of my Android.mk file:
LOCAL_PATH := $(call my-dir)
# Rules to build libabc.so
include $(CLEAR_VARS)
LOCAL_CPP_EXTENSION := .cc
LOCAL_SDK_VERSION := 8
LOCAL_NDK_VERSION := 7
LOCAL_NDK_STL_VARIANT := gnustl_static
LOCAL_CFLAGS += \
-std=gnu++0x
LOCAL_C_INCLUDES := \
external/abc/inc \
external/openssl/include
LOCAL_SRC_FILES := \
file1.cc \
file2.cc
LOCAL_SHARED_LIBRARIES := \
libcrypto \
libssl \
liblog
LOCAL_PRELINK_MODULE := false
LOCAL_REQUIRED_MODULES := \
external/openssl/crypto/libcrypto \
external/openssl/ssl/libssl
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libabc
include $(BUILD_SHARED_LIBRARY)
Anyone have any ideas how I can solve the "No rule to make target" build issue?
Solution found:
The simple answer is that I need to change the LOCAL_NDK_VERSION version from 7 to 5 or 6.
The complex answer is that the binary.mk file has not been updated to account for changes that were made when NDK-7 was released.
In NDK-5 and NDK-6 when using gnustl_static the library file that contained everything for STL was in libstdc++.a that was located in the location specified in the binary.mk file. When NDK-7 was released the library name was changed from libstdc++.a to libgnustl_static.a. It does not look like the binary.mk was updated to account for this change.
This is not that surprising since it appears that no projects use gnustl_static. I did a grep accross all of the code in the android repository and the only code I found that was using the LOCAL_NDK_VERSION set to gnustl_static was my own.
You shoudl not use LOCAL_NDK_STL_VARIANT to select STL variant.
You should use APP_STL := gnustl_static in Application.mk file.
I'm writing an Android App fully in C++. Using OpenGL E.S. 2, Android-NDK r7 (platform-9), OpenJDK, and Ubuntu 12.04.
The issue that I'm running into is that my main library which is supposed to make calls to the engine I'm developing is spitting out "undefined reference to android_main" errors. Why it is doing this I have no idea, but I'm almost positive it has some thing to do with my Android.mk. For whatever reason, I can't quite figure it out.
While the engine library builds perfectly fine, the main Android.mk which references the files used which make up the actual game isn't building in the way I'd like it to.
The Goal
-I'd like this to link up with -loptim so it may reference and call functions from the engine as a separate library. Because of this, I should be able to port this engine to various other projects and simply link it. This appears to have been done, though if someone else has a better way of accomplishing this I'm all ears.
-I'd also like to figure out why my android_main is not being referenced, and what can be done to fix it.
Main.cpp
#include "engine/stdafx.hpp"
#include "engine/AppData.hpp"
#include "engine/Engine.hpp"
#include "glm/glm.hpp"
using namespace optim;
void android_main( android_app* application )
{
AppData appData;
appData.mApplication = application;
appData.mGraphicsService = new GraphicsService( application );
Engine app( &appData );
}
Android.mk
MY_LOCAL_PATH := $(call my-dir)
LOCAL_PATH := $(MY_LOCAL_PATH)
include $(CLEAR_VARS)
include $(LOCAL_PATH)/engine/Android.mk
include $(CLEAR_VARS)
LOCAL_PATH := $(MY_LOCAL_PATH)
LOCAL_CFLAGS := -I$(LOCAL_PATH)/glm -I$(ANDROID_NDK)/sources/cxx-stl/stlport/stlport -I$(LOCAL_PATH)/ -I$(LOCAL_PATH)/engine
LOCAL_MODULE := pongdroid
LOCAL_SRC_FILES := Main.cpp PongDroid.cpp
LOCAL_LDLIBS := -landroid -llog -lEGL -lGLESv2 -L$(PONGDROID_DEV)/obj/local/armeabi/ -loptim
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
Note that -loptim is the shared library of the engine I'm linking the main module to. The problem is that, while it appears to link perfectly fine, the library for this makefile in particular won't produce a shared_library. Everything else seems to compile just fine, however.
NDK-BUILD
**** Build of configuration Default for project pongdroid ****
ndk-build all
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile++ thumb : optim <= Engine.cpp
Compile++ thumb : optim <= Config.cpp
Compile++ thumb : optim <= GraphicsService.cpp
Compile thumb : android_native_app_glue <= android_native_app_glue.c
StaticLibrary : libandroid_native_app_glue.a
StaticLibrary : libstdc++.a
SharedLibrary : liboptim.so
./obj/local/armeabi/libandroid_native_app_glue.a(android_native_app_glue.o): In function `android_app_entry':
/home/amsterdam/Android/android-ndk/sources/android/native_app_glue/android_native_app_glue.c:234: undefined reference to `android_main'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/liboptim.so] Error 1
**** Build Finished ****
Update
So, I've narrowed down the problem a bit. The issue lies in the fact that the root Android.mk file for some reason seems to be ignoring its own library. What's even stranger is that when I comment out include $(LOCAL_PATH)/engine/Android.mk, the error output gets worse.
So, I'm posting my engine/Android.mk file for clarity to see if anyone can make sense of this mess...
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS := -I$(LOCAL_PATH)/
LOCAL_MODULE := optim
LOCAL_SRC_FILES := Engine.cpp Config.cpp GraphicsService.cpp
LOCAL_LDLIBS := -landroid -llog -lEGL -lGLESv2
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
Update 2
A call to ndk-build pongdroid from the shell.
ndk-build pongdroid
Compile++ thumb : pongdroid <= Main.cpp
Compile++ thumb : pongdroid <= PongDroid.cpp
SharedLibrary : liboptim.so
/home/amsterdam/Programming/Android/pongdroid/obj/local/armeabi/libandroid_native_app_glue.a(android_native_app_glue.o): In function `android_app_entry':
/home/amsterdam/Android/android-ndk/sources/android/native_app_glue/android_native_app_glue.c:234: undefined reference to `android_main'
collect2: ld returned 1 exit status
make: *** [/home/amsterdam/Programming/Android/pongdroid/obj/local/armeabi/liboptim.so] Error 1
Are you including "android_native_app_glue.h" header in Main.cpp or one of its included headers?