问题
I am trying to get a basic running app that would use the bitcoinj library to create a wallet and sync. Very basic. I used bitcoinj library for my desktop application with no problems. When i try to make one for android it hangs on "...Installing APK" when trying to run it on my phone.
This is my code.
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ProgressBar;
import org.bitcoinj.core.Context;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.listeners.DownloadProgressTracker;
import org.bitcoinj.kits.WalletAppKit;
import org.bitcoinj.params.TestNet3Params;
import java.io.File;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
public static NetworkParameters BTCparams = TestNet3Params.get();
public static WalletAppKit BTCkit = new WalletAppKit(BTCparams,new File("."),"BTC-Test");
private ProgressBar BTCProgress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BTCProgress = findViewById(R.id.BTCProgress);
Context.propagate(new Context(BTCparams));
DownloadProgressTracker BTCListener = new DownloadProgressTracker() {
@Override
public void progress(double pct, int blocksSoFar, Date date) {
System.out.println("Syncing..."+pct+"%");
BTCProgress.setProgress((int) pct);
}
@Override
public void doneDownload() {
System.out.println("Sync Done.");
BTCProgress.setProgress(100);
}
};
BTCkit.setDownloadListener(BTCListener).setBlockingStartup(false).startAsync().awaitRunning();
}
}
This is my build.gradle in my app folder.
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.testapp.testapp"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:design:28.0.0'
implementation 'org.bitcoinj:bitcoinj-core:0.14.7'
implementation 'org.slf4j:slf4j-api:1.7.12'
implementation 'org.slf4j:slf4j-simple:1.7.12'
}
I eventually get this dialog box.
Dialog
When i click ok i get this error.
Error
which brings you to here...
Binder.java
I am stumped and cannot figure out why this isnt working. I suspect once i resolve this issue then my development will be a breeze. Please provide details as im still learning the android development.
回答1:
change it to:
implementation "org.slf4j:slf4j-simple:1.7.25"
api "org.slf4j:slf4j-api:1.7.25"
this also looks strange:
Context.propagate(new Context(BTCparams));
because it is not even NULL
, but has no value.
来源:https://stackoverflow.com/questions/53620658/bitcoinj-library-on-android-hung-on-installing-apk