I am trying to build a .so for android and I want to build with address sanitizer but the only instructions I see are for Android NDK based Makefiles, but I am using the newer endorsed CMake setup. Just adding the flag -fsanitize=address wasn't enough as the clang runtime library was missing.
what is the correct thing to add in my CMakeLists for Android built libraries?
You also need to prepare your device as described in documentation. You have to run asan_device_setup script from NDK. It will put asan .so on the device.
Related
I am building an open source lib C/C++ for Android development using Android NDK. I had got code from Github and created my own jni folder under source code. In that jni folder, I created some C source files and included many header files in open source lib. But when I built, I had got failed log:
fatal error: bits/libc-header-start.h: No such file or directory
I checked and saw that file "libc-header-start.h" existed in /usr/include/x86_64-linux-gnu/bits/ folder of Ubuntu system but when building, it can not link to that header file
So can I use Ubuntu system header file in my Android NDK lib?
No, you should not use Ubuntu (or any other host) includes or libs to build an Android NDK library. NDK cross-compiles your code for the Android targets. Not all C++ projects on GitHub may be ported easily to Android. If they use CMake, these scripts often need adaptations for Android NDK. If they use automake tools, tuning the build scripts may be quite painful.
So can I use Ubuntu system header file in my Android NDK lib?
NO. You have to use all the Android NDK specific headers and libs for your NDK compilation, i.e. those inside your NDK folders.
Here is an example for Android JNI programming: https://github.com/russell-shizhen/JniExample
I am building a custom app in Android AOSP and added it under packages/apps/Car/MyApp
Currently, the only way that I know how to integrate it into the build process is to create a Makefile Android.mk. Since adding dependencies/3rd party libraries with that approach is very tedious I would prefer being able to do it via gradle.
Is there any known solution how to use gradle as the build system for the app and trigger it with the Android.mk so it is still included in the overall build?
You can build it with gradle, and write Android.mk for your built apk. For adding prebuilt apk as system/privilege app, you can visit the stackoverflow question How to include prebuilt APK into AOSP with platform privileges
I'm working on porting this digital logic library to Android. However, I keep getting build errors involving missing functions from standard libraries like CMath, or missing C++11 libraries when trying to compile the Android project. Searching has revealed that issues with building C++ for Android in Visual Studio are rather common, but none of the suggestions I have found so far have helped. Here is the project with the build errors.
I have tried changing the target platform, changing the platform toolset, and changing the use of STL. Various combinations of the settings. I can't seem to get anything building.
Should I just give up on Visual Studio for my mobile C++ code and build those libraries elsewhere?
After creating a new branch with only Android code (as opposed to the previous cross platform mobile branch) and further playing with settings and searching, I arrived at the solution. These settings will allow the code to compile:
Compiler: Clang 3.8
Use of STL: GNU STL Static library
C++ Language Standard: C++11
Linker Command Line Additional Options: -lm
The designation that made it work was the -lm linker option to ensure it was properly linking the math library.
I have a Java Android application project that includes a so library in libs/armeabi folder.
The c++ code of this library is in a different Android NDK project and is dependent on other different library NDK projects.
Is it possible to debug the c++ code of this library while the Java Android application is running?
In order to debug the native code in .so, first you need .so that was generated with debugging mode. (e.g., NDK_DEBUG = 1)
If you don't have source code and therefore no debuggable .so, there is no way to debug.
Also, please specify your environment such as Android NDK version, IDE, etc.
Assuming you are using Eclipse, this is detailed description how to debug native applications.
I have a Linux library that needs to be compiled under Android. I understand that should be used to build this program: / home/user/android-ndk/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/arm-eabi-gcc and then compile a ndk-build . I think right? Assembly via the utility should work correctly?
You need to install the Native Development Kit (NDK) and read through the documentation in the NDK about the build process. The NDK basic info is at http://developer.android.com/sdk/ndk/index.html, and you'll need to install an appropriate version of Cygwin (if you're using Windows).
It comes with a prebuilt compiler, so you shouldn't have to rebuild that.