Connect my Java Android App To MongoDB Atlas Serverless Insatnce

I try to use the mongo DB atlas for my app. It works fine on the iOS side with MongoKitten.

On the Android side, I try to use the official driver

no matter which version, my app crashed when trying to connect to the database

`java.lang.NoClassDefFoundError: Failed resolution of:

    at com.mongodb.internal.dns.JndiDnsClient.createDnsDirContext(`
    `the official code

    package fundamentals;

   `your text`import com.mongodb.*;
   import org.bson.BsonDocument;
   import org.bson.BsonInt64;
   import org.bson.Document;
   import org.bson.conversions.Bson;

   import com.mongodb.client.MongoClient;
   import com.mongodb.client.MongoClients;
   import com.mongodb.client.MongoDatabase;

   public class MongoClientConnectionExample {
       public static void main(String[] args) {
           // Replace the placeholder with your Atlas connection string
              String uri = "<connection string>";

           // Construct a ServerApi instance using the ServerApi.builder() method
           ServerApi serverApi = ServerApi.builder()

           MongoClientSettings settings = MongoClientSettings.builder()
                   .applyConnectionString(new ConnectionString(uri))

           // Create a new client and connect to the server
           try (MongoClient mongoClient = MongoClients.create(settings)) {
               MongoDatabase database = mongoClient.getDatabase("admin");
               try {
                   // Send a ping to confirm a successful connection
                   Bson command = new BsonDocument("ping", new BsonInt64(1));
                   Document commandResult = database.runCommand(command);
                   System.out.println("Pinged your deployment. You successfully connected to         
             } catch (MongoException me) {

implementation 'org.mongodb:mongodb-driver-sync:4.11.1'

also when installing

2 files found with path ‘META-INF/native-image/org.mongodb/bson/’.

issue comes up

Which I solve by using

pickFirst 'META-INF/native-image/org.mongodb/bson/

can anyone help me to solve these issues?

I tried the official guide

Are you attempting to connect to MongoDB Atlas directly from a phone client? If yes, that may well be the locus of the problem here: As a general rule you wouldn’t want to connect and end client directly to a database without going through a backend layer: for example you could spin up a backend on a cloud server or functions service that uses the MongoDB java driver which you connect to from your client via an API call (or via one of our device SDKs