Unable to use Aspose.words on Android

I was trying out the Aspose.words SDK and after including its JAR, I am getting the below exception:

Caused by: java.lang.ClassNotFoundException: Didn't find class "org.bouncycastle.operator.DefaultAlgorithmNameFinder" on path: DexPathList[[zip file "/data/app/~~7Yor1dP0yUyNSv5XnCtVZw==/com.adobe.reader-8yCmtHAHXn2NHlXJDQvZIg==/base.apk"],nativeLibraryDirectories=[/data/app/~~7Yor1dP0yUyNSv5XnCtVZw==/com.adobe.reader-8yCmtHAHXn2NHlXJDQvZIg==/lib/arm64, /data/app/~~7Yor1dP0yUyNSv5XnCtVZw==/com.adobe.reader-8yCmtHAHXn2NHlXJDQvZIg==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at com.aspose.words.internal.zzRO.<clinit>(Unknown Source:851) 
    at com.aspose.words.internal.zzI4.zzW(Unknown Source:22) 
    at com.aspose.words.zzY0E.zzZ(Unknown Source:10030) 
    at com.aspose.words.zzY0E.zzZH(Unknown Source:551) 
    at com.aspose.words.zzY0E.zzZI(Unknown Source:493) 
    at com.aspose.words.Document.zzZ(Unknown Source:1131) 
    at com.aspose.words.Document.save(Unknown Source:1106) 
    at com.aspose.words.Document.save(Unknown Source:1079) 
    at com.adobe.reader.utils.ARFileOpenUtils.openFile(ARFileOpenUtils.kt:409)
    ....
2024-11-11 16:37:29.356  4424-4424  IBG-CR                  com.adobe.reader                     E  InstabugUncaughtExceptionHandler Caught an Unhandled Exception: java.lang.NoClassDefFoundError
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/bouncycastle/operator/DefaultAlgorithmNameFinder;
    at com.aspose.words.internal.zzRO.<clinit>(Unknown Source:851)
    at com.aspose.words.internal.zzI4.zzW(Unknown Source:22)
    at com.aspose.words.zzY0E.zzZ(Unknown Source:10030)
    at com.aspose.words.zzY0E.zzZH(Unknown Source:551)
    at com.aspose.words.zzY0E.zzZI(Unknown Source:493)
    at com.aspose.words.Document.zzZ(Unknown Source:1131)
    at com.aspose.words.Document.save(Unknown Source:1106)
    at com.aspose.words.Document.save(Unknown Source:1079)

Do we need to manually include bouncy castle dependency on Android with the SDK to make it work? I am using the 24.9 version of Aspose.words for Android.

@shubhgar

It seems that you are encountering a ClassNotFoundException related to the Bouncy Castle library while using Aspose.Words for Android. This issue typically arises when the required Bouncy Castle classes are not included in your project.

To resolve this, you will need to manually include the Bouncy Castle dependency in your Android project. The Aspose.Words for Android SDK relies on certain classes from the Bouncy Castle library, and if they are missing, you will face the NoClassDefFoundError you mentioned.

Here’s how you can include the Bouncy Castle library in your project:

  1. Add Bouncy Castle Dependency: If you are using Gradle, you can add the following line to your build.gradle file under the dependencies section:

    implementation 'org.bouncycastle:bcprov-jdk15on:1.68' // Check for the latest version
    
  2. Sync Your Project: After adding the dependency, make sure to sync your project with Gradle files.

  3. Rebuild Your Project: Clean and rebuild your project to ensure that all dependencies are correctly included.

By following these steps, you should be able to resolve the ClassNotFoundException and successfully use Aspose.Words for Android.

If you continue to experience issues, please check the documentation for any additional setup instructions or dependencies that may be required for your specific version of Aspose.Words.

Sources:
[1]: Install Aspose.Words for Android via Java - Aspose Documentation

Even after including this dependency, I get the same error.

Hi @shubhgar

Can you try to use 24.6 version of Aspose.Words for Android?
In version 24.9 I updated Bouncy Castle library from 1.0.2.4 to 2.0.0 and on my side all work fine.

Thanks, It is working fine with 24.6 version.

1 Like