ligi / IPFSDroid

Android App for the InterPlanetary File System(IPFS)
GNU General Public License v3.0
304 stars 73 forks source link

build script for ipfs command line on Android ARM #9

Closed n8fr8 closed 8 years ago

n8fr8 commented 8 years ago

This will produce an Android ARM command line ipfs binary that you can embed in an app and run via Runtime.exec()

You can install and execute binaries, as we do with the Orbot (Tor on Android) app: https://github.com/n8fr8/orbot/blob/master/src/org/torproject/android/service/TorResourceInstaller.java https://github.com/n8fr8/orbot/blob/master/src/org/torproject/android/service/TorService.java#L912


!/bin/sh

export NDK_TOOLCHAIN=/please/define/this/to/your/ndk

export CC=$NDK_TOOLCHAIN/bin/arm-linux-androideabi-gcc export GOOS=android export GOARCH=arm export GOARM=7 export CGO_ENABLED=1 GOGCCFLAGS="$GOGCCFLAGS -fPIE -pie"

go build -v --ldflags '-extldflags "-fPIE -pie" "-s"'


adb push ipfs /data/local/tmp adb shell IPFS_PATH=/data/local/tmp /data/local/tmp/ipfs init adb shell IPFS_PATH=/data/local/tmp /data/local/tmp/ipfs daemon &

ghost commented 8 years ago

I don't think you need the CC and GOGCCFLAGS vars. go-ipfs can't be built with GCC <= 5.

ligi commented 8 years ago

thanks for the input - unfortunately somehow I am not ending up with the ipfs binary after this approach:

ligi@ligi-520i7:~/git/3rd/go-ipfs$ export NDK_TOOLCHAIN=/home/ligi/bin/android-ndk/
ligi@ligi-520i7:~/git/3rd/go-ipfs$ export CC=$NDK_TOOLCHAIN/bin/arm-linux-androideabi-gcc
ligi@ligi-520i7:~/git/3rd/go-ipfs$ export GOOS=android
ligi@ligi-520i7:~/git/3rd/go-ipfs$ export GOARCH=arm
ligi@ligi-520i7:~/git/3rd/go-ipfs$ export GOARM=7
ligi@ligi-520i7:~/git/3rd/go-ipfs$ export CGO_ENABLED=1
ligi@ligi-520i7:~/git/3rd/go-ipfs$ GOGCCFLAGS="$GOGCCFLAGS -fPIE -pie"
ligi@ligi-520i7:~/git/3rd/go-ipfs$ go build -v --ldflags '-extldflags "-fPIE -pie" "-s"'
runtime/internal/sys
runtime/internal/atomic
runtime
_/home/ligi/git/3rd/go-ipfs
ligi@ligi-520i7:~/git/3rd/go-ipfs$ ls ipfs
ls: cannot access 'ipfs': No such file or directory

I already had a IPFS binary ( context: https://github.com/ligi/IPFSDroid/issues/4 ) - unfortunately It was freezing on some commands ( like init and pin ) - I am using gomobile currently - this works but has some other drawbacks. Would love to do it with a binary and Runtime.exec - but have not much experience with go to be fast figuring out problems like this. I live in the java/kotlin android world ;-)

Update: seems like I was in the wrong path - when being in the right one I get:

ligi@ligi-520i7:~/git/3rd/go-ipfs/cmd/ipfs$ go build -v --ldflags '-extldflags "-fPIE -pie" "-s"'
daemon.go:27:2: cannot find package "gx/ipfs/QmXJBB9U6e6ennAJPzk8E2rSaVGuHVR2jCxE9H9gPDtRrq/go-libp2p/p2p/net/conn" in any of:
    /usr/local/go/src/gx/ipfs/QmXJBB9U6e6ennAJPzk8E2rSaVGuHVR2jCxE9H9gPDtRrq/go-libp2p/p2p/net/conn (from $GOROOT)
    /home/ligi/go/src/gx/ipfs/QmXJBB9U6e6ennAJPzk8E2rSaVGuHVR2jCxE9H9gPDtRrq/go-libp2p/p2p/net/conn (from $GOPATH)
daemon.go:28:2: cannot find package "gx/ipfs/QmZ62t46e9p7vMYqCmptwQC1RhRv5cpQ5cwoqYspedaXyq/go-libp2p-peerstore" in any of:
    /usr/local/go/src/gx/ipfs/QmZ62t46e9p7vMYqCmptwQC1RhRv5cpQ5cwoqYspedaXyq/go-libp2p-peerstore (from $GOROOT)
    /home/ligi/go/src/gx/ipfs/QmZ62t46e9p7vMYqCmptwQC1RhRv5cpQ5cwoqYspedaXyq/go-libp2p-peerstore (from $GOPATH)
n8fr8 commented 8 years ago

I think you need to first do the standard "make install" for go-ipfs to get all the dependencies like gx. Once you can build the standard go for linux/amd64/x86, then clean that, and do the build with the script.

Sorry I didn't see #4 - good to see this effort was already underway. I use this same trick building our Tor Pluggable Transport libraries (meek and obfs4) so it definitely works at a production level.

Gomobile is the future, but it also requires a pretty big shift from standard Go code that I haven't quite got my head around either. I think we could create a Gomobile library, that imports the main go-ipfs libraries, and offers the ability to launch the daemons etc via an API. This will need to be done for iOS support.

haiitch commented 6 years ago

This method doesn't appear to be working anymore (as of 2018-03-04)

Software in use: go1.9.2 linux/amd64 ipfs version 0.4.14-dev

Since this issue was originally posted, has anybody else worked on a more streamlined ipfs build targetting android/arm? (using gomobile or otherwise)

I'd appreciate any pointers you can provide. Thank you

ligi commented 6 years ago

@htrob did you try what I posted in #28 ?

haiitch commented 6 years ago

@ligi Yes, I tried exactly that and it didn't work. At least it does not work in the exact way that was pasted. I don't know what I'm missing, it may possibly be a missing dependency or state your solution is assuming to be present, but I don't know what that is.

ligi commented 6 years ago

what was the error you got?

haiitch commented 6 years ago

Sorry I thought I had pasted this earlier.

$ mkdir /tmp/workspace
$ cd /tmp/workspace
$ export GOPATH=/tmp/workspace
$ export PATH=$GOPATH/bin:$PATH
$ go get -d github.com/ipfs/go-ipfs
$ cd $GOPATH/src/github.com/ipfs/go-ipfs
$ make toolkit_upgrade
**make: *** No rule to make target 'toolkit_upgrade'.  Stop.**

It seems that the IPFS Makefile has been changed?

ligi commented 6 years ago

hm - this is strange - still works here - so I do not think the IPFS Makefile has changed. What OS are you on?

haiitch commented 6 years ago

Ubuntu 16.04 LTS I've never had any issues building go-ipfs, using it every day. And your script clones the latest version anyway, right? The Makefile just doesn't have the specified "toolkit_upgrade" rule in it