TLDR: Full bitcoin and lightning node running on Android os, video example below!

Full Article

I admit it’s a bit of a click baity title but the purpose of this article is to demonstrate how it is possible for a user to run their own Bitcoin and Lightning Full Node on their consumer Android OS device such as their smart phone or smart TV.

I am a firm believer that if you aren't running your own full node then you aren't really using bitcoin, however I appreciate the obvious barrier to entry of running a full bitcoin node let alone a full lightning node. This has become much easier recently with the introduction of standalone full lightning node solutions such as the CASA NODE and NODL which I think are great products however would it not be even better if a user could install a full bitcoin and lightning node as simply as downloading and installing an app on their existing consumer entertainment device?

Actually the easiest way to do this is to use Lightning Labs Neutrino SPV solution with the LND lightning implementation, something like Zap, Pebble Wallet or Lightning Lab’s own mobile wallet will soon support this option in the app stores. The SPV solution is pretty straight forward and more light weight than a full node however the SPV approach also has some concerns regarding its effect on the health of the entire bitcoin network. For anybody interested in these concerns they are explained by Nicolas Dorier in his article here.

Moving on… in the article I will demonstrate how I created an Android app that runs a full bitcoind and LND node side by side, furthermore as this is all runnable on android it follows that given a bit of fancy UI and optimizations a user could simply download a fully sovereign lightning setup onto their Android TV or… hey… technically even their smart fridge? why not? it’s always on.

Next I will go into the weeds on the technical details, for those not interested please be kind enough to scroll to the bottom and check out the donation links, any little donation helps me justify to my wife why i’m spending the weekends tinkering for fun when I could be doing paid work or taking her out to fancy restaurants.

Components

The three main components used are stated below, the developers of these components did all the hard work I was just lucky enough to be able to bundle them all together so kudos to them.

ABCore

The foundational app used in this setup is ABCore developed by the Areen Address team, ABCore is an Android wrapper for bitcoind allowing bitcoind to be run on Android OS.

LND

The lightning implementation I chose to use along side ABCore is LND, the reason being is that LND is written in golang and golang has a very useful module called gomobile which lets you compile a golang app into an iOS or Android library.

gRPC

The LND api communicates using gRPC which is an RPC framework allowing a native Android Java app to communicate with the LND lncli.

Putting it all together

With the components in place I decided to download the sample ABCore app as a starting base.

https://github.com/greenaddress/abcore

After compiling it builds a simple app with a switch that will download the bitcoind binary and run it based on a config file you can adjust in the app settings. For this purpose I set this config to testnet and ran it on an android emulator as I don’t have an android device with more than 16GB of storage and 512MB of ram, however if it runs on an emulator it would work on a real device.

Luckily as ABCore is just a wrapper of bitcoind it means that LND should have no compatibility issues connecting to it, as the RPC server api would be the same as regular bitcoind. The next step was to build LND for android using gomobile and import it as a library into our project.

This was a lengthy process as the standard LND master branch cannot be easily built using gomobile due to its structure. After a lot of research I was able to create my own custom branch based off of the mobile support branch developed by halseth at Lightning Labs, the resulting branch is here and should not be used for production purposes. (Apparently Lightning Labs has a plan to release an update to the LND repository to make this process easier in the future!)

After building for Android gomobile produces an .aar file we can import into our android studio project.

Once we have LND imported as a module we need to be able to interface with it, this is where gRPC comes in which can be installed as a gradle dependency. Using the LND rpc.proto file will let gRPC generate an LND api java class we can use to make calls to our LND instance. This process is also somewhat cumbersome to setup at first but more info can be found in the relevant gRPC documentation for Android.

Finally we just need to set up the config files for LND and ABCore to let LND connect to our bitcoind backend. With ABCore it was pretty simple as it can be done directly inside the sample app provided by green address