V2ray-core: 我想编译 ios 的命令行版本,怎么着手

Created on 17 Jan 2018  ·  52Comments  ·  Source: v2ray/v2ray-core

我不是汇报问题,而是要问一下,目前 ios/tvOS 已经越狱,我想编译一个在后台自动运行的 v2ray ,目的有两个:

  1. 对于 ios 而言,可以越狱后自动启动,而且使用配置文件更灵活。
  2. 对于 AppleTV 来说,可以后台有代理,直接自身就能翻。

特别是对于后者是十分需要的(大多数只能路由器来解决)。大体上我是希望 v2ray-core 类似于 https://github.com/pobizhe/MobileShadowSocks 这个项目一样,可以不需要 UI,纯 CLI 即可。

Most helpful comment

翻了下之前编译的4.19.1
v2ray-ios-arm64-4.19.1.7z
这次没armv7(我记得拿vultr编译了,但不是fat程序,搞不懂了)
这个可以用quic,我当时为了用别人的编译的,后续好像暂时没什么新功能?

All 52 comments

你需要使用 gomobile 来编译,可能需要自己写一个 main 文件来适配 iOS,具体的不太清楚。

打扰一下(挖个坟)
想问一下弄出成品了吗,想弄一个服务搜到这个issue,有的话我就伸个手偷懒了,要是没有的话我也去研究下怎么编


自己最后研究了一晚上,一直尝试直接交叉编译一直失败,甚至手机上装了clang都没成功
结果最后找到了个神器 karalabe/xgo
我自己成品也就姑且放这了(armv7+arm64,已经ldid签名过)
v2ray.zip

@bao3 你后面编译成功了吗

同求 如果能像android一样提供官方编译包的话 应该可以推进ios客户端的发展

@duanhai @fax001
我这里有编译完成的成品,v2ctl和v2ray都弄完了,双cpu兼容 v2ray-ios-3.24.7z


19/02/24 更新iOS12可以运行的3.51
v2ray-ios-3.51.7z
(服务器炸了,上次编辑的3.51打包没了)

esterTion:/usr/local/bin/v2ray root# ./v2ray -version
runtime/cgo: no Info.plist URL
V2Ray 3.24 (die Commanderin) Custom
A unified platform for anti-censorship.

懒得弄deb包了,有这个需求的都自己会点基本ssh操作吧
有新版需求可以翻我上面那个用xgo编译

关于启动项,下面我扔一个plist,不过我这里放一个 警告:我上次直接扔在 /Library/LaunchDaemons 底下导致我两个小时一直尝试都进不去越狱系统,后来偶然才成功进入然后我就把启动项删了。现在是在cydia启动脚本/usr/libexec/cydia/startup后面追加launchctl load /Libary/com.v2ray.v2ray.plist。反正我这个经历放在这里,你们如果想试直接启动项也可以(也有可能是我首次参数有问题,后来改过几个)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>EnablePressuredExit</key>
    <false/>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>com.v2ray.v2ray</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/sh</string>
        <string>/usr/local/bin/v2ray/v2ray-daemon-wrapper</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/tmp/v2ray.log</string>
    <key>UserName</key>
    <string>mobile</string>
</dict>
</plist>

@esterTion 十分感谢

太感谢了,真的。如果有办法让 apple TV 也用上就好了,这样 tvOS 就在 wifi 里指定本地v2ray ,不必依赖路由了

发自我的 iPhone

在 2018年9月5日,下午6:01,luomo notifications@github.com 写道:

@esterTion 十分感谢


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@esterTion 我需要一个iOS的动态库Framework版本,你能帮忙编译一个吗,或者你把你的编译环境打包发我邮箱一下[email protected]

@bao3
xgo没看到tvos编译器,估计不行,我自己一直没成功只是直接用了xgo就成功了

@android0276
v2ray怎么编库,这不是cli单独程序吗。你研究下xgo

@esterTion 老哥,你用什么编译的啊,我用debain 跑xgo 编译跑不动,xgo 老是报错Failed to cross compile package: exit status 1. 请教下老哥用的什么环境编译的?方便给个邮箱交流下么?

我就是直接cent7跑的,顶多就是clone的时候得挂个代理

@esterTion 老哥,你的编译命令是在v2ray的目录下,执行xgo --targets=ios-9/* . 么,

xgo --targets=ios-7.0/* v2ray.com/core/main

高手,感谢

发自我的 iPhone

在 2019年2月28日,09:05,esterTion notifications@github.com 写道:

'xgo --targets=ios-7.0/* v2ray.com/core/main'


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

xgo --targets=ios-7.0/* v2ray.com/core/main
为什么我这样编译出来的frameWork 没有暴露出来头文件,,

高手,感谢 发自我的 iPhone

在 2019年2月28日,09:05,esterTion @.*> 写道: 'xgo --targets=ios-7.0/* v2ray.com/core/main' — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

xgo --targets=ios-7.0/* v2ray.com/core/main
为什么我这样编译出来的frameWork 没有暴露出来头文件,,

我通过这个命令得到了framwork 也有头文件,但是里面有这些东西,我赶紧有点问题,// skipped field Config.Inbound with unsupported type: []*v2ray.com/core.InboundHandlerConfig 有很多

gomobile bind -target=ios .

看来,编译蠢命令行的,还挺难。。。。

请赐教,我试过用Xgo 去编译,但是没有头文件,我用gomobile 去编译,得到的core.framwork ,有头文件,我去看了头文件,感觉有问题,里面很多 // skipped field Config.Inbound with unsupported type: []*v2ray.com/core.InboundHandlerConfig 这种东西,感觉是很多方法没编译出来,说不支持?
我是直接把这个Cloen下来,进入本地文件夹然后编译的

克隆v2ray-core项目,并把代码拖到mygo/src 目录下

cd 到当前项目目录 /Users/lanyao/mygo/src/v2ray-core
cd main

环境配置
lanyaodeMacBook-Pro:main lanyao$ go env
GOARCH="amd64"
GOBIN="/Users/lanyao/mygo/bin"
GOCACHE="/Users/lanyao/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/lanyao/mygo"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.9/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.9/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/hg/yqckrn1148qgrc3rb50539lw0000gn/T/go-build433880180=/tmp/go-build -gno-record-gcc-switches -fno-common"

编译信息:
lanyaodeMacBook-Pro:main lanyao$ xgo --targets=ios-9.0/* .
Checking docker installation...
Client: Docker Engine - Community
Version: 19.03.1
API version: 1.40
Go version: go1.12.5
Git commit: 74b1e89
Built: Thu Jul 25 21:18:17 2019
OS/Arch: darwin/amd64
Experimental: false

Server: Docker Engine - Community
Engine:
Version: 19.03.1
API version: 1.40 (minimum version 1.12)
Go version: go1.12.5
Git commit: 74b1e89
Built: Thu Jul 25 21:17:52 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.2.6
GitCommit: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
runc:
Version: 1.0.0-rc8
GitCommit: 425e105d5a03fabd737a126ad93d62a9eeede87f
docker-init:
Version: 0.18.0
GitCommit: fec3683

Checking for required docker image karalabe/xgo-latest... found.
Cross compiling v2ray-core/main...
Building locally v2ray-core/main...
Bootstrapping ios-9.0/arm-7...
Compiling for ios-9.0/arm-7...
go get: warning: modules disabled by GO111MODULE=auto in GOPATH/src;
ignoring ../go.mod;
see 'go help modules'
Cleaning up Go runtime for ios-9.0/arm-7...
Bootstrapping ios-9.0/arm64...
Compiling for ios-9.0/arm64...
go get: warning: modules disabled by GO111MODULE=auto in GOPATH/src;
ignoring ../go.mod;
see 'go help modules'
Cleaning up Go runtime for ios-9.0/arm64...
arm-apple-darwin11-ranlib: for architecture: armv7 file: /build/main-ios-9.0-framework/Main.framework/Versions/A/Main(000000.o) has no symbols
arm-apple-darwin11-ranlib: for architecture: armv7 file: /build/main-ios-9.0-framework/Main.framework/Versions/A/Main(000001.o) has no symbols
arm-apple-darwin11-ranlib: for architecture: armv7 file: /build/main-ios-9.0-framework/Main.framework/Versions/A/Main(000003.o) has no symbols
arm-apple-darwin11-ranlib: for architecture: armv7 file: /build/main-ios-9.0-framework/Main.framework/Versions/A/Main(000005.o) has no symbols
arm-apple-darwin11-ranlib: for architecture: armv7 file: /build/main-ios-9.0-framework/Main.framework/Versions/A/Main(000006.o) has no symbols
Cleaning up build environment...

得到Main. framework 还是没有 .h 文件

尝试删除go.mod文件,也是一样,得到的framework 没有 .h 文件

@bao3 老哥,指点下怎么编译iOS的蠢命令行啊

惭愧呀,我也是屡试不成。我觉得我要向 reddit 上的老外求助了。

@esterTion 老哥,我这个编译出来的怎么没.h文件,是我那里出问题了吗 xgo --targets=ios-7.0/* v2ray.com/core/main

没注意过,我编译出来只拿cli程序,不太清楚编库怎么搞

@esterTion 这个Cli能用在Xcode里用来开发不

下载 https://github.com/v2ray/v2ray-core 源码,放到自己的工作目录下
我的位置 /Users/lanyao/mygo/src/v2ray-core/
cd /Users/lanyao/mygo/src/v2ray-core/
命令:gomobile bind -target=ios .
得到core.framework 文件:部分头文件信息:

`// Objective-C API for talking to v2ray-core Go package.
// gobind -lang=objc v2ray-core
//
// File is generated by gobind. Do not edit.

ifndef __Core_H__

define __Core_H__

@import Foundation;

include "ref.h"

include "Universe.objc.h"

@class CoreAnnotation;
@class CoreConfig;
@class CoreConfigFormat;
@class CoreInboundHandlerConfig;
@class CoreInstance;
@class CoreOutboundHandlerConfig;
@protocol CoreServer;
@class CoreServer;

@protocol CoreServer

  • (BOOL)close:(NSError* _Nullable* _Nullable)error;
  • (BOOL)start:(NSError* _Nullable* _Nullable)error;
    @end

/**

  • Annotation is a concept in V2Ray. This struct is only for documentation. It is not used anywhere.
    Annotations begin with "v2ray:" in comment, as metadata of functions or types.
    */
    @interface CoreAnnotation : NSObject {
    }
    @property(strong, readonly) _Nonnull id _ref;
  • (nonnull instancetype)initWithRef:(_Nonnull id)ref;
  • (nonnull instancetype)init;
    /**

    • API is for types or functions that can be used in other libs. Possible values are:
  • v2ray:api:beta for types or functions that are ready for use, but maybe changed in the future.

  • v2ray:api:stable for types or functions with guarantee of backward compatibility.
  • v2ray:api:deprecated for types or functions that should not be used anymore.

Types or functions without api annotation should not be used externally.
/
@property (nonatomic) NSString
_Nonnull api;
@end

/**

  • Config is the master config of V2Ray. V2Ray takes this config as input and functions accordingly.
    */
    @interface CoreConfig : NSObject {
    }
    @property(strong, readonly) _Nonnull id _ref;
  • (nonnull instancetype)initWithRef:(_Nonnull id)ref;
  • (nonnull instancetype)init;
    // skipped field Config.Inbound with unsupported type: []*v2ray-core.InboundHandlerConfig

// skipped field Config.Outbound with unsupported type: []*v2ray-core.OutboundHandlerConfig

// skipped field Config.App with unsupported type: []*v2ray.com/core/common/serial.TypedMessage

// skipped field Config.Transport with unsupported type: *v2ray.com/core/transport.Config

// skipped field Config.Extension with unsupported type: []*v2ray.com/core/common/serial.TypedMessage

// skipped field Config.XXX_NoUnkeyedLiteral with unsupported type: struct{}`

很多 skipped 字样,好像是很多方法没编译出来

@esterTion 兄台,可以编译一个 tvOS 能用的吗?这个在 tvOS 是硬需求,方便 tvOS 用户自动翻墙,而不受限于路由器。

xgo里面没有tvos的编译器,大概是不行

@esterTion 感谢回应。能分享一下 ios 的 cli 给我吗?我用 jtool 改签成 tvOS 试试看。

不是签名的问题……电视好像是x86吧,手机都是arm64

@esterTion ATV 4 也是 ARM64 的。

@bao3 老哥 cli 是怎么用的 ,有全名没,我搜搜资料

翻了下之前编译的4.19.1
v2ray-ios-arm64-4.19.1.7z
这次没armv7(我记得拿vultr编译了,但不是fat程序,搞不懂了)
这个可以用quic,我当时为了用别人的编译的,后续好像暂时没什么新功能?

