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

build script for ipfs command line on Android ARM #9

Closed
n8fr8 opened this issue Jun 9, 2016 · 10 comments
Closed

build script for ipfs command line on Android ARM #9

n8fr8 opened this issue Jun 9, 2016 · 10 comments

Comments

@n8fr8
Copy link

n8fr8 commented Jun 9, 2016

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
Copy link

ghost commented Jun 9, 2016

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

@ligi
Copy link
Owner

ligi commented Jun 9, 2016

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: #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
Copy link
Author

n8fr8 commented Jun 9, 2016

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.

@ligi ligi closed this as completed Jun 22, 2016
@haiitch
Copy link

haiitch commented Mar 4, 2018

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
Copy link
Owner

ligi commented Mar 4, 2018

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

@haiitch
Copy link

haiitch commented Mar 11, 2018

@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
Copy link
Owner

ligi commented Mar 11, 2018

what was the error you got?

@haiitch
Copy link

haiitch commented Mar 12, 2018

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
Copy link
Owner

ligi commented Mar 12, 2018

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

@haiitch
Copy link

haiitch commented Mar 12, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants