文章摘自:把 VS Code 带到安卓 - Code FA —— 梦魇兽
主要分为以下几个步骤:
- 启动 termux 环境
- 下载并安装完整 Linux(30m)
- 下载 code-server arm64(自带node能用了)
- 执行 bin/code-server 启动服务
启动 termux 环境
使用 termux-package 的编译脚本编译一个 bootstrap 集成到 apk,app 启动进行解压,然后根据符号链接格式进行恢复就行。
终端是 termare_view。
bootstrap 是一个带有最小依赖的类 linux 环境,有bash,apt 等。
function initApp(){cd ${RuntimeEnvir.usrPath}/echo 准备符号链接...for line in `cat SYMLINKS.txt`doOLD_IFS="\$IFS"IFS="←"arr=(\$line)IFS="\$OLD_IFS"ln -s \${arr[0]} \${arr[3]}donerm -rf SYMLINKS.txtTMPDIR=/data/data/com.nightmare.termare/files/usr/tmpfilename=bootstraprm -rf "\$TMPDIR/\$filename*"rm -rf "\$TMPDIR/*"chmod -R 0777 ${RuntimeEnvir.binPath}/*chmod -R 0777 ${RuntimeEnvir.usrPath}/lib/* 2>/dev/nullchmod -R 0777 ${RuntimeEnvir.usrPath}/libexec/* 2>/dev/nullapt updaterm -rf $lockFileexport LD_PRELOAD=${RuntimeEnvir.usrPath}/lib/libtermux-exec.soinstall_vs_codestart_vs_codebash
}
RuntimeEnvir.usrPath 是 /data/data/$package/files/usr/bin
安装完整 Linux 和 code-server
1.安装 ubuntu
install_ubuntu(){cd ~colorEcho - 安装Ubuntu Linuxunzip proot-distro.zip >/dev/null#cd ~/proot-distrobash ./install.shapt-get install -y prootproot-distro install ubuntuecho '$source' > $ubuntuPath/etc/apt/sources.list
}
2.安装 code-server
install_vs_code(){if [ ! -d "$ubuntuPath/home/code-server-$version-linux-arm64" ];thencd $ubuntuPath/homecolorEcho - 解压 Vs Code Arm64tar zxvf ~/code-server-$version-linux-arm64.tar.gz >/dev/nullcd code-server-$version-linux-arm64fi
}
启动 code-server
使用 proot-distro 启动
–termux-home 参数:开启 app 沙盒的 home 挂载到 ubuntu 的 /root 下,这样 ubuntu 就能用 app 里面的文件夹了
start_vs_code(){install_vs_codemkdir -p $ubuntuPath/root/.config/code-server 2>/dev/nullecho 'bind-addr: 0.0.0.0:8080auth: nonepassword: nonecert: false' > $ubuntuPath/root/.config/code-server/config.yamlecho -e "\x1b[31m- 启动中..\x1b[0m"proot-distro login ubuntu -- /home/code-server-$version-linux-arm64/bin/code-server
}