在 Gradle 中为 x86 android 设备配置 Scrypt
Configure Scrypt in Gradle for x86 android devices
在我的应用程序中,我需要使用 Scrypt 库,但存在一个问题:取自 Maven Central 的 scrypt-1.4.0.jar
拒绝在 x86 架构上工作。
在此线程中找到了解决方案的提示:https://groups.google.com/forum/#!topic/bitcoinj/B0kOqUVIW24,特别是:
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.
我使用 Adroid Studio,但不知道如何在 Gradle 中获得相同的结果。我发现的唯一 "solution" 完全排除了 Scrypt 库:
dependencies {
compile('org.bitcoinj:bitcoinj-core:0.12.2') {
exclude module: 'scrypt'
}
}
当然,这只有在我需要在我的应用程序中使用 Scrypt 时才有效。这是同一线程对上述代码的评论:
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).
如何在 Gradle 中实现相同的目标?或者,有人建议使用 NDK 编译 Scrypt 本机库,但我不知道该怎么做。
解法:
我建议你重新编译库,我在 linux 下编译我的库,这很容易,这里是如何(注意编译它们需要很长时间)
设置环境:
- 下载解压AndroidNDK
- 将 NDK 添加到环境变量(见下文)
- 安装android SDK 框架
- 将Android SDK 添加到环境变量(见下文)
启动SDK管理器的命令行:
sdk/tool/androis(SDK 管理器)
将Android添加到环境变量(必须在编译库之前完成):
导出ANDROID_HOME=/media/.../android-sdk-linux
导出路径=${路径}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export PATH=~/bin:/media/.../android-sdk-linux/tools/:/media/.../android-ndk-r10d/:$PATH
编译库:
从项目根目录:运行
./misc/build-native.sh
Android工作室:
信息:将 android studio bin 添加到 bin 路径
运行 : 来自 bin 目录 运行 studio
清理库以重新编译它们:
删除以下文件夹
“\对象”
“\ovpnlibs”
"\libs"
重新编译库
在我的应用程序中,我需要使用 Scrypt 库,但存在一个问题:取自 Maven Central 的 scrypt-1.4.0.jar
拒绝在 x86 架构上工作。
在此线程中找到了解决方案的提示:https://groups.google.com/forum/#!topic/bitcoinj/B0kOqUVIW24,特别是:
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.
我使用 Adroid Studio,但不知道如何在 Gradle 中获得相同的结果。我发现的唯一 "solution" 完全排除了 Scrypt 库:
dependencies {
compile('org.bitcoinj:bitcoinj-core:0.12.2') {
exclude module: 'scrypt'
}
}
当然,这只有在我需要在我的应用程序中使用 Scrypt 时才有效。这是同一线程对上述代码的评论:
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).
如何在 Gradle 中实现相同的目标?或者,有人建议使用 NDK 编译 Scrypt 本机库,但我不知道该怎么做。
解法:
我建议你重新编译库,我在 linux 下编译我的库,这很容易,这里是如何(注意编译它们需要很长时间)
设置环境:
- 下载解压AndroidNDK
- 将 NDK 添加到环境变量(见下文)
- 安装android SDK 框架
- 将Android SDK 添加到环境变量(见下文)
启动SDK管理器的命令行:
sdk/tool/androis(SDK 管理器)
将Android添加到环境变量(必须在编译库之前完成):
导出ANDROID_HOME=/media/.../android-sdk-linux
导出路径=${路径}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export PATH=~/bin:/media/.../android-sdk-linux/tools/:/media/.../android-ndk-r10d/:$PATH
编译库:
从项目根目录:运行
./misc/build-native.sh
Android工作室:
信息:将 android studio bin 添加到 bin 路径
运行 : 来自 bin 目录 运行 studio
清理库以重新编译它们:
删除以下文件夹 “\对象” “\ovpnlibs” "\libs"
重新编译库