logo
0
0
WeChat Login
fix: 修复安卓端闪退问题,添加错误处理与重试机制

代理浏览器 (Proxy Browser)

项目结构

├── android/ # Flutter + Go 安卓端 │ ├── lib/ # Flutter Dart 代码 │ ├── go/ # Go Mobile 绑定代码 │ ├── android/ # Android 原生配置 │ └── pubspec.yaml ├── server/ # Go 服务器端 │ ├── main.go │ └── go.mod

安卓端 (android/)

基于 Flutter + Go Mobile 的网页浏览器应用。

功能

  • 网页浏览功能 (WebView)
  • 自动拦截 www.google.com 域名请求
  • 将 Host 改为 www.baidu.com,原始域名保存在 shost 请求头
  • 请求转发至代理服务器 192.168.68.124:8080

编译方法

  1. 安装 Flutter SDK 和 Android SDK
  2. 安装 Go 和 gomobile:
    go install golang.org/x/mobile/cmd/gomobile@latest gomobile init
  3. 编译 Go 库为 AAR:
    cd android/go gomobile bind -target=android -o ../android/app/libs/proxy.aar ./proxy
  4. 编译 Flutter APK:
    cd android flutter pub get flutter build apk --release
  5. 编译产物: android/build/app/outputs/flutter-apk/app-release.apk

服务器端 (server/)

Go 编写的反向代理服务器。

功能

  • 接收来自安卓客户端的请求
  • shost 请求头恢复原始域名
  • 转发请求到目标服务器并返回响应
  • 支持 HTTP 和 HTTPS (CONNECT 方法)

编译方法

# Linux amd64 cd server CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o proxy-server-linux-amd64 . # Windows amd64 CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o proxy-server-windows-amd64.exe .

运行方法

# 默认监听 8080 端口 ./proxy-server-linux-amd64 # 如需 HTTPS,修改 main.go 中的 certFile 和 keyFile

工作流程

  1. 用户在安卓浏览器中访问 www.google.com
  2. 安卓端拦截请求,将域名替换为 www.baidu.com
  3. 在请求头中添加 shost: www.google.com
  4. 将请求发送至代理服务器 192.168.68.124:8080
  5. 代理服务器从 shost 头读取原始域名
  6. 代理服务器恢复原始请求,向真实目标服务器发起请求
  7. 代理服务器将响应返回给安卓端
  8. 安卓端正常显示页面内容