Android native library linker stops working after gradle update - android

My project stops working after updating gradle.
I'm using a C library in Android though JNI.
Using Cmake to compile and join the libraries
Before, it compiled and linked without a problem, but now there is an error at link time when building the project.
It throw this error:
/home/my_user/Documents/Proyects/optandroid/app/src/main/cpp/kotlin-jni.c:152: error: undefined reference to 'find_best_order'
This is an extended error message that android studio also gives after trying to build the project:
> Task :app:externalNativeBuildDebug FAILED
Build multiple targets main_armeabi-v7a this_library_armeabi-v7a process_control_armeabi-v7a
ninja: Entering directory `/home/my_user/Documents/Proyects/optandroid/app/.cxx/cmake/debug/armeabi-v7a'
[1/1] Linking C shared library /home/my_user/Documents/Proyects/optandroid/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libthis_library.so
FAILED: /home/my_user/Documents/Proyects/optandroid/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libthis_library.so
: && /home/my_user/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=armv7-none-linux-androideabi19 --gcc-toolchain=/home/my_user/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/my_user/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libthis_library.so -o /home/my_user/Documents/Proyects/optandroid/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libthis_library.so CMakeFiles/this_library.dir/kotlin-jni.c.o used_library/src/libmodule_used_library.a /home/my_user/Documents/Proyects/optandroid/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libprocess_control.so -latomic -lm && :
/home/my_user/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: used_library/src/libmodule_used_library.a: member at 3324 is not an ELF object
/home/my_user/Documents/Proyects/optandroid/app/src/main/cpp/kotlin-jni.c:152: error: undefined reference to 'find_best_order'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process ninja with arguments {-C /home/my_user/Documents/Proyects/optandroid/app/.cxx/cmake/debug/armeabi-v7a main this_library process_control}
ninja: Entering directory `/home/my_user/Documents/Proyects/optandroid/app/.cxx/cmake/debug/armeabi-v7a'
[1/1] Linking C shared library /home/my_user/Documents/Proyects/optandroid/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libthis_library.so
FAILED: /home/my_user/Documents/Proyects/optandroid/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libthis_library.so
: && /home/my_user/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=armv7-none-linux-androideabi19 --gcc-toolchain=/home/my_user/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/my_user/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libthis_library.so -o /home/my_user/Documents/Proyects/optandroid/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libthis_library.so CMakeFiles/this_library.dir/kotlin-jni.c.o used_library/src/libmodule_used_library.a /home/my_user/Documents/Proyects/optandroid/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libprocess_control.so -latomic -lm && :
/home/my_user/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: used_library/src/libmodule_used_library.a: member at 3324 is not an ELF object
/home/my_user/Documents/Proyects/optandroid/app/src/main/cpp/kotlin-jni.c:152: error: undefined reference to 'find_best_order'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
This is the CmakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project(Optandroid)
set(CMAKE_C_STANDARD 99)
add_subdirectory(used_library)
add_library(this_library
SHARED
kotlin-jni.c
)
# Include libraries needed for kotlin-jni lib
target_link_libraries(this_library
process_library
android
log)
used_library is the library directory, it builds the library process_library, and this_library it is what I use for JNI.
This is a pure C project, nothing of C++, so it is not the problem of C++ changing the names of functions.
I corroborated that the problem starts by updating gradle in the project by taking an older proyect which use this library in exactly the same way, and just making the update, it works before, but has the exactly same error after.
Thanks in advance.

At the end the problem was the NDK version. I just updated NDK to the newest version and started worked like before.

Related

Android Studio: Build Command failed gradle sync failed

