Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Android demo compile issues #47

Open
Jasonvdb opened this issue Jan 19, 2021 · 17 comments · May be fixed by #48
Open

Android demo compile issues #47

Jasonvdb opened this issue Jan 19, 2021 · 17 comments · May be fixed by #48
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed
Milestone

Comments

@Jasonvdb
Copy link
Collaborator

Steps to reproduce:

  • Used these instructions to build the artifacts on ubuntu using docker.
  • Copied artifacts/android/library-debug.aar into demo/android/app/libs/
  • Open /demo/android in Android Studio and build project

Build error:

/Users/jason/Documents/Repositories/rgb/rgb-sdk/demo/android/app/src/main/java/org/lnpbp/demoapp/DemoApp.java:6: error: package org.lnpbp.rgbnode does not exist
import org.lnpbp.rgbnode.Runtime;
                        ^

I noticed org.lnpbp.rgbnode.Runtime does not exist but org.lnpbp.rgb.Runtime does so I made these changes and I get the app to build but it then crashes on first open with this run error:

I/DemoApp: Loading 'rgb_node' library
E/DemoApp: Error loading 'rgb_node' library: java.lang.UnsatisfiedLinkError: dlopen failed: library "librgb_node.so" not found
E/g.lnpbp.demoap: No implementation found for long org.lnpbp.rgb_autogen.rgbJNI.rgb_node_run(java.lang.String, java.lang.String, java.lang.String, short) (tried Java_org_lnpbp_rgb_1autogen_rgbJNI_rgb_1node_1run and Java_org_lnpbp_rgb_1autogen_rgbJNI_rgb_1node_1run__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2S)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.lnpbp.demoapp, PID: 7455
    java.lang.UnsatisfiedLinkError: No implementation found for long org.lnpbp.rgb_autogen.rgbJNI.rgb_node_run(java.lang.String, java.lang.String, java.lang.String, short) (tried Java_org_lnpbp_rgb_1autogen_rgbJNI_rgb_1node_1run and Java_org_lnpbp_rgb_1autogen_rgbJNI_rgb_1node_1run__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2S)
        at org.lnpbp.rgb_autogen.rgbJNI.rgb_node_run(Native Method)
        at org.lnpbp.rgb_autogen.rgb.rgb_node_run(rgb.java:57)
        at org.lnpbp.rgb.Runtime.<init>(Runtime.java:24)
        at org.lnpbp.demoapp.DemoApp.onCreate(DemoApp.java:32)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6712)
        at android.app.ActivityThread.access$1300(ActivityThread.java:237)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
@dr-orlovsky dr-orlovsky self-assigned this Jan 19, 2021
@dr-orlovsky dr-orlovsky added the bug Something isn't working label Jan 19, 2021
@dr-orlovsky dr-orlovsky added this to the v0.2 milestone Jan 19, 2021
@dr-orlovsky
Copy link
Member

The crash seems to be another naming-related issue. Will try to fix

@dr-orlovsky
Copy link
Member

Ok, this is not the naming issue. It just can't find the library in runtime, i.e. it is not copied as a part of APK: E/DemoApp: Error loading 'rgb_node' library: java.lang.UnsatisfiedLinkError: dlopen failed: library "librgb_node.so" not found

@dr-orlovsky
Copy link
Member

Working on replicating all the steps. BTW, you get this error on device or in simulator? And are you using Java or already React Native?

@Jasonvdb
Copy link
Collaborator Author

Have managed to get the same error on a device and simulator.

For this error I'm using the Java Android demo in this repo. I do have a react-native wrapper that is working for iOS so far. If I can get this demo working then it should be simple enough to fix for react-native as well.

@dr-orlovsky
Copy link
Member

Screen Shot 2021-01-19 at 15 09 13

From what I see by looking inside .aar package is that the binary library called librgb.so and not librgb_node.so (while Android is looking for librgb_node.so as error message says). Don't know how to change that part, I assume this is something gradle-related. Any ideas?

@dr-orlovsky
Copy link
Member

dr-orlovsky commented Jan 19, 2021

... considering of renaming librgb.so back into librgb_node.so. This renaming was mostly accidential and I see has broken many things

@Jasonvdb
Copy link
Collaborator Author

I thought maybe just changing this line final String libName = "rgb_node"; to use rgb instead of rgb_node would work but I then get the this error:

