Skip to main content
Skip table of contents

Android C++ Standard Library

The VeridiumID Mobile SDK includes components written in C++ and built with the Android NDK. Because of this, if you use other C++ components in your app, there are some important considerations to bear in mind.

Background: C++ Standard Library

Unlike many other platforms, Android and the NDK requires that the C++ standard library is distributed with your app, rather than being included as part of the OS. The NDK also provides multiple versions of the standard library: libc++ (in shared and static variants), and system (only includes new and delete, deprecated in NDK r18). Previous versions of the NDK also included GNU libstdc++ and STLport.

Because of the C++ One Definition Rule (ODR), you can only have one instance of the C++ standard library linked into a program.

Because of these limitations, the best option is to use the shared variant of libc++, referred to by the NDK as c++_shared. The other alternative, using c++_static, is problematic unless the app includes exactly one C++ shared library; each shared library would link in the static C++ standard library, and so end up duplicating it multiple times when each of those shared libraries is linked to the app, violating the ODR.

Possible Pitfalls

When building with Android Studio, the build process collects all C++/native libraries to bundle into the APK. If there are multiple copies of libraries with same filename, it may error out or pick one of them arbitrarily. It also can strip the standard library to remove unused symbols to reduce code size.

This can cause incompatibilities to arise, where libraries refuse to load with unresolved symbol errors. You may need to take some action to resolve this.

Troubleshooting

Scanning the apk dependencies using this script version_check.py will provide the list of native libraries that should be updated to use the newer NDK build.

Actions You May Need To Take

Remove the bundled C++ standard library from Veridium SDK

Change the extension of veridium-core-release.aar to .zip, extract the contents, remove every instance of libc++_shared.so, then re-zip it and change the extension back to .aar.

Third-Party Dependencies

Remove any included libc++_shared.so from third-party .aar dependencies using the same method as above.

Configure your own C++ libraries

Any C++ libraries you build as part of your Android Studio project must link with c++_shared rather than the default c++_static. The NDK has documentation for this, but in summary:

CMake

The section of the Gradle file which invokes CMake should set the ANDROID_STL variable.

CODE
externalNativeBuild {
    cmake {
        arguments '-DANDROID_STL=libc++_shared‘
        cppFlags ''
    }
}

ndk-build

Set APP_STL in the http://Application.mk file:

CODE
APP_STL := c++_shared

Create a 'dummy' C++ library

If you're not already building your own C++ library, you can create an empty C++ library in Android Studio and configure it as described in the previous section; this will cause Android Studio to bundle libc++_shared.so into the app.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.