I have installed android studio 3.1.2 and creates My application app but it says this:
Build command failed.
Error while executing process C:\Users\Rajeev Sarraf\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {-HC:\Users\Rajeev Sarraf\ApkProjects\MyApplication\app -BC:\Users\Rajeev Sarraf\ApkProjects\MyApplication\app\.externalNativeBuild\cmake\release\armeabi-v7a -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=android-15 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Rajeev Sarraf\ApkProjects\MyApplication\app\build\intermediates\cmake\release\obj\armeabi-v7a -DCMAKE_BUILD_TYPE=Release -DANDROID_NDK=C:\Users\Rajeev Sarraf\AppData\Local\Android\Sdk\ndk-bundle -DCMAKE_CXX_FLAGS= -DCMAKE_TOOLCHAIN_FILE=C:\Users\Rajeev Sarraf\AppData\Local\Android\Sdk\ndk-bundle\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=C:\Users\Rajeev Sarraf\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\ninja.exe -GAndroid Gradle - Ninja}
-- Check for working C compiler: C:/Users/Rajeev Sarraf/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- Check for working C compiler: C:/Users/Rajeev Sarraf/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- broken
/Users/Rajeev Sarraf/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe" is not able to compile a simple test program.
Open File
It fails with the following output:
Change Dir: C:/Users/Rajeev Sarraf/ApkProjects/MyApplication/app/.externalNativeBuild/cmake/release/armeabi-v7a/CMakeFiles/CMakeTmp
Run Build Command:"C:/Users/Rajeev
Sarraf/AppData/Local/Android/Sdk/cmake/3.6.4111459/bin/ninja.exe"
"cmTC_c2a5a"
[1/2] Building C object CMakeFiles/cmTC_c2a5a.dir/testCCompiler.c.o
FAILED:
C:\Users\RAJEEV~1\AppData\Local\Android\Sdk\NDK-BU~1\TOOLCH~1\llvm\prebuilt\WINDOW~1\bin\clang.exe
--target=armv7-none-linux-androideabi --gcc-toolchain="C:/Users/Rajeev
Sarraf/AppData/Local/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64"
--sysroot="C:/Users/Rajeev
Sarraf/AppData/Local/Android/Sdk/ndk-bundle/sysroot" -isystem
C:/Users/Rajeev
Sarraf/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi
-D__ANDROID_API__=15 -g -DANDROID -ffunction-sections -funwind-tables
-fstack-protector-strong -no-canonical-prefixes -march=armv7-a
-mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat
-Werror=format-security -o CMakeFiles/cmTC_c2a5a.dir/testCCompiler.c.o -c
"C:\Users\Rajeev
Sarraf\ApkProjects\MyApplication\app\.externalNativeBuild\cmake\release\armeabi-v7a\CMakeFiles\CMakeTmp\testCCompiler.c"
error: no such file or directory:
'Sarraf/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi'
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt
-- Configuring incomplete, errors occurred!
See also "C:/Users/Rajeev Sarraf/ApkProjects/MyApplication/app/.externalNativeBuild/cmake/release/armeabi-v7a/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Rajeev Sarraf/ApkProjects/MyApplication/app/.externalNativeBuild/cmake/release/armeabi-v7a/CMakeFiles/CMakeError.log".
Build command failed.
Error while executing process C:\Users\Rajeev Sarraf\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {-HC:\Users\Rajeev Sarraf\ApkProjects\MyApplication\app -BC:\Users\Rajeev Sarraf\ApkProjects\MyApplication\app\.externalNativeBuild\cmake\debug\armeabi-v7a -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=android-15 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Rajeev Sarraf\ApkProjects\MyApplication\app\build\intermediates\cmake\debug\obj\armeabi-v7a -DCMAKE_BUILD_TYPE=Debug -DANDROID_NDK=C:\Users\Rajeev Sarraf\AppData\Local\Android\Sdk\ndk-bundle -DCMAKE_CXX_FLAGS= -DCMAKE_TOOLCHAIN_FILE=C:\Users\Rajeev Sarraf\AppData\Local\Android\Sdk\ndk-bundle\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=C:\Users\Rajeev Sarraf\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\ninja.exe -GAndroid Gradle - Ninja}
-- Check for working C compiler: C:/Users/Rajeev Sarraf/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- Check for working C compiler: C:/Users/Rajeev Sarraf/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- broken
/Users/Rajeev Sarraf/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe" is not able to compile a simple test program.
Open File
It fails with the following output:
Change Dir: C:/Users/Rajeev Sarraf/ApkProjects/MyApplication/app/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeTmp
Run Build Command:"C:/Users/Rajeev
Sarraf/AppData/Local/Android/Sdk/cmake/3.6.4111459/bin/ninja.exe"
"cmTC_f8247"
[1/2] Building C object CMakeFiles/cmTC_f8247.dir/testCCompiler.c.o
FAILED:
C:\Users\RAJEEV~1\AppData\Local\Android\Sdk\NDK-BU~1\TOOLCH~1\llvm\prebuilt\WINDOW~1\bin\clang.exe
--target=armv7-none-linux-androideabi --gcc-toolchain="C:/Users/Rajeev
Sarraf/AppData/Local/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64"
--sysroot="C:/Users/Rajeev
Sarraf/AppData/Local/Android/Sdk/ndk-bundle/sysroot" -isystem
C:/Users/Rajeev
Sarraf/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi
-D__ANDROID_API__=15 -g -DANDROID -ffunction-sections -funwind-tables
-fstack-protector-strong -no-canonical-prefixes -march=armv7-a
-mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat
-Werror=format-security -o CMakeFiles/cmTC_f8247.dir/testCCompiler.c.o -c
"C:\Users\Rajeev
Sarraf\ApkProjects\MyApplication\app\.externalNativeBuild\cmake\debug\armeabi-v7a\CMakeFiles\CMakeTmp\testCCompiler.c"
error: no such file or directory:
'Sarraf/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi'
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt
-- Configuring incomplete, errors occurred!
See also "C:/Users/Rajeev Sarraf/ApkProjects/MyApplication/app/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Rajeev Sarraf/ApkProjects/MyApplication/app/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeError.log".
it says 4 errors
anyone can please give a solution
I had the same Problem. I hope i can help u here.
Try to create a new project and change the project location. Its important, that the new project location, contain NO whitespace. Gradle cannot sync, if there is whitespace.
Jules

