Configure Scrypt in Gradle for x86 android devices

346 views Asked by At

In my application I need to use a Scrypt library but there's an issue: scrypt-1.4.0.jar which is taken from Maven Central refuses to work on x86 architectures.

A hint to solution has been found in this thread: https://groups.google.com/forum/#!topic/bitcoinj/B0kOqUVIW24, specifically:

Yes, the scrypt jar on Maven Central contains native code (lib/*.so). They really should put this into a separate artifact )-:

Anyway, I'm using

 <excludeJarResources>   
 <excludeJarResource>.*\.jar$</excludeJarResource> 
 </excludeJarResources>  

in my android-maven-plugin configuration. You need to find something similar for Gradle.

I use Adroid Studio and have no idea how to achieve the same result in Gradle. The only "solution" I've found is excluding Scrypt library entierly:

dependencies {
    compile('org.bitcoinj:bitcoinj-core:0.12.2') {
        exclude module: 'scrypt'
    }
}

But of course that only works until I need to use Scrypt in my app. Here's a comment for the code above from the same thread:

Andreas' code only excludes the JAR resources i.e. dynamic library, which means the scrypt library will fall back to a pure Java implementation (much slower).

How can I achieve the same in Gradle? Or alternatively, there was a suggestion to compile the Scrypt native library with the NDK but I have no idea how to do that.

1

There are 1 answers

0
intika On BEST ANSWER

Solution :

I advice you to recompile the library, i compile my library under linux it's easy, here is how (note it takes a long time to get them compiled)

Setting up the Environment :

  1. Download and decompress Android NDK
  2. Add NDK to Environment Variables (See below)
  3. Install android SDK Framework
  4. Add Android SDK to Environment Variables (See below)

Command line to start SDK Manager :

sdk/tool/androis (sdk manager)

Adding Android to Environment Variables (Must be done before compiling library) :

export ANDROID_HOME=/media/.../android-sdk-linux

export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

export PATH=~/bin:/media/.../android-sdk-linux/tools/:/media/.../android-ndk-r10d/:$PATH

Compiling Library :

from the project root : run ./misc/build-native.sh

Android Studio :

Info : add android studio bin to bin path

Run : from bin dir run studio

Cleanning Library to recompile them :

  1. Delete following folders "\obj" "\ovpnlibs" "\libs"

  2. Recompile library