Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package does not work on Android. #19

Closed
danilobassi8 opened this issue Aug 5, 2024 · 20 comments · Fixed by #20
Closed

Package does not work on Android. #19

danilobassi8 opened this issue Aug 5, 2024 · 20 comments · Fixed by #20
Labels
bug Something isn't working more info needed Waiting for a response verified Bug is verified

Comments

@danilobassi8
Copy link

Hi guys, thanks for the efforts you put into making this expo module.

I've been trying to make a React app that uses the wesh protocol for the last weeks. I know nothing about golang, but I read on the discord channel that you've been working on this package to abstract the complexity of having to compile go code, and build our own native layer.

When I try to run the provided example app on the /example directory, I am having some errors. I'll put all the steps I made in order to make it "almost" work in my setup.

Setup

OS: Ubuntu 22.04 LTS
Phone: Motorola g100 with Android 12.

Steps to reproduce the error:

1 - Clone the repo and install packages.

git clone git@github.com:berty/weshnet-expo.git
cd weshnet-expo
make asdf.install_plugins
make asdf.install_tools

2 - Run the provided example

cd example
make node_modules
npm run android

After this step, I'm seeing this error:

> Task :berty-weshnet-expo:makeBuild FAILED
mkdir -p api/
buf export buf.build/berty/weshnet:c72d5759847b4dedb5411c19485e1a37 --output api/
No version is set for command buf
Consider adding one of the following versions in your config file at /home/danilo/dev/weshnet-expo/.tool-versions
buf 1.15.1
make: *** [Makefile:80: api/protocoltypes.proto] Error 126

After adding buf 1.15.1 in the .tool-versions, and running make asdf.install_plugins and make asdf.install_tools again, and re-running npm run android now I see this issue:

> Task :berty-weshnet-expo:makeBuild FAILED
> copying current '.tool-versions' in '' folder in order to make asdf works
> this hack is needed in order for gomobile (who is building from '') bind to use the correct javac and go version
'.tool-versions' -> '/.tool-versions'
cp: cannot create regular file '/.tool-versions': Permission denied
make: *** [Makefile:118: /.tool-versions] Error 1

In my case, the solution to this error was creating a /tmp directory and adding this in line 103 on the Makefile at the root of the project.

# main Makefile 
TMPDIR='./tmp'

with this little changes, now I'm able to build the code.
But as soon as I open the app on my phone, I see some errors, and the expo console says this:

Android Bundling complete 10326ms
 ERROR  init error [Error: CoreError]
 WARN  Possible Unhandled Promise Rejection (id: 0):
TypeError: Cannot read property 'serviceGetConfiguration' of undefined
TypeError: Cannot read property 'serviceGetConfiguration' of undefined
    at anonymous (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=expo.modules.weshnetexpo.example&modulesOnly=false&runModule=true:1159:39)
    at tryCallOne (/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/2q6r403w/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:53:16)
    at anonymous (/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/2q6r403w/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:139:27)
    at apply (native)
    at anonymous (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=expo.modules.weshnetexpo.example&modulesOnly=false&runModule=true:26302:26)
    at _callTimer (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=expo.modules.weshnetexpo.example&modulesOnly=false&runModule=true:26221:17)
    at _callReactNativeMicrotasksPass (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=expo.modules.weshnetexpo.example&modulesOnly=false&runModule=true:26251:17)
    at callReactNativeMicrotasks (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=expo.modules.weshnetexpo.example&modulesOnly=false&runModule=true:26414:44)
    at __callReactNativeMicrotasks (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=expo.modules.weshnetexpo.example&modulesOnly=false&runModule=true:4608:46)
    at anonymous (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=expo.modules.weshnetexpo.example&modulesOnly=false&runModule=true:4420:45)
    at __guard (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=expo.modules.weshnetexpo.example&modulesOnly=false&runModule=true:4592:15)
    at flushedQueue (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=expo.modules.weshnetexpo.example&modulesOnly=false&runModule=true:4419:21)

Trying to debug what is going on, I replaced this line in WeshnetExpoModule.kt

    @Throws(CodedException::class)
    private fun initializeCoreService(): Service {
        // Add logic to create and return your service instance
        // If an error occurs, throw WeshnetError2.kt
        try {
            return Core.newService()
        } catch (err: Exception) {
           // throw WeshnetCoreError(err)            commented this and added the following line:
           throw err
        }
    }