@esterTion 老哥 ,解压后的东西我怎么看不懂,iOS开发用不了啊,能不帮我编译一个iOS的framework ,有偿,可以吗

这个不是lib,我也不会
xgo好像会输出,但我只拿了程序
建议直接vultr之类的开个机子上去编译,编完打包下下来就可以删服务器了,墙内太烦

@qxc122 请问你那边编译成功了吗?我这么也是在做 v2ray 的 ios 客户端

@esterTion 我需要一个iOS的动态库Framework版本,你能帮忙编译一个吗,或者你把你的编译环境打包发我邮箱一下[email protected]

这个我编译好了

@esterTion 我需要一个iOS的动态库Framework版本,你能帮忙编译一个吗,或者你把你的编译环境打包发我邮箱一下[email protected]

这个我编译好了

大神可以发一份给小弟吗 ?[email protected]

@esterTion 我需要一个iOS的动态库Framework版本,你能帮忙编译一个吗,或者你把你的编译环境打包发我邮箱一下[email protected]

这个我编译好了

也可以發給我嗎? [email protected]
多謝

@esterTion 我需要一个iOS的动态库Framework版本,你能帮忙编译一个吗,或者你把你的编译环境打包发我邮箱一下[email protected]

这个我编译好了

能给我发一个么,大神。[email protected], 先谢谢了🙏

[email protected] need framework!

@esterTion 我需要一个iOS的动态库Framework版本,你能帮忙编译一个吗,或者你把你的编译环境打包发我邮箱一下[email protected]

这个我编译好了
[email protected] need framework!

@lil-hope @zhoujin960157994 @shenshouer 可以发我一份到邮箱吗[email protected]感谢

@lil-hope @zhoujin960157994 @shenshouer @wsqer [email protected] 如果可以的话,请发一份到我邮箱 万分感激

用gomobile编译出了一个Core.Framework,有头文件但是不知道该怎么配置了

@qxc122 请问你那边编译成功了吗?我这么也是在做 v2ray 的 ios 客户端

@yuanmomo 请问下你那边iOS上用V2ray core可以么

@esterTion 我需要一个iOS的动态库Framework版本,你能帮忙编译一个吗,或者你把你的编译环境打包发我邮箱一下[email protected]

这个我编译好了

你好,请问你编译好的framework能正常用么,我也编译出来一个core.framework,但是头文件里面很多// skipped field ....这样的注释,感觉很多字段和方法没有编译出来

@esterTion 我需要一个iOS的动态库Framework版本,你能帮忙编译一个吗,或者你把你的编译环境打包发我邮箱一下[email protected]

这个我编译好了

[email protected] 大神拜托了

@qxc122 请问你那边编译成功了吗?我这么也是在做 v2ray 的 ios 客户端

@yuanmomo 请问下你那边iOS上用V2ray core可以么

PacketTunnel进程有15M的内存限制瓶颈,我尝试过,gomolibe直接编译出的core.framework刷个网页就突破这个瓶颈了。感觉要从core这侧优化运行内存

Was this page helpful?
0 / 5 - 0 ratings