mongodb 3.x driver Android compatibility mongodb 3.x driver Android compatibility mongodb mongodb

mongodb 3.x driver Android compatibility


It looks to me like the ManagementFactory is a red herring, as the driver catches that exception and falls back to using a random number instead.

The real problem appears to be that the driver needs to authenticate with SCRAM-SHA-1, the implementation of which imports the following classes:

import javax.crypto.Mac;import javax.crypto.SecretKeyFactory;import javax.crypto.spec.PBEKeySpec;import javax.crypto.spec.SecretKeySpec;import javax.security.sasl.SaslClient;import javax.security.sasl.SaslException;

I suspect that these are not available in the Android platform, which is not a complete implementation of the Java Runtime Environment.

One thing you could try would be to run against MongoDB 2.6, against which the driver's authentication implementation only relies on java.security.MessageDigest.

Another thing to think about is putting a REST service between the mobile app and MongoDB that is responsible for proxying all interactions with the database. The REST application can be run in an environment where the MongoDB driver will be fully functional.


For anyone want to use github.com/mongodb/mongo-java-driver on Android, I have a solution!

I've forked from ufficial github.com/mongodb/mongo-java-driver and integrated classes from github.com/koterpillar/android-sasl to fix javax.security.sasl on Android.

Important: No driver-async is not ported because java.nio.channels.AsynchronousSocketChannel doesn't exist on Android and doesn't exist any porting.

The result is a working synchronous MongoDB Android (Java) driver that you can download from https://github.com/matfur92/mongo-java-driver

LAST UPDATE (5 November 2015) : 3.2.0-SNAPSHOT --> https://github.com/matfur92/mongo-java-driver/blob/gh-pages/JARs/mongo-java-driver-3.2.0-SNAPSHOT.jar?raw=true


REST service workaround isn't the way, I must connect directly to mongodb instances.

EDIT:

Sync mongo-java-driver is correctly ported on Android with this porting: https://github.com/matfur92/mongo-java-driver

No driver-async is not ported because java.nio.channels.AsynchronousSocketChannel doesn't exist on Android and doesn't exist any porting.

If anyone has a solution to get driver-async working tell me please. The problem is in java.nio.channels.AsynchronousSocketChannel that not exist for Android