LondonX / clash_flt

Flutter Clash plugin
Other
41 stars 23 forks source link

iOS打包上传到AppConnect过程ClashKit.framework报错 #8

Closed netyouli closed 1 year ago

netyouli commented 1 year ago
image image

Asset validation failed Invalid bundle structure. The “Runner.app/PlugIns/PacketTunnel.appex/Frameworks/ClashKit.framework/ClashKit” binary file is not permitted. Your app cannot contain standalone executables or libraries, other than a valid CFBundleExecutable of supported bundles. For details, visit: https://developer.apple.com/documentation/bundleresources/placing_content_in_a_bundle (ID: 95da3fb9-af1c-45e2-8aed-e17e8effcab3)

Asset validation failed Invalid bundle structure. The “Runner.app/PlugIns/PacketTunnel.appex/Frameworks/ClashKit.framework/Versions/A/ClashKit” binary file is not permitted. Your app cannot contain standalone executables or libraries, other than a valid CFBundleExecutable of supported bundles. For details, visit: https://developer.apple.com/documentation/bundleresources/placing_content_in_a_bundle (ID: 28b8fe34-bb29-488c-b1b7-a31918675c1c)

Asset validation failed Invalid Bundle. The bundle at 'Runner.app/PlugIns/PacketTunnel.appex' contains disallowed nested bundles. (ID: 41a9786e-c5fd-4f88-9d08-8274219842d8)

Asset validation failed Invalid Bundle. The bundle at 'Runner.app/PlugIns/PacketTunnel.appex' contains disallowed file 'Frameworks'. (ID: b15ce666-d0bb-4c90-9b47-eda44f97cc03)

LondonX commented 1 year ago

Make sure that ClashKit.framework is not included under Copy Bundle Resources.

Ref: Your app can’t contain standalone executables or libraries, invalid-bundle-structure

netyouli commented 1 year ago
image image

没有添加到Copy Bundle Resources,我使用你这个clash_flt flutter项目打包上传也是报这个问题,可以编译成.a吗,我想问问gomobile怎么编译framework不带bitcode

LondonX commented 1 year ago

试试把ClashKit.xcframework放到PacketTunnel里去呢

LondonX commented 1 year ago

可以编译成.a吗?

gomobile怎么编译framework不带bitcode?

netyouli commented 1 year ago

这样操作下来还是有问题 需要修改ClashKit项目的clash/clash.go文件,将需要暴露的函数加上//export 函数名。 然后直接用go build编译ClashKit,应该会得到clashkit.a和clashkit.h两个文件。 export CFLAGS="-arch arm64 -miphoneos-version-min=9.0 -isysroot "$(xcrun -sdk iphoneos --show-sdk-path) export CGO_LDFLAGS="-arch arm64 -miphoneos-version-min=9.0 -isysroot "$(xcrun -sdk iphoneos --show-sdk-path) CGO_ENABLED=1 GOARCH=arm64 GOOS=darwin CC="clang $CFLAGS $CGO_LDFLAGS" go build -tags ios -ldflags=-w -trimpath -v -o "clashkit.a" 得到clashkit.a 没有h文件然后大小只有200kb,能加你联系方式吗,比如微信,qq,飞机,项目比较紧急,感谢了大佬

LondonX commented 1 year ago

帮你修改了一下clash.go,package改成了main,加了main函数,加了export。

package main

import "C"
import (
    "encoding/json"
    "time"

    "github.com/Dreamacro/clash/adapter"
    "github.com/Dreamacro/clash/adapter/outboundgroup"
    "github.com/Dreamacro/clash/config"
    "github.com/Dreamacro/clash/constant"
    "github.com/Dreamacro/clash/hub/executor"
    "github.com/Dreamacro/clash/log"
    "github.com/Dreamacro/clash/tunnel"
    "github.com/Dreamacro/clash/tunnel/statistic"
)

func main() {

}

type Client interface {
    Traffic(up, down int64)
    Log(level, message string)
}

var (
    base   *config.Config
    client Client
)

//export Setup
func Setup(homeDir, config string, c Client) {
    client = c
    go fetchLogs()
    go fetchTraffic()
    constant.SetHomeDir(homeDir)
    constant.SetConfig("")
    cfg, err := executor.ParseWithBytes(([]byte)(config))
    if err != nil {
        panic(err)
    }
    base = cfg
    executor.ApplyConfig(base, true)
}

//export GetConfigGeneral
func GetConfigGeneral() []byte {
    if base == nil {
        return nil
    }
    data, _ := json.Marshal(base.General)
    return data
}

//export PatchSelector
func PatchSelector(data []byte) bool {
    if base == nil {
        return false
    }
    mapping := make(map[string]string)
    err := json.Unmarshal(data, &mapping)
    if err != nil {
        return false
    }
    proxies := tunnel.Proxies()
    for name, proxy := range proxies {
        selected, exist := mapping[name]
        if !exist {
            continue
        }
        outbound, ok := proxy.(*adapter.Proxy)
        if !ok {
            continue
        }
        selector, ok := outbound.ProxyAdapter.(*outboundgroup.Selector)
        if !ok {
            continue
        }
        err := selector.Set(selected)
        if err == nil {
            return true
        }
    }
    return false
}

//export fetchLogs
func fetchLogs() {
    ch := make(chan log.Event, 1024)
    sub := log.Subscribe()
    defer log.UnSubscribe(sub)
    go func() {
        for elm := range sub {
            l := elm.(log.Event)
            select {
            case ch <- l:
            default:
            }
        }
        close(ch)
    }()
    for l := range ch {
        if l.LogLevel < log.Level() {
            continue
        }
        client.Log(l.Type(), l.Payload)
    }
}

//export fetchTraffic
func fetchTraffic() {
    tick := time.NewTicker(time.Second)
    defer tick.Stop()
    t := statistic.DefaultManager
    for range tick.C {
        up, down := t.Now()
        client.Traffic(up, down)
    }
}

编译命令也改了一下,加了-buildmode c-shared参数,输出改成了clashkit.dylib

export CFLAGS="-arch arm64 -miphoneos-version-min=9.0 -isysroot "$(xcrun -sdk iphoneos --show-sdk-path) 
export CGO_LDFLAGS="-arch arm64 -miphoneos-version-min=9.0 -isysroot "$(xcrun -sdk iphoneos --show-sdk-path)
CGO_ENABLED=1 GOARCH=arm64 GOOS=darwin CC="clang $CFLAGS $CGO_LDFLAGS" go build -tags ios -ldflags=-w -trimpath -v -buildmode c-shared -o clashkit.dylib

我试了一下可以编译dylib和h文件

$ ls
clash.go       clashkit.dylib clashkit.h

$ file clashkit.dylib
clashkit.dylib: Mach-O 64-bit dynamically linked shared library arm64
netyouli commented 1 year ago

非常感谢,已经可以了,但是现在有一个问题就是链接vpn ios端Telegram连不上不能用其他google,youtube都没问题,同一个节点其他平台mac,windows可以使用

LondonX commented 1 year ago

可以分享一下是怎么解决的吗,说不定会有其他人遇到同样的问题。

但是现在有一个问题就是链接vpn ios端Telegram连不上

这个问题我自己也在找方案,可能要用tun2socks把所有流量转发到clash的socks端口,就像目前Android这边一样。

netyouli commented 1 year ago

可以分享一下是怎么解决的吗,说不定会有其他人遇到同样的问题。

但是现在有一个问题就是链接vpn ios端Telegram连不上

这个问题我自己也在找方案,可能要用tun2socks把所有流量转发到clash的socks端口,就像目前Android这边一样。

image image image

ClashKit.xcframework 只在主工程里面引入就行