编译Telegram代码,群语音版本
Telegram github地址
github: https://github.com/DrKLO/Telegram.git
编译环境
Windows 64
Android studio 4.2
ndk版本:21.1.6352462
JDK1.8
准备工作
- 去telegram官网下载app,注意需要vpn才能连接到,app也同样需要vpn才可以使用。
- 使用手机号登录telegram app
- 打开https://my.telegram.org/,输入刚才在app内登录的账号如 +8618312345678,点击NEXT获取验证码,验证码会发到app内,
- 登录后打开 API development tools,填写app名称,和shortname,比如 testapp1,选择Android,最后点击 Create application 创建完成
开始编译
拉取代码
git clone https://github.com/DrKLO/Telegram.git
检出7.6.1
我们的项目目前使用到群语音版本 7.6.1,如果是连接的是telegram的服务,不需要做服务端的,如果想自己做服务端的接口,去参考官方的api标准,
我们的app服务端是自己做的,所以群语音也需要自己做,后面会出一个自己做的群语音服务的教程,基于mediasoup,以及官方的Demo讲解。
git checkout 7ba9838a
Android studio打开telegram项目
编辑Telegram\TMessagesProj\src\main\java\org\telegram\messenger\BuildVars.java
替换你在控制台创建的获取的 APP_ID 和 APP_HASH
下面是对应修改的代码
public class BuildVars {
public static boolean DEBUG_VERSION = BuildConfig.DEBUG;
public static boolean DEBUG_PRIVATE_VERSION = DEBUG_VERSION;
public static boolean LOGS_ENABLED = DEBUG_VERSION;
public static boolean USE_CLOUD_STRINGS = true;
public static boolean CHECK_UPDATES = true;
public static int BUILD_VERSION = BuildConfig.VERSION_CODE;
public static String BUILD_VERSION_STRING = BuildConfig.VERSION_NAME;
public static int APP_ID = 1;//你的api_id
public static String APP_HASH = "你的api_hash";
//由于要在谷歌商店,必须去掉所有APPCENTER相关的库,否则被拒
//public static String APPCENTER_HASH = "a5b5c4f5-51da-dedc-9918-d9766a22ca7c";
//public static String APPCENTER_HASH_DEBUG = "f9726602-67c9-48d2-b5d0-4761f1c1a8f3";
public static String SMS_HASH = DEBUG_VERSION ? "O2P2z+/jBpJ" : "oLeq9AcOZkT";
public static String PLAYSTORE_APP_URL = "https://play.google.com/store/apps/details?id=org.telegram.messenger";
static {
if (ApplicationLoader.applicationContext != null) {
SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("systemConfig", Context.MODE_PRIVATE);
LOGS_ENABLED = sharedPreferences.getBoolean("logsEnabled", DEBUG_VERSION);
}
}
}
去除一些代码
- AndroidManifest.xml中删除android:manageSpaceActivity=“org.telegram.ui.ExternalActionActivity”,防止想清除数据而没法进入系统清除的界面
- 全局搜索 protectionLevel=“signature” 并删除防止手机上装了telegram而权限冲突安装失败
<permission android:name="org.telegram.messenger.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
运行项目
到此项目应该会成功运行,运行完成即可登录到telegram正式服务器
如果想看tg的数据,打印log日志查看
- 添加依赖库
implementation 'org.apache.commons:commons-lang3:3.6'
- 创建RecursiveToStringStyle.java,将tg数据转为字符串并格式化
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.telegram.messenger.FileLog;
import java.util.Collection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RecursiveToStringStyle extends ToStringStyle {
private final int maxDepth;
private int depth;
private final String tabs;
public RecursiveToStringStyle(int maxDepth) {
this.maxDepth = maxDepth;
this.depth = 0;
tabs = StringUtils.repeat("\t", maxDepth);
setUseShortClassName(true);
setUseIdentityHashCode(false);
this.setArrayStart("");
this.setArrayEnd("");
this.setArraySeparator(", ");
this.setNullText("null");
this.setSummaryObjectStartText("\"<");
this.setSummaryObjectEndText(">\"");
setContentStart(" {");
setFieldSeparator(",\n");
setFieldSeparatorAtStart(true);
setFieldNameValueSeparator(": ");
setContentEnd("}");
}
public static String toString(Object value) {
if (value == null)
return "null";
final StringBuffer sb = new StringBuffer(512);
RecursiveToStringStyle ins = new RecursiveToStringStyle(13);
ins.appendDetail(sb, null, value);
return sb.toString();
}
private int getDepth() {
return Math.min(this.maxDepth, this.depth);
}
private void padDepth(StringBuffer buffer) {
buffer.append(tabs, 0, getDepth());
}
private StringBuffer appendTabified(StringBuffer buffer, String value) {
Matcher matcher = Pattern.compile("\n").matcher(value);
String replacement = "\n" + tabs.substring(0, getDepth());
while (matcher.find()) {
matcher.appendReplacement(buffer, replacement);
}
matcher.appendTail(buffer);
return buffer;
}
@Override
protected void appendFieldSeparator(StringBuffer buffer) {
buffer.append(getFieldSeparator());
padDepth(buffer);
}
@Override
public void appendStart(StringBuffer buffer, Object object) {
this.depth++;
// 开头特殊处理
boolean is_array = object != null && object.getClass().isArray();
if(object != null) {
if (is_array) {