main.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/exec"
  6. "path/filepath"
  7. _ "github.com/sagernet/gomobile/asset"
  8. "github.com/sagernet/sing-box/cmd/internal/build_shared"
  9. "github.com/sagernet/sing-box/log"
  10. "github.com/sagernet/sing/common/rw"
  11. )
  12. var debugEnabled bool
  13. func init() {
  14. flag.BoolVar(&debugEnabled, "debug", false, "enable debug")
  15. }
  16. func main() {
  17. build_shared.FindSDK()
  18. build_shared.FindMobile()
  19. args := []string{
  20. "bind",
  21. "-v",
  22. "-androidapi", "21",
  23. "-javapkg=io.nekohasekai",
  24. "-libname=box",
  25. }
  26. if !debugEnabled {
  27. args = append(args,
  28. "-trimpath", "-ldflags=-s -w -buildid=",
  29. "-tags", "with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api,debug",
  30. )
  31. } else {
  32. args = append(args, "-tags", "with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api")
  33. }
  34. args = append(args, "./experimental/libbox")
  35. command := exec.Command(build_shared.GoBinPath+"/gomobile", args...)
  36. command.Stdout = os.Stdout
  37. command.Stderr = os.Stderr
  38. err := command.Run()
  39. if err != nil {
  40. log.Fatal(err)
  41. }
  42. const name = "libbox.aar"
  43. copyPath := filepath.Join("..", "sing-box-for-android", "app", "libs")
  44. if rw.FileExists(copyPath) {
  45. copyPath, _ = filepath.Abs(copyPath)
  46. err = rw.CopyFile(name, filepath.Join(copyPath, name))
  47. if err != nil {
  48. log.Fatal(err)
  49. }
  50. log.Info("copied to ", copyPath)
  51. }
  52. }