Post

Telegram研究二:运行Telegram

Telegram研究二:运行Telegram

参考:
https://github.com/TelegramMessenger/Telegram-iOS/issues/849
https://github.com/TelegramMessenger/Telegram-iOS/issues/877
https://github.com/TelegramMessenger/Telegram-iOS
https://telegra.ph/tgiostests-01-07
https://www.doudianpu.com/telegram/ telegram-ioser-ci-kai-fa-zhi-nan-googlezhong-du-yi-lai-zhe-de-huan-jing-da-jian-yu-dai-ma-bian-yi/


2023.11.01更新

环境

Intel MacOS 14.0 Sonama / M1 MacOS 14.0 Sonama java version “18.0.1” Python 3.11.4 Xcode 15.0.1

下载项目及配置环境过程查看底部之前说明,配置好后执行如下命令生成项目

1
2
3
4
5
6
7
8
python3 build-system/Make/Make.py \
    --overrideXcodeVersion \
    --cacheDir="$HOME/telegram-bazel-cache" \
    generateProject \
    --configurationPath="$HOME/telegram-configuration/development-configuration.json"  \
    --codesigningInformationPath "$HOME/telegram-configuration/fake-codesigning" \
    --disableExtensions \
    --disableProvisioningProfiles

问题一、升级MacOS和Xcode后运行Telegram报如下错误

error: Could not parse Swift versions from: Swift/ErrorType.swift:200: Fatal error: Error raised at top level: Error Domain=NSCocoaErrorDomain Code=4 "The file “swiftc” doesn’t exist." UserInfo={NSFilePath=swiftc}

解决方案:拉取最新代码后重新生成,Telegram官方最新代码已经解决此问题

问题二、报证书过期,设置了忽略证书不生效