Android build command failed after updating Android Studio

After I updated my Android Studio it is giving me build command failed error. It gives me the following build error :
Build command failed.
Error while executing process /Users/bhaskarrajaryal/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/bhaskarrajaryal/AndroidStudioProjects/wowtime/app/.externalNativeBuild/cmake/debug/armeabi-v7a --target baseUrl}
[1/1] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libbaseUrl.so
FAILED: : && /Users/bhaskarrajaryal/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=armv7-none-linux-androideabi --gcc-toolchain=/Users/bhaskarrajaryal/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/bhaskarrajaryal/Library/Android/sdk/ndk-bundle/sysroot -fPIC -isystem /Users/bhaskarrajaryal/Library/Android/sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=16 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot /Users/bhaskarrajaryal/Library/Android/sdk/ndk-bundle/platforms/android-16/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--exclude-libs,libunwind.a -L/Users/bhaskarrajaryal/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libbaseUrl.so -o ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libbaseUrl.so CMakeFiles/baseUrl.dir/src/cpp/baseUrl.cpp.o -llog -latomic -lm "/Users/bhaskarrajaryal/Library/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libgnustl_static.a" && :
/Users/bhaskarrajaryal/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/stdexcept:136: error: undefined reference to 'std::logic_error::logic_error(char const*)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Had the same issue after the update. I did a clean build (under Build > Clean Project) then restarted android studio with the option "Invalidate and Restart" under File > Invalidate Caches/Restart. It run well after that
Build-->Refresh Linked C++ Projects
Build Project
Try to do this:
Step 1: Safely delete the build folder from app directory.
Step 2: In Android Studio, File -> Invalidate Caches / Restart
Step 3: Build -> Clean Project Then Build -> Rebuild Project. so build folder will be regenerated and hope so error is gone.

gradle build for android native project fails with "unable to open output file" error

