? ? ? ? web3j 4.6.0-android版本,在创建钱包地址时报以上错误。
1. 在自定义的Application中添加以下代码(注:添加位置如下图所示)。
public void setupBouncyCastle() {
final Provider provider = Security.getProvider(BouncyCastleProvider.PROVIDER_NAME);
if (provider == null) {
// Web3j will set up the provider lazily when it's first used.
return;
}
if (provider.getClass().equals(BouncyCastleProvider.class)) {
// BC with same package name, shouldn't happen in real life.
return;
}
// Android registers its own BC provider. As it might be outdated and might not include
// all needed ciphers, we substitute it with a known BC bundled in the app.
// Android's BC has its package rewritten to "com.android.org.bouncycastle" and because
// of that it's possible to have another BC implementation loaded in VM.
Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
Security.insertProviderAt(new BouncyCastleProvider(), 1);
}
2. 在XXXApplication中的onCreate()方法中调用setupBouncyCastle()函数。
注意:个人觉得在XXXApplication中的onCreate()方法中调用setupBouncyCastle(),或在自己所使用的Activity中调用setupBouncyCastle()都是可以的,小编是在Activity中调用的该方法,所以使用static修改方法。
3. 进行到这里,当我们重新运行项目的时候,会报内存溢出的错误。
重点……
解决方案:在AndroidManifest.xml中添加如下代码:
<application
......
android:hardwareAccelerated="true"
android:largeHeap="true"
...... >
? ? ? ? 此时,重启运行项目就好啦~~~
|