ERROR: /Users/macbookpro/Documents/third/telegram/Telegram-iOS/Telegram/BUILD:1955:16: ProcessEntitlementsFiles Telegram/Telegram_entitlements.entitlements failed: (Exit 1): plisttool failed: error executing command (from target //Telegram:Telegram) (cd /private/var/tmp/_bazel_macbookpro/c16a409a18375be2510dd63bad28d118/rules_xcodeproj.noindex/build_output_base/execroot/main &&
exec env -
APPLE_SDK_PLATFORM=iPhoneSimulator
APPLE_SDK_VERSION_OVERRIDE=17.0
XCODE_VERSION_OVERRIDE=15.0.1.15A507
` bazel-out/darwin-opt-exec-2B5CBBC6-ST-8c945a9593fc/bin/external/build_bazel_rules_apple/tools/plisttool/plisttool bazel-out/applebin_ios-ios_x86_64-dbg-ST-0c73515f5804/bin/Telegram/entitlements/Telegramplisttool-control)`

Configuration: 078c4bfe815fe328888eed3a62d860580dd34d0b8b7fffcfa3835ee84d3c101c

Execution platform: @local_config_platform//:host

ERROR: On target "@//Telegram:Telegram", provisioning profile ExpirationDate ("2023-10-27T19:16:43") is in the past. INFO: Elapsed time: 7.171s, Critical Path: 6.37s INFO: 204 processes: 165 internal, 39 local. FAILED: Build did NOT complete successfully error: The bazel build failed, please check the report navigator, which may have more context about the failure.`

解决方案 将相关对证书校验相关的脚本内容注释掉即可 1、搜索:provisioning profile ExpirationDate得到ENTITLEMENTS_PROFILE_HAS_EXPIRED 2、搜索:ENTITLEMENTS_PROFILE_HAS_EXPIRED得到调用这个地方,注释掉即可

1
2
3
# if expire and expire < datetime.datetime.now():
    #   raise PlistToolError(ENTITLEMENTS_PROFILE_HAS_EXPIRED % (
    #       self.target, expire.isoformat()))

去掉证书有效期校验

问题三、OSSpinLock报错

/Users/macbookpro/Documents/third/telegram/Telegram-iOS/submodules/AsyncDisplayKit/Source/PublicHeaders/AsyncDisplayKit/ASRecursiveUnfairLock.h:70:3: 'OSSpinLock' is deprecated: first deprecated in iOS 10.0 - Use os_unfair_lock() from <os/lock.h> instead [-Werror,-Wdeprecated-declarations]

解决方案: 将#define AS_USE_OS_LOCK false改成#define AS_USE_OS_LOCK true AS_USE_OS_LOCK

成功运行并使用Lookin查看UI

Lookin


环境

Intel MacOS 12.1 java version “18.0.1” Python 3.8.9 Xcode 13.4.1 master最新分支 release-9.0.2


1、clone源代码

1
git clone --recursive -j8 https://github.com/TelegramMessenger/Telegram-iOS.git

2.1、进入下载后的源代码,

1
cd Telegram-iOS

2.2 并创建配置参数

1
2
mkdir -p $HOME/telegram-configuration
cp -R build-system/example-configuration/* $HOME/telegram-configuration/

3、创建xcode项目

1
2
3
4
5
6
7
8
python3 build-system/Make/Make.py \
    --overrideXcodeVersion \
    --cacheDir="$HOME/telegram-bazel-cache" \
    generateProject \
    --configurationPath="$HOME/telegram-configuration/development-configuration.json"  \
    --codesigningInformationPath "$HOME/telegram-configuration/fake-codesigning" \
    --disableExtensions \
    --disableProvisioningProfiles

错误:Make generateProject: error: one of the arguments --gitCodesigningRepository --codesigningInformationPath is required

解决方式: 1、将xxx/Telegram-iOS/build-system/fake-codesigning 复制到 ~telegram-configuration/fake-codesigning 2、将 xxx/Telegram-iOS/build-system/appstore-configuration.json 复制到 ~/telegram-configuration/development-configuration.json

image.png

增加参数: --codesigningInformationPath "$HOME/telegram-configuration/fake-codesigning"

报xcode版本不匹配 Required Xcode version is 14.0, but 13.4.1 is reported by 'xcode-select -p' 解决方式:

xxxx/Telegram-iOS/versions.json中的xcode版本改为安装版本一致即可或者增加参数--overrideXcodeVersion 但是我本地报 Make: error: unrecognized arguments: --overrideXcodeVersion--overrideXcodeVersion放在命令的generatProject前面就可以解决

image.png

改完后重新执行创建xcode项目的命令,然后就可以正常的创建项目了

还遇到如下问题: Could not parse the Xcode version from /Library/Developer/CommandLineTools/../Info.plist

解决方案

1
2
sudo xcode-select --reset
sudo xcode-select --switch /Applications/Xcode.app

创建好项目后编译报错

1
2
3
4
5
6
7
8
9
10
11
Showing Recent Errors Only
/Users/aaa/Documents/workspace/Telegram-source/Telegram-iOS/Telegram/BUILD:1952:16: ProcessEntitlementsFiles Telegram/Telegram_entitlements.entitlements failed: (Exit 1): plisttool failed: error executing command

On target "//Telegram:Telegram", provisioning profile ExpirationDate ("2022-10-26T17:10:00") is in the past.

Build did NOT complete successfully

/Users/aaa/Documents/workspace/Telegram-source/Telegram-iOS/build-input/gen/project/Telegram.xcodeproj/.tulsi/Scripts/bazel_build.py:590: Bazel build failed with exit code 1. Please check the build log in Report Navigator (⌘9) for more information.


这是因为使用的证书都过期了,需要增加--disableProvisioningProfiles的参数

/Users/aaa/Documents/workspace/Telegram-source/Telegram-iOS/submodules/Media/LocalAudioTranscription/Sources/LocalAudioTranscription.swift:57:37: Value of type 'SFSpeechURLRecognitionRequest' has no member 'addsPunctuation'

image.png

原因是最新代码已经使用了iOS16的内容,xcode13不支持这个编译,暂时方式一:注释或使用kvo的方式解决 image.png


方式二:升级xcode到最新版本xcode14.0.1

image.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Showing Recent Errors Only
/Users/aaa/Documents/workspace/Telegram-source/Telegram-iOS/submodules/AsyncDisplayKit/BUILD:9:13: Compiling submodules/AsyncDisplayKit/Source/ASControlNode.mm failed: (Aborted): wrapped_clang_pp failed: error executing command

/Users/aaa/Documents/workspace/Telegram-source/Telegram-iOS/submodules/AsyncDisplayKit/Source/PublicHeaders/AsyncDisplayKit/ASRecursiveUnfairLock.h:70:3: 'OSSpinLock' is deprecated: first deprecated in iOS 10.0 - Use os_unfair_lock() from <os/lock.h> instead

/Users/aaa/Documents/workspace/Telegram-source/Telegram-iOS/submodules/AsyncDisplayKit/Source/PublicHeaders/AsyncDisplayKit/ASThread.h:282:5: 'OSSpinLock' is deprecated: first deprecated in iOS 10.0 - Use os_unfair_lock() from <os/lock.h> instead

/Users/aaa/Documents/workspace/Telegram-source/Telegram-iOS/submodules/AsyncDisplayKit/Source/PublicHeaders/AsyncDisplayKit/ASThread.h:153:21: 'OSSpinLockTry' is deprecated: first deprecated in iOS 10.0 - Use os_unfair_lock_trylock() from <os/lock.h> instead

/Users/aaa/Documents/workspace/Telegram-source/Telegram-iOS/submodules/AsyncDisplayKit/Source/PublicHeaders/AsyncDisplayKit/ASThread.h:178:11: 'OSSpinLockLock' is deprecated: first deprecated in iOS 10.0 - Use os_unfair_lock_lock() from <os/lock.h> instead

/Users/aaa/Documents/workspace/Telegram-source/Telegram-iOS/submodules/AsyncDisplayKit/Source/PublicHeaders/AsyncDisplayKit/ASThread.h:201:11: 'OSSpinLockUnlock' is deprecated: first deprecated in iOS 10.0 - Use os_unfair_lock_unlock() from <os/lock.h> instead

Build did NOT complete successfully

/Users/aaa/Documents/workspace/Telegram-source/Telegram-iOS/build-input/gen/project/Telegram.xcodeproj/.tulsi/Scripts/bazel_build.py:590: Bazel build failed with exit code 1. Please check the build log in Report Navigator (⌘9) for more information.

#define AS_USE_OS_LOCK false改成#define AS_USE_OS_LOCK true image.png


运行成功 image.png


2024.11.21更新

环境

M1 MacOS 15.0.1 Sequoia
java 20.0.1 2023-04-18
Python 3.10.8
Swift version 6.0
分支:master

问题一:Showing All Messages Unable to discover 'swiftc' command line tool info: Could not parse Swift versions from: 参考:Swift Command Line not working while Xcode works fine - repl_swift not found

1
2
sudo xcode-select -s /Applications/Xcode.app
xcrun swift

问题二: ERROR: On target "@//Telegram:Telegram", provisioning profile ExpirationDate ("2023-10-27T19:16:43") is in the past.

解决方案 将相关对证书校验相关的脚本内容注释掉即可 1、搜索:provisioning profile ExpirationDate得到ENTITLEMENTS_PROFILE_HAS_EXPIRED 2、搜索:ENTITLEMENTS_PROFILE_HAS_EXPIRED得到调用这个地方,注释掉即可 /xxx/xxx/Telegram-iOS/build-system/bazel-rules/rules_apple/tools/plisttool/plisttool.py

1
2
3
# if expire and expire < datetime.datetime.now():
    #   raise PlistToolError(/ % (
    #       self.target, expire.isoformat()))

去掉证书有效期校验

1
2
3
4
5
6
7
8
python3 build-system/Make/Make.py \
    --overrideXcodeVersion \
    --cacheDir="$HOME/telegram-bazel-cache" \
    generateProject \
    --configurationPath="$HOME/telegram-configuration/development-configuration.json"  \
    --codesigningInformationPath "$HOME/telegram-configuration/fake-codesigning" \
    --disableExtensions \
    --disableProvisioningProfiles

Showing Recent Issues FATAL: corrupt installation: file '/var/tmp/_bazel_macbookpro/install/3b6d3b89ac6edd12cb24971ba5ddc98f/A-server.jar' is missing or modified. Please remove '/var/tmp/_bazel_macbookpro/install/3b6d3b89ac6edd12b24971ba5ddc98f' and try again.

/private/var/tmp/_bazel_macbookpro/c16a409a18375be2510dd63bad28d118/rules_xcodeproj.noindex/build_output_base/execroot/__main__/submodules/ItemListUI/Sources/Items/ItemListEditableItem.swift:61:12 Main actor-isolated class 'ItemListRevealOptionsItemNode' has different actor isolation from nonisolated superclass 'ListViewItemNode'; this is an error in Swift 6

FileNotFoundError: [Errno 2] No such file or directory: '/Users/macbookpro/Documents/third/telegram/Telegram-iOS/build-input/bazel-7.3.1-darwin-x86_64' https://bazel.build/install/os-x?hl=zh-cn brew upgrade bazel

Call to main actor-isolated initializer 'init()' in a synchronous nonisolated context

Release-11.5.1 Xcode 15.4 MacOS 14 Intel


2025-01-25 芯片:Apple M4 Pro(mac mini) 系统: iOS 15.1 xcode: 16.2 telegram分支:master

1、先安装Java环境 brew install openjdk 2、安装bazel环境 brew install bazel 3、clean bazel clean –expunge 4、下载代码

1
git clone --recursive -j8 https://github.com/TelegramMessenger/Telegram-iOS.git

5、编译运行

1
2
3
4
5
6
7
8
python3 build-system/Make/Make.py \
    --overrideXcodeVersion \
    --cacheDir="$HOME/telegram-bazel-cache" \
    generateProject \
    --configurationPath="$HOME/telegram-configuration/development-configuration.json"  \
    --codesigningInformationPath "$HOME/telegram-configuration/fake-codesigning" \
    --disableExtensions \
    --disableProvisioningProfiles

过程中遇到过的问题

fetching local_repository rule //external:rules_xcodeproj: java.io.IOException: No MODULE.bazel, REPO.bazel, or WORKSPACE file found in /Telegram-iOS/build-system/bazel-rules/rules_xcodeproj

File “/xxx/xxx/Telegram-iOS/build-system/Make/BuildEnvironment.py”, line 106, in call_executable subprocess.check_call(resolved_arguments, env=resolved_env) File “/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/subprocess.py”, line 373, in check_call raise CalledProcessError(retcode, cmd)

解决方法: 按照从文档重新重github拉取全部代码 git clone --recursive -j8 https://github.com/TelegramMessenger/Telegram-iOS.git

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

解决方案: 将github的官网证书下载下来,然后将证书加入到信任里 sudo keytool -import -trustcacerts -alias github -file /xxx/xxx/xx/github.com.cer -keystore /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk/Contents/Home/lib/security/cacerts -storepass changeit


2025-02-24 芯片:Apple M4 Pro(mac mini) 系统:MacOS 15.3.1 xcode:Xcode 16.2 telegram分支:master

unlinkat (/private/var/tmp/_bazel_blue/1cef169aa54cbdb03ae508e6d924b40f/rules_xcodeproj.noindex/build_output_base/execroot) (Directory not empty)

1
2
3
PhaseScriptExecution Generate\ Bazel\ Dependendencies /Users/xxx/Library/Developer/Xcode/DerivedData/Telegram-ekdxowqkoroxakhboqezjfbjhfti/Build/Intermediates.noindex/Telegram.build/rules_xcodeproj/Script-FF0100000000000000000004.sh (in target 'BazelDependencies' from project 'Telegram')
    cd /var/tmp/_bazel_blue/1cef169aa54cbdb03ae508e6d924b40f/rules_xcodeproj.noindex/build_output_base/execroot/__main__
    /bin/sh -c /Users/xxx/Library/Developer/Xcode/DerivedData/Telegram-ekdxowqkoroxakhboqezjfbjhfti/Build/Intermediates.noindex/Telegram.build/rules_xcodeproj/Script-FF0100000000000000000004.sh
1
2
3
4
5
6
ERROR: /Users/xxx/xxx/Telegram-iOS/submodules/TgVoipWebrtc/BUILD:134:13: Compiling submodules/TgVoipWebrtc/tgcalls/tgcalls/v2/ikcp.cpp failed: missing input file '//submodules/TgVoipWebrtc:tgcalls/tgcalls/v2/ikcp.cpp'
ERROR: /Users/blue/Documents/studyIM/Telegram-iOS/submodules/TgVoipWebrtc/BUILD:134:13: Compiling submodules/TgVoipWebrtc/tgcalls/tgcalls/v2/ikcp.cpp failed: 1 input file(s) do not exist
ERROR: /Users/blue/Documents/studyIM/Telegram-iOS/submodules/TgVoipWebrtc/BUILD:134:13 Compiling submodules/TgVoipWebrtc/tgcalls/tgcalls/v2/ikcp.cpp failed: 1 input file(s) do not exist
INFO: Elapsed time: 7.110s, Critical Path: 6.25s
INFO: 4733 processes: 3239 disk cache hit, 1234 internal, 260 local.
ERROR: Build did NOT complete successfully

更新子项目

1
2
3
4
5
6
7
8
9
git submodule update --init --recursive
# 或者reset更新
git reset --hard HEAD
git clean -fdx
git pull
git submodule update --init --recursive

# 或者删除项目全部重新下载
git clone --recursive -j8 https://github.com/TelegramMessenger/Telegram-iOS.git
1
2
3
4
5
6
7
# 清除Bazel缓存
bazel clean --expunge
# 更新xcode选择
sudo xcode-select -s /Applications/Xcode.app
# 或如下
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

This post is licensed under CC BY 4.0 by the author.