Now, in the console, I'm able to see this error:

 ERROR  init error [Error: Call to function 'WeshnetExpo.init' has been rejected.
→ Caused by: go.Universe$proxyerror: unable to start service: TODO(#666): failed to init ipfs node: constructing the node (see log for full detail): opening IPFS_PATH: exec: "getent": executable file not found in $PATH]
 WARN  Possible Unhandled Promise Rejection (id: 0):
TypeError: Cannot read property 'serviceGetConfiguration' of **undefined**

... same as before.

I don't know how to fix that issue. And I don't know if this is something on your side or a third party library you use.

I remember reading on the discord channel that your priorities have changed since the weshnet-expo project was created, and the last commit was 10 month ago, but I'd be glad to help in this project because I truly believe that this is the best way to expose the wesh protocol for react devs.

Let me know if you need help on testing this issue.
Thanks in advance!

@bluesliverx
Copy link

Hey, I'm not on the wesh/berty team but I've been playing around with this too. I actually have it somewhat working to the point where compiled go code can be used in an expo app. I'll push my changes up to a fork so you can see what I did (I hit a lot of the same things you did).

@bluesliverx
Copy link

bluesliverx commented Aug 6, 2024

@danilobassi8, here you go: https://github.com/bluesliverx/weshnet-expo

GitHub
🚧 [Work In Progress] 🚧 This library cannot be used yet!! - bluesliverx/weshnet-expo

I made these notes to myself as well in an app that is using it with this dependency in the package.json file:

    "@berty/weshnet-expo": "file:../weshnet-expo",

After making any changes to the code in weshnet-expo, run the following:

# In this repo
npm install
cd ../weshnet-expo
make all

After making changes to the native code in weshnet-expo, run the following:

#TODO Ensure that this is correct, the prebuild may not be needed?
# In this repo
npm install
cd ../weshnet-expo
make all
cd -
npx expo prebuild --clean

Finally, I should say after getting this working, I started playing around with the weshnet go code itself and found that the tutorial they provide does not work as is - the connect never happens. It must be something with my network setup or something, but I have yet to figure it out even when using go code directly.

@danilobassi8
Copy link
Author

@bluesliverx thanks for your comments. I tried your fork and I got this error when running npm run android:

Android Bundling failed 85ms
error: ../src/index.ts: /home/danilo/dev/weshnet-expo/src/index.ts: Export namespace should be first transformed by `@babel/plugin-transform-export-namespace-from`.
  11 |
  12 | // Export these types to be used in consuming apps
> 13 | export * as ProtocolTypes from './api/protocoltypes.pb';
     |        ^^^^^^^^^^^^^^^^^^
  14 | export * as Weshnet from './weshnet.types.gen';
  15 |
  16 | export async function init(): Promise<ProtocolServiceClient> {

If I checkout to your previous commit, I have the same error as the original repo.

@bluesliverx
Copy link

This is why I haven't pushed anything up 😅

Try removing those star imports for the types, it's likely not the right way to do it anyways

@AgustinBaffo
Copy link

I got stuck at the same point when trying to run it for Android. The execution deads in await WeshnetExpoModule.init() (in src/index.ts).

I'd like to add to this issue that when running adb logcat in a terminal I'm seeing:

08-09 00:08:46.733 12174 12266 I ReactNativeJS: Starting initialization...
08-09 00:08:46.733 12174 12266 I ReactNativeJS: Initializing WeshnetExpoModule...
08-09 00:08:46.741 12174 12290 E GoLog   : 2024-08-09T00:08:46.741Z	ERROR	core	core/builder.go:158	constructing the node: could not build arguments for function "github.com/ipfs/kubo/core/node".PeerWith.func1 (/home/baffo/.asdf/installs/golang/1.19.7/packages/pkg/mod/github.com/ipfs/kubo@v0.19.0/core/node/peering.go:29): failed to build *peering.PeeringService: could not build arguments for function "github.com/ipfs/kubo/core/node".Peering (/home/baffo/.asdf/installs/golang/1.19.7/packages/pkg/mod/github.com/ipfs/kubo@v0.19.0/core/node/peering.go:14): failed to build host.Host: could not build arguments for function "github.com/ipfs/kubo/core/node/libp2p".Host (/home/baffo/.asdf/installs/golang/1.19.7/packages/pkg/mod/github.com/ipfs/kubo@v0.19.0/core/node/libp2p/host.go:40): could not build value group []config.Option[group="libp2p"]: received non-nil error from function "github.com/ipfs/kubo/core/node/libp2p".ResourceManager.func1 (/home/baffo/.asdf/installs/golang/1.19.7/packages/pkg/mod/github.com/ipfs/kubo@v0.19.0/core/node/libp2p/rcmgr.go:31): o
08-09 00:08:46.741 12174 12290 E GoLog   : pening IPFS_PATH: exec: "getent": executable file not found in $PATH
08-09 00:08:46.745 12174 12266 E ReactNativeJS: 'Initialization error:', { [Error: CoreError] code: 'ERR_WESHNET_CORE_ERROR' }
08-09 00:08:46.761 12174 12266 E ReactNativeJS: 'WeshnetExpo.init() error:', { [Error: CoreError] code: 'ERR_WESHNET_CORE_ERROR' }

Note: the ..I ReactNativeJS.. are just some messages I added for debugging.

It seems that something is wrong in either IPFS_PATH or getent. Idk if it makes sense that you are trying to run getent on Android.

@jefft0 jefft0 added question Further information is requested bug Something isn't working and removed question Further information is requested labels Aug 9, 2024
@jefft0
Copy link
Collaborator

jefft0 commented Aug 9, 2024

@jefft0 to try to reproduce the error on an Ubuntu VM.

@costinberty
Copy link

costinberty commented Aug 9, 2024

Thank you for opening the issue 🙏 We confirm this is an important bug and we need to fix it.

To put things in perspective, we are currently focused on fixing the RDV server issues (which requires updating a lot of components, a laborious task). So, we could approximate Sept 2024 when we will attack this Expo Module bug.

We imagine it is frustrating to have so slow times of addressing important bugs, but we have limited resources and a few very important priorities in some tangent projects. However, we will improve Berty Messenger and more than that, have the Wesh Network protocol power more decentralized dApps. Stay tuned :)

@bluesliverx
Copy link

This is the same problem I'm hitting locally with pure go code I believe as well. Thanks everyone for looking into it

@jefft0
Copy link
Collaborator

jefft0 commented Aug 23, 2024

Hello @danilobassi8 . I am trying to reproduce your bug. I think you got farther than I did in the build process. I'm getting an error from gradle. So, what is your version of the Android SDK? If you installed Android Studio, what is its version? Thanks.

@jefft0 jefft0 added the more info needed Waiting for a response label Aug 23, 2024
@danilobassi8
Copy link
Author

danilobassi8 commented Aug 23, 2024

Hi @jefft0 , thanks for addressing this issue.
I'm using the latest Android Studio downloaded from the official page.

I'm using it with default settings, but I also tried other JDKs to check if it works, but it didn't.

@jefft0
Copy link
Collaborator

jefft0 commented Aug 29, 2024

Hello @danilobassi8 . I have reproduced your error Cannot read property 'serviceGetConfiguration' of undefined. Now that I can reproduce the error, I will get our expo devs to look at it, and the comments from @bluesliverx .

@jefft0 jefft0 added verified Bug is verified and removed more info needed Waiting for a response labels Aug 29, 2024
@D4ryl00
Copy link
Contributor

D4ryl00 commented Oct 8, 2024

ipfs/kubo#10492 fixes opening IPFS_PATH: exec: "getent": executable file not found in $PATH.
This fix will be released in kubo v0.31 (ipfs/kubo#10499).

I've opened a PR (#20) to start fixing this issue, and waiting that kubo v0.31 will be released.

@jefft0
Copy link
Collaborator

jefft0 commented Oct 18, 2024

@danilobassi8, with the latest fixes, I'm able to build on Ubuntu 22.04 and run the example on my Android phone. Do you want to try again?

@bluesliverx
Copy link

bluesliverx commented Oct 18, 2024

@D4ryl00 @jefft0 I'm seeing this in dev with a brand new project following the example code:

Android Bundling failed 1091ms node_modules/expo/AppEntry.js (649 modules)
Unable to resolve "./protocoltypes.pb" from "node_modules/@berty/weshnet-expo/build/api/index.js"

@jefft0
Copy link
Collaborator

jefft0 commented Oct 19, 2024

When I build, I use asdf as described in the original post. It uses the versions in this file.
https://github.com/berty/weshnet-expo/blob/main/.tool-versions
Are you using these versions?

GitHub
🚧 [Work In Progress] 🚧 This library cannot be used yet!! - berty/weshnet-expo

@bluesliverx
Copy link

@jefft0 that is a good call, I made sure to match those versions now with asdf. To be clear, I'm installing the weshnet-expo package into another project. I first tried it using the npm package published upstream, but that failed with the Unable to resolve "./protocoltypes.pb" message I showed above. I then cloned the latest version and tried it as a local dependency, but ran into the same issues. I had to once again make the Makefile changes [I mentioned above|https://github.com/berty/weshnet-expo/compare/main...bluesliverx:weshnet-expo:main#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52] and then was able to get much further.

I am now getting an error that it cannot read the property serviceGetConfiguration of undefined, which is generated using [the method documented in the readme|https://github.com/berty/weshnet-expo/blob/main/README.md?plain=1#L52].

On the other side, iOS is working great and I get a PeerID just fine, so it's just a problem with Android.

@jefft0
Copy link
Collaborator

jefft0 commented Oct 21, 2024

Thanks for the feedback. We confirm this issue and we're looking into it.

@jefft0 jefft0 reopened this Oct 21, 2024
@bluesliverx
Copy link

Thanks @jefft0. Here are some changes I made to get the dependent project further along (fixes the Unable to resolve "./protocoltypes.pb error): main...bluesliverx:weshnet-expo:main

@D4ryl00
Copy link
Contributor

D4ryl00 commented Oct 25, 2024

Hi @bluesliverx , #22 should fix your issue.
I successfully tested creating a new Expo project and then added weshnet-expo on Android and iOS.
Can you confirm me that is working to you too.
Thanks.

@jefft0 jefft0 added the more info needed Waiting for a response label Oct 25, 2024
@jefft0
Copy link
Collaborator

jefft0 commented Nov 15, 2024

No more comments from poster. Issue has been fixed in our tests. Closing as resolved.

@jefft0 jefft0 closed this as completed Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working more info needed Waiting for a response verified Bug is verified
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants