lnd/mobile
Andreas Schjønhaug 6dc7bda883 docs: Improvements to mobile instructions [skip ci]
Fixed PR feedback

Fixed name of xcode framwork file, and added section on dependency on Swift Protobuf in Xcode

Added link to https://api.lightning.community

Link to PR
2021-12-20 12:43:02 +01:00
..
bindings.go multi: extract wallet initialization 2021-10-08 12:13:15 +02:00
gen_bindings.sh docs+lnrpc: rename rpc.proto to lightning.proto 2021-07-27 12:59:56 +02:00
README.md docs: Improvements to mobile instructions [skip ci] 2021-12-20 12:43:02 +01:00
sample_lnd.conf mobile: add tlsdisableautofill to sample config 2021-04-21 12:55:46 +02:00

Building mobile libraries

Prerequisites

Docker

Make

  • Check that make is available by running the following command without errors:
⛰  make --version

Go mobile

Install gomobile and initialize it:

⛰  go install golang.org/x/mobile/cmd/gomobile@latest
⛰  gomobile init

Building the libraries

Note that gomobile only supports building projects from GOPATH at this point. So, before continuing, be sure to be in the src folder:

cd $GOPATH/src/github.com/lightningnetwork/lnd

To checkout the latest tagged release of lnd, run

⛰  git checkout $(git describe --tags --abbrev=0)

Building lnd for iOS

⛰  make ios

Building lnd for Android

⛰  make android

make mobile will build both iOS and Android libraries.

Libraries

After the build has succeeded, the libraries will be found in mobile/build/ios/Lndmobile.xcframework and mobile/build/android/Lndmobile.aar. Reference your platforms' SDK documentation for how to add the library to your project.

Generating proto definitions

In order to call the methods in the generated library, the serialized proto for the given RPC call must be provided. Similarly, the response will be a serialized proto.

iOS

In order to generate protobuf definitions for iOS, add --swift_out=. to the first protoc invocation found in gen_protos.sh .

Then, some changes to Dockerfile need to be done in order to use the Swift protobuf plugin with protoc:

  1. Replace the base image with FROM swift:focal so that Swift can be used.
  2. clang-format='1:7.0*' is unavailable in Ubuntu Focal. Change that to clang-format='1:10.0*.
  3. On the next line, install Go and set the environment variables by adding the following commands:
RUN apt-get install -y wget \
    && wget -c https://golang.org/dl/go1.17.3.linux-amd64.tar.gz -O - \
    | tar -xz -C /usr/local
ENV GOPATH=/go
ENV PATH=$PATH:/usr/local/go/bin:/go/bin
  1. At the end of the file, just above CMD, add the following RUN command. This will download and compile the latest tagged release of Swift protobuf.
RUN git clone https://github.com/apple/swift-protobuf.git \
&& cd swift-protobuf \ 
&& git checkout $(git describe --tags --abbrev=0) \
&& swift build -c release \
&& mv .build/release/protoc-gen-swift /bin

Finally, run make rpc.

Tip: The generated Swift files will be found in various folders. If youd like to move them to the same folder as the framework file, run

`find . -name "*.swift" -print0 | xargs -0 -I {} mv {} mobile/build/ios`.

Lndmobile.xcframework and all Swift files should now be added to your Xcode project. You will also need to add Swift Protobuf to your project to support the generated code.

Android

In order to generate protobuf definitions for Android, add --java_out=.

to the first protoc invocation found in gen_protos.sh . Then, run make rpc.

Options

Similar to lnd, subservers can be conditionally compiled with the build by setting the tags argument:

⛰  make ios

To support subservers that have APIs with name conflicts, pass the "prefix" flag. This will add the subserver name as a prefix to each method name:

⛰  make ios prefix=1

API docs

LND gRPC API Reference

TODO(halseth)