How to use NativeSecp256k1 wrapper from Bitcoinj in Android? - android

As I understand bitcoinj library contains wrapper for bitcoin-core functions - NativeSecp256k1. I am trying to call one of methods from this wrapper:
NativeSecp256k1.secKeyVerify(byteArrayOf(...))
But I got a crash:
java.lang.UnsatisfiedLinkError: No implementation found for int
org.bitcoin.NativeSecp256k1.secp256k1_ec_seckey_verify(java.nio.ByteBuffer,
long) (tried
Java_org_bitcoin_NativeSecp256k1_secp256k1_1ec_1seckey_1verify and
Java_org_bitcoin_NativeSecp256k1_secp256k1_1ec_1seckey_1verify__Ljava_nio_ByteBuffer_2J)
at org.bitcoin.NativeSecp256k1.secp256k1_ec_seckey_verify(Native Method)
at org.bitcoin.NativeSecp256k1.secKeyVerify(NativeSecp256k1.java:134)
at com.my.app.MainActivity.onCreate(MainActivity.kt:15)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
It looks like bitcoinj library contains the wrapper but doesn't contains native library which used in this wrapper. How to fix this issue?

Bitcoinj uses JNI to load a C library for secp256k1 curve operations. If the lib is imported correctly... and since you are trying to access it directly, you might be missing the System.loadLibrary('secp256k1') call
Check here : https://github.com/bitcoinj/bitcoinj/blob/2ec193f8479425c3a66bebf5f2d3493e39e88f7c/core/src/main/java/org/bitcoin/Secp256k1Context.java
To build the compiles sources for the lib, its describes in the comment block of the NativeSecp256k1 class, here : https://github.com/bitcoinj/bitcoinj/blob/2ec193f8479425c3a66bebf5f2d3493e39e88f7c/core/src/main/java/org/bitcoin/NativeSecp256k1.java#L34

Related

Using Zbar.jar for Bar code scan, but it is not working in Android 6.0 and up

I am getting error while opening scanning bar code on the below line of code:
static
{
System.loadLibrary("iconv");
}
After that getting run time exception as mentioned below:
02-19 00:35:54.101 17727-17727/com.trialliancebarcode E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.trialliancebarcode, PID: 17727
java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/com.trialliancebarcode-1/lib/arm/libiconv.so: has text relocations
at java.lang.Runtime.loadLibrary(Runtime.java:372)
at java.lang.System.loadLibrary(System.java:1076)
at com.trialliancebarcode.BarcodeScanner.<clinit>(BarcodeScanner.java:48)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1090)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Please help me on this.
i'm not using ZBAR but i work on project Reading barcode
i use mobile vision Api supported by google try it
Check this Link
Please try this:
Download the latest ZBar project here
grab the latest .so from barcodescanner/zbar/src/main/jniLibs, and replace the relative .so in your project.
Run your app.
(Works well targetSdkVersion 25, buildToolsVersion '25.0.3', compileSdkVersion 25, or below)

Android Studio OpenCV Library not working

I have followed the directions here OpenCV in Android Studio the one that has 94 votes. I get this error when I dod System.loadlibrary("opencv-java")
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file
"/data/app/com.krikorherlopian.opencvsample-
1/base.apk"],nativeLibraryDirectories=
[/data/app/com.krikorherlopian.opencvsample-1/lib/arm,
/data/app/com.krikorherlopian.opencvsample-1/base.apk!/lib/armeabi-
v7a, /vendor/lib, /system/lib]]] couldn't find "libopencv_java.so"
at java.lang.Runtime.loadLibrary(Runtime.java:367)
at java.lang.System.loadLibrary(System.java:1076)
at com.krikorherlopian.opencvsample.MainActivity.onCreate(MainActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
EDIT: I still get the error , and I have the ndk added . Krikors-MacBook-Air:~ KrikorHerlopian$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/KrikorHerlopian/Downloads/adt-bundle-mac-x86_64-20140702/sdk/ndk-bundle
Whats the problem?
Edit2: Now I got problem of Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: /Users/KrikorHerlopian/Downloads/adt-bundle-mac-x86_64-20140702/sdk/ndk-bundle//jni/Android.mk when i try running my app from the terminal using /Users/KrikorHerlopian/Downloads/adt-bundle-mac-x86_64-20140702/sdk/ndk-bundle/ndk-build

issues with ttorrent with android?

i was looking for a torrent library for android and came-across ttorrent
.when i tried to add dependencty to gradle it gave me errors regarding slf4j-log4j12.
i ended up adding all jar files manually and managed to run the app using sample code.
But i am getting this error now.
ClassLoader referenced unknown path: /data/app/com.test.torrent-1/lib/arm64
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273)
at java.net.InetAddress.lookupHostByName(InetAddress.java:431)
at java.net.InetAddress.getLocalHost(InetAddress.java:409)
at com.test.torrent.MainActivity.onCreate(MainActivity.java:26)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
i think it is trying to find a library but i cannot find it , that path does not exist in my mobile , any help?

