I am unable to connect cosmos db to android app

Isuru Jayasinghe 0 Reputation points
2023-11-29T11:25:47.5433333+00:00
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.myapplication, PID: 4077
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/sun/management/OperatingSystemMXBean;
        at com.azure.cosmos.implementation.cpu.CpuMemoryReader.<init>(CpuMemoryReader.java:25)
        at com.azure.cosmos.implementation.cpu.CpuMemoryMonitor.<clinit>(CpuMemoryMonitor.java:36)
        at com.azure.cosmos.implementation.cpu.CpuMemoryMonitor.register(CpuMemoryMonitor.java:77)
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,537 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. GeethaThatipatri-MSFT 29,017 Reputation points Microsoft Employee
    2023-11-29T13:54:09.91+00:00

    Hi @Isuru Jayasinghe Welcome to Microsoft Q&A thanks for posting your question.

    The issue you are facing with the OperatingSystemMXBean class is because it is not supported on Android. This class is used by the Azure Cosmos DB Java SDK to monitor CPU and memory usage, which is not applicable on Android. However, you can exclude the com.sun.management package from the SDK dependency to resolve this issue.

    It is important to note that directly calling Azure Cosmos DB from an Android app is not a recommended approach. Azure Cosmos DB is a distributed database that has a lot of logic being executed on the "client" side, such as partial query logic. For mobile apps, the usual and recommended pattern is to have the mobile app use a frontend service of the app and then connect to Azure Cosmos DB from that service.

    Regards

    Geetha

    0 comments No comments