最近在安装Battery Historain时遇到不少问题,记录下来,方便以后查看
安装步骤:
一.安装go,因为Battery Historain是go语言开发的,所以需要先安装go
方法1:brew install go
方法2:下载安装包,直接安装
我开始用brew安装的,后来在启动的时候,报错:
cannot load github.com/google/battery-historian/bugreportutils/bugreportutils.go: no matching versions for query "latest"
参考了这篇文章:https://www.jianshu.com/p/5f6415bf25be,好像没有go.mod我就放弃了。
后来又直接clone,好像仍然有这个问题。后来就直接卸载了,从安装包安装,我的版本是1.14.2
二.go环境变量设置
我的设置如下:
GOROOT是go的安装路径
GOPATH是go的工程目录,需要自己创建一个文件夹
我这边的PATH添加了2个,一个是go语言的环境变量,一个是Battery Historain要求的
三.安装Battery Historain
go get -u github.com/golang/protobuf/proto
go get -u github.com/golang/protobuf/protoc-gen-go
go get -u github.com/google/battery-historian
(1)设置GOPROXY:
这几个需要翻墙下载,我这边是从国内镜像下载的,方法如下:
go env -w GO111MODULE=on
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
参考:https://www.sunzhongwei.com/problem-of-domestic-go-get-unable-to-download?from=sidebar_new
前2个很顺序的安装了,安装第三个的时候又报错了。
(2)could not read Username
fatal: could not read Username for 'https://github.com': terminal prompts disabled
package github.com/XXX/OOOO/: exit status 128
这里解决时参考了:https://www.jianshu.com/p/dc6b84a378f4
在环境变量里添加了GIT_TERMINAL_PROMPT=1,执行命令的时候手动输入git的用户名和密码。
(3)remote:Repository not found
看了上面的截图,才理解作者说库名称写错了,battery-historian写成了battery-histrizan😂。
而我以为是权限问题,还重新设置了git的SSH。
如此,白折腾了那么久,问题没有解决,还产生了一个新问题:Github does not provide shell acess
(4)Warning: Permanently added the RSA host key for IP address '13.229.188.59' to the list of known hosts.
这个是把13.229.188.59加到hosts去就行了
这之后我就选择直接去goworkspace/src/github.com/google/下面clone这个项目,文件夹不存在的手动新建。
git clone https://github.com/google/battery-historian.git
四.clone完成之后,运行:
cd battery-historian
go run setup.go
(1)working directory is not part of a module
用cd ..返回上层目录,就是goworkspace/src/github.com/google这一层,执行go mod init
参考链接:https://blog.csdn.net/fly910905/article/details/104299085的Go modules使用步骤
之后再两次执行go run setup.go
此时终于看到了胜利的曙光,然而高兴的还太早。
(2)这个Downloading了好久好久好久。。。突然报了中断
正克隆到 'closure-library'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (6/6), done.
packet_write_wait: Connection to 13.250.177.223 port 22: Broken pipe
fatal: 远端意外挂断了
fatal: 过早的文件结束符(EOF)
fatal: index-pack 失败
尝试了五六次吧,直接用码云去git拉了一个zip包下来,解压缩后放在了下面的目录下:/Users/weixiumin/goworkspace/src/github.com/google/battery-historian/third_party
再三次执行go run setup.go,又出现了最后一个问题,还有好多的waring,忽略
(3)full_test_cases.js:631: ERROR - Parse error. '(' expected
参考链接:https://blog.csdn.net/lx6101989/article/details/102483182
下载了2017年的包替换进去,最后一次执行go run setup.go,终于成功了。
五.go run cmd/battery-historian/battery-historian.go
六.Failed to get bugreportz version, which is only available on devices running Android 7.0 or later.
Trying a plain-text bug report instead.
说是adb版本太高,需要用低版本替换。
参考链接:https://www.jianshu.com/p/5c5dbe11f531
adb bugreport>bugreport.txt生成后的文件就在adb同一目录下。
在第五步的页面上传这个文件,需要翻墙