Should we absolutely add meta-data tag for Facebook SDK?

I am adding Facebook Share functionality to my app. I am using SDK v4.5. In the SDK documentation, we are told to add the following meta-data tag to AndroidManifest:
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
The problem is, I get my app id from server by making an http request. In the older version of Facebook SDK, i could initialize the SDK with the app id from java code, so it would not be a problem:
mFacebook = new Facebook(FACEBOOK_APP_ID);
But now with the new SDK, if I do not put that meta-data tag, I get the following error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.yrazlik.facebooklogindemo, PID: 6450
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.yrazlik.facebooklogindemo/com.yrazlik.facebooklogindemo.MainActivity}:
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:772)
at com.facebook.internal.Utility.getDialogFeatureConfig(Utility.java:882)
at com.facebook.internal.DialogPresenter.getVersionSpecForFeature(DialogPresenter.java:253)
at com.facebook.internal.DialogPresenter.getProtocolVersionForNativeDialog(DialogPresenter.java:239)
at com.facebook.internal.DialogPresenter.canPresentNativeDialogWithFeature(DialogPresenter.java:73)
at com.facebook.share.widget.ShareDialog.canShowNative(ShareDialog.java:131)
at com.facebook.share.widget.ShareDialog.access$300(ShareDialog.java:53)
at com.facebook.share.widget.ShareDialog$NativeHandler.canShow(ShareDialog.java:239)
at com.facebook.share.widget.ShareDialog$NativeHandler.canShow(ShareDialog.java:231)
at com.facebook.internal.FacebookDialogBase.createAppCallForMode(FacebookDialogBase.java:184)
at com.facebook.internal.FacebookDialogBase.showImpl(FacebookDialogBase.java:147)
at com.facebook.internal.FacebookDialogBase.show(FacebookDialogBase.java:142)
at com.yrazlik.facebooklogindemo.MainActivity.onCreate(MainActivity.java:136)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
So, is there anything I can do about that? Can i somehow set app id from java code instead of using meta-data tag?
Thanks.
I found a way to do this. There is clearly a method for setting the app id from code instead of using meta-data tag. I deleted the meta-data tag from the manifest, and used the following methods and now it works fine.
FacebookSdk.setApplicationId(AppConstants.FACEBOOK_APP_ID);
FacebookSdk.sdkInitialize(getApplicationContext());
You can make service call for facebook app id at the time of splash screen. and save it in sharedpreferences.
then initialize
FacebookSdk.setApplicationId(GET FACEBOOK APP ID FROM SHARED PREFERENCES);
Facebook.sdkInitialize(getApplicationContext());
But make sure you have to first get facebook app id from server and then only you can initialize. otherwise application will be force closed.

An app using zbar library for scanning QR codes is getting crash.

I am trying to run the QR scanner app downloaded from
http://kvenkataprasad.blogspot.in/2015/01/bar-code-and-qr-code-scanner-example.html?showComment=1449051540990#c226949441944394510
App getting started but when I am clicking the scan button, the app get crashed.
Following the log of crash.
13239-13239/com.kvprasad.zbarbarcodescanner E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.kvprasad.zbarbarcodescanner, PID: 13239
java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/com.kvprasad.zbarbarcodescanner-1/lib/arm/libzbarjni.so: has text relocations
at java.lang.Runtime.loadLibrary(Runtime.java:372)
at java.lang.System.loadLibrary(System.java:1076)
at net.sourceforge.zbar.ImageScanner.<clinit>(Unknown Source)
at com.kvprasad.zbarbarcodescanner.BarcodeScanner.initControls(BarcodeScanner.java:52)
at com.kvprasad.zbarbarcodescanner.BarcodeScanner.onCreate(BarcodeScanner.java:42)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I am not getting the main issue behind crashing because I am a newbie in android. Please guide me to solve the problem.
Thanks.

Categories

Resources