Fails on Android Nougat in dlopen


Android Nougat made a change such that it permits linking only to NDK-provided native libraries, and libsqlite.so is not an NDK-provided native library. As a result, any attempt to dlopen libsqlite.so will result in a crash. More information on this can be found in the Xamarin.Android 6.2 release notes.

Xamarin.Android developers currently use SQLite-net PCL, which uses platform-independent code to get around this problem. However, the Portable Class Library for SQLite appears to be using the libsqlite.so library provided by the Android OS, and thus fails when it runs on Android Nougat.

To verify this, I created two simple SQLite apps:

SQLiteFrank: uses SQLite-net PCM.
SQLiteCodePlex: uses the Portable Class Library for SQLite.

I'm using the Xamarin.Android N Preview with Visual Studio 2015, testing with Google's emulators on Windows 10 (Nexus5 images, configured for Android Lollipop and Android Nougat).

The results:

SQLiteFrank works on both Lollipop and Nougat.
SQLiteCodePlex works on Lollipop but fails on Nougat.

When SQLiteCodePlex fails on Nougat, it produces errors in the output window like this:

library "/system/lib/libsqlite.so" ("/system/lib/libsqlite.so") needed or dlopened by "/data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so" is not accessible for the namespace

I've attached the project that fails.

file attachments


Mogikan wrote Oct 11, 2016 at 11:26 AM

Tested it in Released version of Android N:
It shows the following popup warning if I choose target API 24: Detected problems with native libraries (please consult log for detail): libmonosgen-2.0.so: unauthorized access to "/system/lib64/libsqlite.so"
I found the following in the console:
10-11 18:20:31.856: W/linker(11919): library "/system/lib64/libsqlite.so" ("/system/lib64/libsqlite.so") needed or dlopened by "/data/app/com.perpetuumsoft.mobidb.lite-1/lib/arm64/libmonosgen-2.0.so" is not accessible for the namespace "classloader-namespace" - the access is temporarily granted as a workaround for http://b/26394120, note that the access will be removed in future releases of Android.

Mogikan wrote Oct 13, 2016 at 7:51 AM

Is there any chance this bug will be fixed? I see that commits are quite old and almost 2 y.o. Should I switch to another framework which supports android 7?

Mogikan wrote Oct 14, 2016 at 8:17 AM

OK, never mind, half of the day and I switched to another non-dead library sqlite-net-pcl.
More details can be found here: https://forums.xamarin.com/discussion/78234/android-libmonosgen-library-sqlite-problems-with-app-native-libraries.