【IPFS应用开发】ipfs安卓节点编译 ipfs andriod node

本系列文章是针对 https://blog.csdn.net/weixin_43668031/article/details/83962959 内容的实现所编写的。开发经历包括思考过程、重构和推翻重来。

【IPFS应用开发】ipfs安卓节点编译 ipfs andriod node

1.环境说明

项目代码:https://github.com/ipfs-shipyard/gomobile-ipfs
演示平台:Windows 10
Android Studio:3.6.2
wsl: ubuntu18
涉及到的语言和安装包:
wsl:
ubuntu18:
gcc make python3-pip openjdk-8-jdk
go:go1.14.1.linux-amd64.tar.gz
Android NDK:android-ndk-r21-linux-x86_64.zip
Android SDK:commandlinetools-linux-6200805_latest.zip
win10:
android-studio-ide-192.6308749-windows.exe
我准备了一个新的操作系统来做个ipfs andriod,之后肯定也要做go filecoin 或者 android filecoin。

2. 语言准备

apt install -y zip gcc make python3-pip
apt install -y openjdk-8-jdk

vim /etc/profile
添加

export GOPROXY=https://mirrors.aliyun.com/goproxy/
export PATH=$PATH:/usr/local/go/bin
export ANDROID_HOME=/root/android_sdk
export ANDROID_NDK_HOME=/root/android-ndk-r21

几个包比较大,可以用迅雷下载好放进去

wget ***/go1.14.1.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.14.1.linux-amd64.tar.gz
rm -rf go1.14.1.linux-amd64.tar.gz
wget ***/android-ndk-r21-linux-x86_64.zip
unzip android-ndk-r21-linux-x86_64.zip
rm -rf android-ndk-r21-linux-x86_64.zip
wget ***/commandlinetools-linux-6200805_latest.zip
unzip commandlinetools-linux-6200805_latest.zip
rm -rf commandlinetools-linux-6200805_latest.zip

sdk需要这个目录,需要这3层a/cmdline-tools/latest

mkdir -p android_sdk/cmdline-tools
mv tools android_sdk/cmdline-tools/latest
cd ~/android_sdk/cmdline-tools/latest/bin
./sdkmanager "platform-tools" "platforms;android-29" --no_https

3. 准备go语言依赖

mkdir -p ~/go/src/golang.org/x/
cd ~/go/src/golang.org/x/
git clone https://github.com/golang/mobile
git clone https://github.com/golang/tools
git clone https://github.com/golang/mod
git clone https://github.com/golang/xerrors

特别注意一下编译出来的gomobile 和 gobind 放到系统/bin/目录下

cd ~
go build golang.org/x/mobile/cmd/gomobile
mv gomobile /bin/
gomobile init
mv ~/go/bin/gobind /bin/

4.编译maven

mkdir -p ~/go/src/github.com/ipfs-shipyard/
cd ~/go/src/github.com/ipfs-shipyard/
git clone https://github.com/ipfs-shipyard/gomobile-ipfs
cd gomobile-ipfs/packages/
make

根据说明 运行 make build_core.android
在这里插入图片描述
中途遇到windows下的换行符\n\r 问题,修改好之后继续跑。
在这里插入图片描述
编译成果:

5. 编译APK

在Android Studio打开 android 文件夹,经过漫长的时间下载maven,终于插上手机点击编译。
在这里插入图片描述

6. 试用

在这里插入图片描述在这里插入图片描述在这里插入图片描述
再来看看其他对等节点有没有收到连接信息
在这里插入图片描述
这就完成了Android节点的建立,在手机上启动了独立节点。接下去就可以关注我应用层面的事情了。
当然 关于filecoin相关事情也会继续。包括从filecoin拉取文件到android上。

原创文章 29 获赞 21 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43668031/article/details/105397926