E/DemoApp: Error loading 'rgb' library: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZNSt12length_errorD1Ev" referenced by "/data/app/~~LN6GpR4dsQOH6xN0_cqfNA==/org.lnpbp.demoapp-1eB-I4WLe5-ims5tw7RtTA==/lib/x86/librgb.so"...
E/g.lnpbp.demoap: No implementation found for long org.lnpbp.rgb_autogen.rgbJNI.rgb_node_run(java.lang.String, java.lang.String, java.lang.String, short) (tried Java_org_lnpbp_rgb_1autogen_rgbJNI_rgb_1node_1run and Java_org_lnpbp_rgb_1autogen_rgbJNI_rgb_1node_1run__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2S)

I can't see where else to fix the name, there's nothing in the gradle file it seems.

@dr-orlovsky
Copy link
Member

Ok, figured out the reason of the second error. Now actually it finds the library, however swig (after update?) generates incorrect binding linking uchar/byte to short (which is two bytes). Figuring out how to fix.

@dr-orlovsky
Copy link
Member

dr-orlovsky commented Jan 20, 2021

E/DemoApp: Error loading 'rgb' library: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZNSt12length_errorD1Ev" referenced by "/data/app/~~LN6GpR4dsQOH6xN0_cqfNA==/org.lnpbp.demoapp-1eB-I4WLe5-ims5tw7RtTA==/lib/x86/librgb.so"...

Spent a day investigating & trying to fix. No success so far; however what I have found out:

  1. Error is a library linking error: it happens before any function inside the app or inside the library is called and before the app has actually started.
  2. Error is independent from library name: I tried both librgb and librgb_node. Error and happens only when library named in the correct way (if the library named incorrectly we have the other, originally reported issue).
  3. Changing function name and it's arguments does not fix the issue; it continues to happen for the new function
  4. The symbol mentioned in the error text (length_error) is absent from the code and I have no idea why it is required and how it should be used.
  5. Improving/changing swig.i does not affect error.

@dr-orlovsky dr-orlovsky added the help wanted Extra attention is needed label Jan 20, 2021
@dr-orlovsky
Copy link
Member

Ok, this seems to be an Android NDK issue: android/ndk#833

Strange we had not it before. Will try to fix by switching to c++_static library.

@dr-orlovsky
Copy link
Member

Other links relevant in the context:

@dr-orlovsky
Copy link
Member

ReLink does not help; the error persists.

With static lib now it can't find a function from libc++_shared.
The library is included into the .aar file, so DemoApp gradle due to some reason does not include it into the resulting apk, causing the original error.

I.e. the reason of the error is that libc++_shared is not part of the APK (while present in the aar produced from bindings). This is the problem of the demo app; unfortunately I have not found how to fix it yet.

UkolovaOlga added a commit to LNP-BP/devcalls that referenced this issue Jan 21, 2021
Agenda:

1. Dev Updates:
- Updates on related projects: rust-bitcoin & rust-miniscript
- Updates on refactoring LNP/BP Core Lib and info on new crates (wallet descriptors, RGB Core, LNP Core, Internet2)
- Moving repositories into project-specific github orgs (RGB-org, Internet2-org)
- v0.3.0 release of LNP/BP Core Lib, RGB Core Lib & RGB Node
- New developments with LNP Core & BOLT-7 by @raj
- Proposed architecture for mobile wallets using RGB+LNP Node
- RGB/LN invoicing protocol: aspects related to mobile payment

2. Pending issues to discuss:
LNP-BP/LNPBPs#83
RGB-WG/rgb-sdk#47
#33

Presentation slides are here https://github.com/LNP-BP/FAQ/blob/master/Presentation%20slides/LNP:BP%20v0.3%20libraries.pdf
YouTube videos are uploaded to the LNP/BP Standards Association channel https://www.youtube.com/c/LNPBP/
@dr-orlovsky dr-orlovsky linked a pull request Jan 21, 2021 that will close this issue
UkolovaOlga added a commit to UkolovaOlga/devcalls that referenced this issue Jan 21, 2021
Agenda:

1. Dev Updates:
- Updates on related projects: rust-bitcoin & rust-miniscript
- Updates on refactoring LNP/BP Core Lib and info on new crates (wallet descriptors, RGB Core, LNP Core, Internet2)
- Moving repositories into project-specific github orgs (RGB-org, Internet2-org)
- v0.3.0 release of LNP/BP Core Lib, RGB Core Lib & RGB Node
- New developments with LNP Core & BOLT-7 by @raj
- Proposed architecture for mobile wallets using RGB+LNP Node
- RGB/LN invoicing protocol: aspects related to mobile payment

2. Pending issues to discuss:
LNP-BP/LNPBPs#83
RGB-WG/rgb-sdk#47
LNP-BP#33

Presentation slides are here https://github.com/LNP-BP/FAQ/blob/master/Presentation%20slides/LNP:BP%20v0.3%20libraries.pdf
YouTube videos are uploaded to the LNP/BP Standards Association channel https://www.youtube.com/c/LNPBP/


@UkolovaOlga UkolovaOlga added bounty Bounty is established for solving this issue and removed bounty Bounty is established for solving this issue labels Jan 22, 2021
@KotlinGeekDev
Copy link

Hello @dr-orlovsky . I am a volunteer for solving this bug. I just had a discussion with an NDK dev about it here . It seems that one of the problems is a dependency(actually, a set of dependencies), cc, and cmake, that first need to be updated, for better interop with the current version of the NDK(or newer) used in the build script.
Thanks.

@dr-orlovsky
Copy link
Member

dr-orlovsky commented Jun 6, 2021

Hi @AnonymousGeekDev! Thank you for proposing volunteering! Right now this demo is outdated and we are preparing compatibility-breaking release of RGB which will require update of the demo and will reduce the number of downstream C dependencies, so the issue may be resolved at that point (but we may have other new issues of course, so we may still need your help then)

@KotlinGeekDev
Copy link

OK @dr-orlovsky thanks for the feedback! I am also interested in building an Android client for MyCitadel, and I have the impression that the future changes will probably be of relevance there :)

@dr-orlovsky
Copy link
Member

@AnonymousGeekDev we will ship so-called CitadelRuntime Android build as a library that you will be able to use in your wallet on Android

@zoedberg
Copy link
Contributor

zoedberg commented Jun 6, 2022

as @DanAlbert pointed out here, the clang++ output is clobbered by the cargo build output (by a cp that overrides the output of the previous command).

you can find here the PR solving this issue, making the android library work again and the java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol [...] error disappear.

for future records, here the contents of a working library:

$ unzip -l artifacts/android/library-release.aar 

Archive:  artifacts/android/library-release.aar
  Length      Date    Time    Name
---------  ---------- -----   ----
    88185  1980-02-01 00:00   R.txt
      299  1980-02-01 00:00   AndroidManifest.xml
    11108  1980-02-01 00:00   classes.jar
        0  1980-02-01 00:00   jni/
        0  1980-02-01 00:00   jni/arm64-v8a/
   936368  1980-02-01 00:00   jni/arm64-v8a/libc++_shared.so
  9633752  1980-02-01 00:00   jni/arm64-v8a/librgb.so
    22360  1980-02-01 00:00   jni/arm64-v8a/librgb_node.so
        0  1980-02-01 00:00   jni/armeabi-v7a/
   558988  1980-02-01 00:00   jni/armeabi-v7a/libc++_shared.so
  6871928  1980-02-01 00:00   jni/armeabi-v7a/librgb.so
    30324  1980-02-01 00:00   jni/armeabi-v7a/librgb_node.so
        0  1980-02-01 00:00   jni/x86/
   939924  1980-02-01 00:00   jni/x86/libc++_shared.so
 13204352  1980-02-01 00:00   jni/x86/librgb.so
    26120  1980-02-01 00:00   jni/x86/librgb_node.so
        0  1980-02-01 00:00   jni/x86_64/
  1002168  1980-02-01 00:00   jni/x86_64/libc++_shared.so
 12435664  1980-02-01 00:00   jni/x86_64/librgb.so
    22632  1980-02-01 00:00   jni/x86_64/librgb_node.so
        0  1980-02-01 00:00   arm64-v8a/
        0  1980-02-01 00:00   armeabi-v7a/
        0  1980-02-01 00:00   x86/
        0  1980-02-01 00:00   x86_64/
---------                     -------
 45784172                     24 files

please note that in each ABI directory there are 3 files, the libc++_shared.so for standard library definitions, the librgb.so outputted by the cargo build and the librgb_node.so that glues all together

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants