A new Flutter plugin based on ClashKit and my ClashKit is forked from AppleClash/clash-apple.
dependencies:
clash_flt:
git:
url: https://github.com/LondonX/clash_flt.git- Requires minSdkVersion 21
- Copy
ClashKit.aarinto<project-root>/android/app/. - Add
implementation files("ClashKit.aar")in<project-root>/android/app/build.gradle's dependencies section.
- Requires iOS 13 or newer.
- As
gomobilestop supporting armv7a, you need to exlude this architecture in XCode.
- Open
Runner.xcodeproj, selectRunnerinPROJECTlist on the left. - In
Build Settings->All->Architectures, set value toarm64.
- Modify
Runner.xcodeproj
- Open Runner's
Signing & Capabilitiestab. - You may need to enable
Network Extensionin Apple Developer Account page/Certificates, IDs & Profiles/Identifiers/YOUR_BUNDLE_ID/Edit/Network Extensions checkbox, before addNetwork Extensionand provision. - Add
Network ExtensionandPersonal VPN. - Check
App ProxyandPacket TunnelofNetwork Extension.
- Add project Target of
Network-Extension
- Create a Target named
PacketTunnel, the XCode will auto create a file namedPacketTunnelProvider.swift. - Open
PacketTunnel'sSigning & Capabilitiestab. - Add
Network ExtensionandPersonal VPN, just as step 3. - Add
ClashKit.xcframeworkintoPacketTunnel'sFrameworks and Librariesan selectDo Not Embed. - Modify
PacketTunnelProvider.swiftby paste from Example's PacketTunnelProvider.swfit
- Add app group
- Create a App Group named
group.<yourBundleId>both inRunnerandPacketTunnelTarget.
await ClashFlt.instance.init(clashHome);final bool isDownloaded = await ClashFlt.instance.downloadProfile(clashProfileUrl, isForce: true);
final File? downloadedFile = await ClashFlt.instance.profileFile.value;
final bool isResolved = await ClashFlt.instance.resolveProfile();
final Profile? resolvedProfile = await ClashFlt.instance.profile.value;final Profile? resolvedProfile = await ClashFlt.instance.profile.value;
final List<ProxyGroup>? groups = resolvedProfile?.proxyGroups;
final List<Proxy>? proxies = resolvedProfile?.proxies;
final List<String>? proxyNames = groups?.first.proxies;
// use ClashFlt.instance.findProxy to link proxy name with Proxy object.final ProxyGroup group;//assigned in somewhere else
final Proxy proxy;//assigned in somewhere else
if (!ClashFlt.instance.isProxySelectable(group, proxy)) return;
if(ClashFlt.instance.isProxySelected(group, proxy)) return;
ClashFlt.instance.selectProxy(group, proxy) return// start
final bool isStarted = await ClashFlt.instance.startClash();
// stop(no value return)
await ClashFlt.instance.stopClash();profileFile
profileDownloading
countryDBFile
countryDBDownloading
profile
profileResolving
healthChecking
state.isRunning
queryTrafficNow
queryTrafficTotal
applyConfig
isClashRunning
startClash
stopClash