I am trying to build an android native project using gradle. While the build passes for the architectures arm64-v8a, x86 and x86_64, it fails for armeabi-v7a with a unique error:
/{sdk-path}/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=15 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -frtti -fexceptions -Os -DNDEBUG -O2 -DNDEBUG -D_NDEBUG=1 -s -fPIC -Wdeprecated-declarations -std=c++14 -MD -MT CMakeFiles/acplocalnet.dir/src/main/cpp/HttpTransferCallbackHookImpl.cpp.o -MF CMakeFiles/acplocalnet.dir/src/main/cpp/HttpTransferCallbackHookImpl.cpp.o.d -o CMakeFiles/acplocalnet.dir/src/main/cpp/HttpTransferCallbackHookImpl.cpp.o -c /Users/acpl/workspace/ACPLocal_net_Android/net/project/android/acplocalnet/app/src/main/cpp/HttpTransferCallbackHookImpl.cpp
clang++: warning: argument unused during compilation: '-s' [-Wunused-command-line-argument]
error: unable to open output file '/apps/temp/HttpTransferCallbackHookImpl-baaa5e.s': 'No such file or directory'
1 error generated.
ninja: build stopped: subcommand failed.
The issue here is I am able to run this command and it builds the native libraries successfully when run the machine locally, but it fails when it is run through jenkins. The other amusing thing is that it fails only for the abi armeabi-v7a and passes for all other architectures.
I have verified the user, path and environment variables like ANDROID_HOME and ANDROID_NDK_HOME which are same when I run using the command line on the machine locally and when run using jenkins.
The command was not able to open the output files in the location "/apps/temp" as this directory was not present in the slave. This temp directory present in the jenkins master and was passed to the slave which was visible in the build variable TMP_DIR. Explicitly mentioning a valid temporary directory for the jenkins slave fixed the issue.

Android Studio NDK Build command failed (Missing c Compiler?)

