@samuele.lucarini
Aspose.Words for Android – Upgrade & Bouncy‑Castle FIPS Issues
Below is a checklist that usually resolves the errors you see when initialising Aspose.Words after upgrading from 24.6 to a newer version while you are also pulling in the Bouncy‑Castle libraries you listed.
1. Use the Bouncy‑Castle version that Aspose.Words expects
| Aspose.Words (Android) |
Recommended Bouncy‑Castle artifact |
Reason |
| 24.7‑24.11 (and newer) |
org.bouncycastle:bcprov-jdk15on:<latest‑1.x> |
The library is compiled against the JDK 15 API. Using the JDK 18 (bcprov-jdk18on) can cause NoSuchMethodError / ClassNotFoundException at runtime on Android. |
| FIPS mode (optional) |
org.bouncycastle:bcprov-fips:<latest‑1.x> and org.bouncycastle:bcpkix-fips:<latest‑1.x> |
Only needed if you explicitly enable the FIPS provider in your code. |
Action
// Remove the JDK‑18 artifacts
// implementation 'org.bouncycastle:bcprov-jdk18on:1.83'
// implementation 'org.bouncycastle:bcutil-jdk18on:1.83'
// Add the supported JDK‑15 artifacts (or the FIPS ones if you need FIPS)
implementation 'org.bouncycastle:bcprov-jdk15on:1.78' // use the latest 1.x version
implementation 'org.bouncycastle:bcpkix-jdk15on:1.78' // optional – needed for PKIX support
Why?
Aspose.Words for Android bundles a light‑weight copy of the Bouncy‑Castle provider that works with the JDK 15 API. When the runtime resolves the newer JDK 18 classes first (because they are on the class‑path), the provider initialization fails.
2. Disable the transitive BC provider that comes with Aspose (if you want to keep your own version)
If you prefer to keep the Bouncy‑Castle version you supply, you must exclude the one that ships inside Aspose.Words:
implementation ('com.aspose:aspose-words-android:24.12') {
exclude group: 'org.bouncycastle', module: 'bcprov-jdk15on'
exclude group: 'org.bouncycastle', module: 'bcpkix-jdk15on'
}
Add the exact version you want after the exclusion (see step 1).
3. ProGuard / R8 keep rules (mandatory for Android releases)
When you shrink/obfuscate, the Bouncy‑Castle classes may be removed or renamed, causing the provider to throw java.security.NoSuchProviderException. Add the following rules to proguard‑rules.pro (or the equivalent R8 file):
# Keep all Bouncy Castle provider classes
-keep class org.bouncycastle.** { *; }
-dontwarn org.bouncycastle.**
# Keep the Aspose.Words security classes that reference BC
-keep class com.aspose.words.security.** { *; }
4. Initialising the provider (only required for explicit FIPS usage)
If you are not using the FIPS provider, do not call Security.addProvider(new BouncyCastleProvider()) – Aspose.Words already registers the bundled provider.
If you are using the FIPS provider, initialise it before any Aspose call:
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
import java.security.Security;
// Must be the very first line that touches Aspose
Security.addProvider(new BouncyCastleFipsProvider());
// Now you can safely call Aspose APIs
com.aspose.words.Document doc = new com.aspose.words.Document("input.docx");
Make sure the FIPS jars (bcprov-fips and bcpkix-fips) are on the class‑path.
5. Clean & rebuild
- Invalidate caches (Android Studio → File → Invalidate Caches / Restart).
- Delete the
build folder of the module (./gradlew clean).
- Re‑run the project (
./gradlew assembleDebug).
Frequently Reported Errors & Their Fixes
| Symptom |
Typical cause |
Fix |
java.lang.NoSuchMethodError: org.bouncycastle.crypto.digests.SHA256Digest.<init>()V |
Using bcprov-jdk18on with Aspose compiled against JDK 15 |
Switch to bcprov-jdk15on |
java.security.NoSuchProviderException: BouncyCastle FIPS |
FIPS provider not added or missing bcprov-fips jar |
Add the FIPS provider (step 4) and the correct artifacts |
ClassNotFoundException: org.bouncycastle.util.Arrays after ProGuard |
R8 stripped Bouncy‑Castle utilities |
Add keep rules (step 3) |
java.lang.IllegalStateException: Could not initialize BouncyCastle |
Both JDK 15 and JDK 18 providers present causing class‑loader conflict |
Exclude the unwanted BC module (step 2) |
Next Steps for You
- Replace the JDK 18 Bouncy‑Castle dependencies with JDK 15 (or FIPS) as shown in step 1.
- Add the ProGuard keep rules if you use code shrinking.
- Perform a clean rebuild and test the application.
If you still encounter an error, please post the exact stack‑trace (including the first Aspose‑related line) and the Aspose.Words version you upgraded to. With that information we can pinpoint any remaining incompatibility.
Helpful Links
Feel free to let us know if any of the steps need clarification or if the problem persists after applying them. We’re happy to help you get the upgrade running smoothly!