Add xray init function for android

This commit is contained in:
albexk
2024-05-27 13:25:30 +03:00
parent 815742c221
commit 8cd26739de
2 changed files with 22 additions and 1 deletions

2
go.mod
View File

@@ -4,6 +4,7 @@ go 1.22.3
require (
github.com/amnezia-vpn/amnezia-xray-core v1.8.12
golang.org/x/mobile v0.0.0-20240520174638-fa72addaaa1b
google.golang.org/grpc v1.64.0
google.golang.org/protobuf v1.34.1
gopkg.in/yaml.v3 v3.0.1
@@ -41,7 +42,6 @@ require (
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/mobile v0.0.0-20240520174638-fa72addaaa1b // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect

21
xray_wrapper_android.go Normal file
View File

@@ -0,0 +1,21 @@
package libXray
import (
"io"
"os"
"path/filepath"
xrayfs "github.com/amnezia-vpn/amnezia-xray-core/common/platform/filesystem"
mobasset "golang.org/x/mobile/asset"
)
// Prepare Xray for android
func InitXray() {
xrayfs.NewFileReader = func(path string) (io.ReadCloser, error) {
if _, err := os.Stat(path); os.IsNotExist(err) {
_, file := filepath.Split(path)
return mobasset.Open(file)
}
return os.Open(path)
}
}