How to include the Spongy Castle JAR in Android?

Nathan Fig picture Nathan Fig · Aug 1, 2011 · Viewed 31.6k times · Source

Apparently Spongy Castle is the Android alternative to using a full version of Bouncy Castle.

However, on importing the jar I'm getting all kinds of "cannot be resolved" errors because it relies on packages not included with Android, primarily javax.mail, javax.activation, and javax.awt.datatransfer.

So what's the best way around this? Responses to this question and this indicate those packages shouldn't be used at all, and this popular question doesn't even consider finding a way to get AWT back. So how is Spongy Castle relying on them? People are using Spongy Castle, right?

Answer

ua741 picture ua741 · Apr 22, 2015

If you are using gradle, then you can just specify your dependencies in build.gradle file like this:

dependencies {
     ....
    compile 'com.madgag.spongycastle:core:1.54.0.0'
    compile 'com.madgag.spongycastle:prov:1.54.0.0'
    compile 'com.madgag.spongycastle:pkix:1.54.0.0'
    compile 'com.madgag.spongycastle:pg:1.54.0.0'

    }

You can find out the latest version of the library here.

Don't forget to insert it as a security provider in your app.

    static {
    Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1);
}