I have tried several days installing the NDK into Android Studio but it always gives me an error message saying that the build failed and I should install a c compiler. I installed the NDK via the SDK Manager by checking the NDK and C Make.
I have already tried completely reinstalling Android Studio and the NDK but that did not work as well -same error.
Something maybe worth mentioning is that if I do not check the C++ support during the project creation there are no errors(but no c++ support too:D).
What should I do because it kills my workflow?
Thank you very much
The Error Message:
Blockquote
External Native Build Issues
Build command failed.
Error while executing process C:\Users\Julius Debus\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {-HC:\Users\Julius Debus\Desktop\MyApplication\app -BC:\Users\Julius Debus\Desktop\MyApplication\app.externalNativeBuild\cmake\release\armeabi-v7a -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=android-21 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Julius Debus\Desktop\MyApplication\app\build\intermediates\cmake\release\obj\armeabi-v7a -DCMAKE_BUILD_TYPE=Release -DANDROID_NDK=C:\Users\Julius Debus\AppData\Local\Android\Sdk\ndk-bundle -DCMAKE_CXX_FLAGS=-std=c++11 -frtti -fexceptions -DCMAKE_TOOLCHAIN_FILE=C:\Users\Julius Debus\AppData\Local\Android\Sdk\ndk-bundle\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=C:\Users\Julius Debus\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\ninja.exe -GAndroid Gradle - Ninja}
-- Check for working C compiler: C:/Users/Julius Debus/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- Check for working C compiler: C:/Users/Julius Debus/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- broken
It fails with the following output:
Change Dir: C:/Users/Julius Debus/Desktop/MyApplication/app/.externalNativeBuild/cmake/release/armeabi-v7a/CMakeFiles/CMakeTmp
Run Build Command:"C:/Users/Julius
Debus/AppData/Local/Android/Sdk/cmake/3.6.4111459/bin/ninja.exe"
"cmTC_a4b3d"
[1/2] Building C object CMakeFiles/cmTC_a4b3d.dir/testCCompiler.c.o
FAILED:
C:\Users\JULIUS~1\AppData\Local\Android\Sdk\NDK-BU~1\TOOLCH~1\llvm\prebuilt\WINDOW~1\bin\clang.exe
--target=armv7-none-linux-androideabi --gcc-toolchain="C:/Users/Julius
Debus/AppData/Local/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64"
--sysroot="C:/Users/Julius
Debus/AppData/Local/Android/Sdk/ndk-bundle/sysroot" -isystem
C:/Users/Julius
Debus/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi
-D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables
-fstack-protector-strong -no-canonical-prefixes -march=armv7-a
-mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb
-Wa,--noexecstack -Wformat -Werror=format-security -fPIE -o
CMakeFiles/cmTC_a4b3d.dir/testCCompiler.c.o -c "C:\Users\Julius
Debus\Desktop\MyApplication\app.externalNativeBuild\cmake\release\armeabi-v7a\CMakeFiles\CMakeTmp\testCCompiler.c"
Error:Error:error: no such file or directory:
'Debus/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi'
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt
-- Configuring incomplete, errors occurred!
See also "C:/Users/Julius Debus/Desktop/MyApplication/app/.externalNativeBuild/cmake/release/armeabi-v7a/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Julius Debus/Desktop/MyApplication/app/.externalNativeBuild/cmake/release/armeabi-v7a/CMakeFiles/CMakeError.log".
Build command failed.
Error while executing process C:\Users\Julius Debus\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {-HC:\Users\Julius Debus\Desktop\MyApplication\app -BC:\Users\Julius Debus\Desktop\MyApplication\app\.externalNativeBuild\cmake\debug\armeabi-v7a -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=android-21 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Julius Debus\Desktop\MyApplication\app\build\intermediates\cmake\debug\obj\armeabi-v7a -DCMAKE_BUILD_TYPE=Debug -DANDROID_NDK=C:\Users\Julius Debus\AppData\Local\Android\Sdk\ndk-bundle -DCMAKE_CXX_FLAGS=-std=c++11 -frtti -fexceptions -DCMAKE_TOOLCHAIN_FILE=C:\Users\Julius Debus\AppData\Local\Android\Sdk\ndk-bundle\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=C:\Users\Julius Debus\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\ninja.exe -GAndroid Gradle - Ninja}
-- Check for working C compiler: C:/Users/Julius Debus/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- Check for working C compiler: C:/Users/Julius Debus/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- broken
It fails with the following output:
Change Dir: C:/Users/Julius Debus/Desktop/MyApplication/app/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeTmp
Run Build Command:"C:/Users/Julius
Debus/AppData/Local/Android/Sdk/cmake/3.6.4111459/bin/ninja.exe"
"cmTC_82ebe"
[1/2] Building C object CMakeFiles/cmTC_82ebe.dir/testCCompiler.c.o
FAILED:
C:\Users\JULIUS~1\AppData\Local\Android\Sdk\NDK-BU~1\TOOLCH~1\llvm\prebuilt\WINDOW~1\bin\clang.exe
--target=armv7-none-linux-androideabi --gcc-toolchain="C:/Users/Julius
Debus/AppData/Local/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64"
--sysroot="C:/Users/Julius
Debus/AppData/Local/Android/Sdk/ndk-bundle/sysroot" -isystem
C:/Users/Julius
Debus/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi
-D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables
-fstack-protector-strong -no-canonical-prefixes -march=armv7-a
-mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb
-Wa,--noexecstack -Wformat -Werror=format-security -fPIE -o
CMakeFiles/cmTC_82ebe.dir/testCCompiler.c.o -c "C:\Users\Julius
Debus\Desktop\MyApplication\app\.externalNativeBuild\cmake\debug\armeabi-v7a\CMakeFiles\CMakeTmp\testCCompiler.c"
Error:Error:error: no such file or directory:
'Debus/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi'
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt
-- Configuring incomplete, errors occurred!
See also "C:/Users/Julius Debus/Desktop/MyApplication/app/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Julius Debus/Desktop/MyApplication/app/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeError.log".
C:\Users\Julius Debus\AppData\Local\Android\Sdk\ndk-bundle\build\cmake\android.toolchain.cmake
Warning:Warning:line (63) (include) CMakeLists.txt
Warning:Warning:line (63) (include) CMakeLists.txt
C:\Users\Julius Debus\AppData\Local\Android\Sdk\cmake\3.6.4111459\share\cmake-3.6\Modules\CMakeTestCCompiler.cmake
Error:Error:line (61)/Users/Julius Debus/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe" is not able to compile a simple test program.
Open File
Error:Error:line (61)/Users/Julius Debus/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe" is not able to compile a simple test program.
Open File

