1

I ran into this problem when writing a audio-related app:

 Build command failed. Error while executing process C:\Android_SDK\cmake\3.6.4111459\bin\cmake.exe with arguments {--build D:\workspace\AndroidAudioNDK\app\.externalNativeBuild\cmake\debug\x86_64 --target native-lib} [1/1] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\x86_64\libnative-lib.so FAILED: cmd.exe /C "cd . && C:\android-ndk-r15c\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=x86_64-none-linux-android --gcc-toolchain=C:/android-ndk-r15c/toolchains/x86_64-4.9/prebuilt/windows-x86_64 --sysroot=C:/android-ndk-r15c/sysroot -fPIC -isystem C:/android-ndk-r15c/sysroot/usr/include/x86_64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -fexceptions -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a --sysroot C:/android-ndk-r15c/platforms/android-21/arch-x86_64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\x86_64\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -llog -lm "C:/android-ndk-r15c/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/libgnustl_static.a" && cd ." D:\workspace\AndroidAudioNDK\app\src\main\cpp/native-lib.cpp:35: error: undefined reference to 'AAssetManager_fromJava' D:\workspace\AndroidAudioNDK\app\src\main\cpp/native-lib.cpp:35: error: undefined reference to 'AAssetManager_open' D:\workspace\AndroidAudioNDK\app\src\main\cpp/native-lib.cpp:35: error: undefined reference to 'AAsset_openFileDescriptor' D:\workspace\AndroidAudioNDK\app\src\main\cpp/native-lib.cpp:44: error: undefined reference to 'AMediaExtractor_new' ... 

And I found a solution to this problem: adding the android lib to LOCAL_LDLIBS, but How to do that in the latest android studio (3.1.3)? I have tried the other solutions under that answer but none of them works for me: the build error persists.

2 Answers 2

2

LOCAL_LDLIBS is for ndk-build but you're using CMake. A good starting place would be one of our samples which shows you that you need to use target_link_libraries.

Sign up to request clarification or add additional context in comments.

2 Comments

It is Android Studio that is using CMake, not me. I'm just confused by the settings.
This document should be updated and linked in the Android Studio configure CMake page. How on earth could a newbie know the correct name of those built-in libraries?
2

Found a solution!

In the CMakeList.txt here: CMakeList.txt

Modify it to

cmake_minimum_required(VERSION 3.4.1) add_library( native-lib SHARED src/main/cpp/native-lib.cpp ) target_link_libraries( native-lib android log ) 

Then the error is gone.

Reference:

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.