NDK Clang error: undefined reference to 'localeconv'

I am trying to build C++ NDK lib inside Android Studio.I have an external lib called json and the Clang compiler faild on localeconv.
json.hpp:11867: error: undefined reference to 'localeconv'
The locale.h header exists and located inside ndk dir sysroot/usr/include.
My toolchain looks like this:
Gradle: (Showing only the part relevant to NDK)
externalNativeBuild {
cmake {
arguments "-DANDROID_PLATFORM_LEVEL=${platformVersion}",
'-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static'
}
ndk {
abiFilters 'armeabi-v7a'
}
}
Cmake
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11 -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -frtti -fexceptions -Wall")
//'native-lib' is the final .so that's packaged into apk
target_link_libraries(native-lib
OPENAL
FREETYPE
android
EGL
${OPENGL_LIB}
log
m
z
atomic
gnustl_static
)
And here is the linker command line:
[1/1] Linking CXX shared library
........\build\intermediates\cmake\debug\obj\armeabi-v7a\libnative-lib.so
FAILED: cmd.exe /C "cd . &&
D:\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe
--target=armv7-none-linux-androideabi --gcc-toolchain=D:/Android/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64
--sysroot=D:/Android/android-sdk/ndk-bundle/sysroot -fPIC -isystem D:/Android/android-sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi
-D__ANDROID_API__=19 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -Wall -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a --sysroot D:/Android/android-sdk/ndk-bundle/platforms/android-19/arch-arm
-Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so
The complete error:
"D:/Android/android-sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libgnustl_static.a"
&& cd ." D:\XXXXX\XXXXXX\windows....\thirdparty\json/json.hpp:11867:
error: undefined reference to 'localeconv' clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed. :app:externalNativeBuildDebug
FAILED
The target SDK is 21.Minimum SDK is 19.NDK Version: 15.0.4075724
The same code base is compiled fine in Visual Studio Android project which uses the same toolchain.
The answer is - NDK version for SDK 19 doesn't implement the whole C++11 standard in the STL. locale.h header has stubs for localeconv() method, but the library doesn't implement it.The closest Android SDK that implement localeconv() is SDK 21.This is implicitly stated in the header <locale.h>
struct lconv* localeconv(void) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
#if __ANDROID_API__ >= 21
locale_t duplocale(locale_t) __INTRODUCED_IN(21);
void freelocale(locale_t) __INTRODUCED_IN(21);
locale_t newlocale(int, const char*, locale_t) __INTRODUCED_IN(21);
#endif /* __ANDROID_API__ >= 21 */
char* setlocale(int, const char*);
#if __ANDROID_API__ >= 21
locale_t uselocale(locale_t) __INTRODUCED_IN(21);
#endif /* __ANDROID_API__ >= 21 */
#define LC_GLOBAL_LOCALE __BIONIC_CAST(reinterpret_cast, locale_t, -1L)
__END_DECLS
#endif /* _LOCALE_H_ */
For me, trying to use Lua 5.4.0, I have to define the API level to 21
Cmake file as:
set(ANDROID_NATIVE_API_LEVEL 21)
I had a similar problem, and unfortunaletly changing API level couldn't work for me --I was working with an old tablet which runs API16. You can try Crystax NDK or you can write an ugly function that mimics the localeconv(). The latter had solved my problem since I was building Lua for Android Terminal Emulator for hobby.

Categories

Resources