Mars 是微信开发的跨平台网络组件。
-%20iOS%20%7C%20OS%20X%20%7C%20Android(ndkr20)%20%7C%20Windows(vs2015)%20-brightgreen.svg)
(中文版本请参看这里)
Mars is a cross-platform infrastructure component developed by WeChat Mobile Team. It has been proved to be effective by billions of WeChat users.
Start with sample usage here.
python scripts only support python3.10 or higher
Choose Android or iOS/OS X or Windows.
You can use either mars-wrapper or mars-core. We recommend you to use mars-wrapper when you just want to build a sample or demo, while mars-core is preferred to be used in your APP.
Add dependencies by adding the following lines to your app/build.gradle.
dependencies {
compile 'com.tencent.mars:mars-wrapper:1.2.5'
}OR
Add dependencies by adding the following lines to your app/build.gradle.
dependencies {
compile 'com.tencent.mars:mars-core:1.2.5'
}OR
If you just want to user xlog, add dependencies by adding the following lines to your app/build.gradle. note: xlog is included in mars-core and mars-wrapper.
dependencies {
compile 'com.tencent.mars:mars-xlog:1.2.5'
}If you read here, make sure you have added dependencies of mars-wrapper, mars-core or mars-xlog.
Initialize Xlog when your APP starts. Remember to use an exclusive folder to save the log files, no other files are acceptable in the folder since they would be removed by the cleansing function in Xlog automatically.
When multiple processes is used in your app, make sure that each process owns its exclusive log file.
…Uninitialized Xlog when your app exits
Log.appenderClose();If you add dependencies of mars-core to your project, you need to initialize and release STN. Initialize STN before you use it
// set callback
AppLogic.setCallBack(stub);
StnLogic.setCallBack(stub);
SdtLogic.setCallBack(stub);
// Initialize the Mars PlatformComm
Mars.init(getApplicationContext(), new Handler(Looper.getMainLooper()));
// Initialize the Mars
StnLogic.setLonglinkSvrAddr(profile.longLinkHost(), profile.longLinkPorts());
StnLogic.setShortlinkSvrAddr(profile.shortLinkPort());
StnLogic.setClientVersion(profile.productID());
Mars.onCreate(true);
BaseEvent.onForeground(true);
StnLogic.makesureLongLinkConnected();Firstly, you should call the setCallBack interface, and secondly, the Mars.init. Then, to initialize the Mars, there is to need to strictly follow the orders of the four commands. Finally, after Mars are initialized, onForeground and makesureLongLinkConnect can be called.
Destroy STN or exit your app:
Mars.onDestroy();Network change:
BaseEvent.onNetworkChange()If you add dependencies of mars-wrapper to your project, you just need initialize STN and no need uninitialized.
MarsServiceProxy.init(this, getMainLooper(),null);No matter which way of dependencies you used, you must pay attention to these.
The state (background or foreground) of the APP is changed:
BaseEvent.onForeground(boolean);The account of the APP is changed:
StnLogic.reset();If you want to modify the encryption algorithm of Xlog, the packer/unpacker of longlink/shortlink, or you want to define the other components by yourself, refer here
Compile
python build_ios.pyor
python build_osx.pyInitialize Xlog when your app starts. Remember to use an exclusive folder to save the log files, no other files are acceptable in the folder since they would be removed by the cleansing function in Xlog automatically.
…Close xlog in function "applicationWillTerminate"
appender_close();Initialize STN before you use it:
…Firstly, you should call the setCallBack interface, and secondly, the Mars.init. Then, to initialize the Mars, there is to need to strictly follow the orders of the four commands. Finally, after Mars are initialized, onForeground and makesureLongLinkConnect can be called.
If you want to destroy STN or exit App:
- (void)destroyMars {
mars::baseevent::OnDestroy();
}When the App's state of background or foreground is changed:
- (void)reportEvent_OnForeground:(BOOL)isForeground {
mars::baseevent::OnForeground(isForeground);
}Network change:
- (void)reportEvent_OnNetworkChange {
mars::baseevent::OnNetworkChange();
}Install Visual Studio 2015.
Compile
python build_windows.pyInitialize Xlog when your app starts. Remember to use an exclusive folder to save the log files, no other files are acceptable in the folder since they would be removed by the cleansing function in Xlog automatically.
std::string logPath = ""; //use your log path
std::string pubKey = ""; //use you pubkey for log encrypt
// init xlog
#if DEBUG
xlogger_SetLevel(kLevelDebug);
appender_set_console_log(true);
#else
xlogger_SetLevel(kLevelInfo);
appender_set_console_log(false);
#endif
appender_open(kAppenderAsync, logPath.c_str(), "Test", 0, pubKey.c_str());Uninitialized xlog before your app exits
appender_close();Initialize STN before you use it:
…Firstly, you should call the setCalBack interface, and secondly, the Mars.init. Then, to initialize the Mars, there is to need to strictly follow the orders of the four commands. Finally, after Mars are initialized, onForeground and makesureLongLinkConnect can be called.
If you want to destroy STN or exit App:
mars::baseevent::OnDestroy();Any problem?
For more information about contributing issues or pull requests, see our Mars Contributing Guide.
Mars is under the MIT license. See the LICENSE file for details.
Mars 是微信官方的跨平台跨业务的终端基础组件。
sample 的使用请参考这里。
python >= 3,10 接入 Android 或者 iOS/OS X 或者 Windows 。
gradle 接入我们提供了两种接入方式:mars-wrapper 或者 mars-core。如果你只是想做个 sample 推荐使用 mars-wrapper,可以快速开发;但是如果你想把 mars 用到你的 app 中的话,推荐使用 mars-core,可定制性更高。
在 app/build.gradle 中添加 mars-wrapper 的依赖:
dependencies {
compile 'com.tencent.mars:mars-wrapper:1.2.5'
}或者
在 app/build.gradle 中添加 mars-core 的依赖:
dependencies {
compile 'com.tencent.mars:mars-core:1.2.5'
}或者
如果只想使用 xlog,可以只加 xlog 的依赖(mars-core,mars-wrapper 中都已经包括 xlog):
dependencies {
compile 'com.tencent.mars:mars-xlog:1.2.5'
}接着往下操作之前,请先确保你已经添加了 mars-wrapper 或者 mars-core 或者 mars-xlog 的依赖
在程序启动加载 Xlog 后紧接着初始化 Xlog。但要注意如果你的程序使用了多进程,不要把多个进程的日志输出到同一个文件中,保证每个进程独享一个日志文件。而且保存 log 的目录请使用单独的目录,不要存放任何其他文件防止被 xlog 自动清理功能误删。
…程序退出时关闭日志:
Log.appenderClose();如果你是把 mars-core 作为依赖加入到你的项目中的话,你需要显式的初始化和反初始化 STN
在使用 STN 之前进行初始化
// set callback
AppLogic.setCallBack(stub);
StnLogic.setCallBack(stub);
SdtLogic.setCallBack(stub);
// Initialize the Mars PlatformComm
Mars.init(getApplicationContext(), new Handler(Looper.getMainLooper()));
// Initialize the Mars
StnLogic.setLonglinkSvrAddr(profile.longLinkHost(), profile.longLinkPorts());
StnLogic.setShortlinkSvrAddr(profile.shortLinkPort());
StnLogic.setClientVersion(profile.productID());
Mars.onCreate(true);
BaseEvent.onForeground(true);
StnLogic.makesureLongLinkConnected();初始化顺序不一定要严格遵守上述代码的顺序,但在初始化时首先要调用 setCallBack 接口 (callback 文件的编写可以参考 demo),再调用 Mars.init,最后再调用 onForeground 和 makesureLongLinkConnect,中间顺序可以随意更改。注意:STN 默认是后台,所以初始化 STN 后需要主动调用一次BaseEvent.onForeground(true)
需要释放 STN 或者退出程序时:
Mars.onDestroy();网络切换时:
BaseEvent.onNetworkChange()如果你是把 mars-wrapper 作为依赖加入到你的项目中,你只需要显式的初始化 STN,不需要反初始化(因为 mars-wrapper 会进行反初始化)
MarsServiceProxy.init(this, getMainLooper(),null);不管你是使用 mars-wrapper 还是 mars-core,你都需要特别注意以下事件:
前后台切换:
BaseEvent.onForeground(boolean);应用的账号信息更改:
StnLogic.reset();如果你想修改 Xlog 的加密算法或者长短连的加解包部分甚至更改组件的其他部分,可以参考这里
编译
python build_ios.pyor
python build_osx.py把 mars.framework 作为依赖加入到你的项目中,把mars/libraries/mars_android_sdk/jni 目录的后缀名为 rewriteme 的文件名删掉".rewriteme"和头文件一起加入到你的项目中。
在程序启动加载 Xlog 后紧接着初始化 Xlog。但要注意保存 log 的目录请使用单独的目录,不要存放任何其他文件防止被 xlog 自动清理功能误删。
…在函数 "applicationWillTerminate" 中反初始化 Xlog
appender_close();在你用 STN 之前初始化:
…初始化顺序不一定要严格遵守上述代码的顺序,但在初始化时首先要调用 setCallBack 接口 (callback 文件的编写可以参考 demo),再调用 Mars.init,最后再调用 onForeground 和 makesureLongLinkConnect,中间顺序可以随意更改。注意:STN 默认是后台,所以初始化 STN 后需要主动调用一次```BaseEve
关于16KB适配的问题,结论是不需要适配!!!,arm64的so已经是16kb对齐的了。
地址:(175.25.33.77:8015), 套接字:149, 关闭连接错误:(49, 无法分配请求的地址), 本地 IP 地址:0.0.0.0, 地址类型:2
mars/openssl 版本文件显示为 1.0.2k 和 1.1.1c,但所有七个预构建二进制文件都是 OpenSSL 1.1.1l
xlog 16k pagesize设备崩溃
可用的 Android MarsXLog 演示
1.3.0 版本。引入失败,release 中下载的文件也无法解压。
Xlog 解密工具
Android 15 适配 16KB 页面大小, 不需要会员
适配Android 15的16K so文件
是否兼容openssl v3.5.4版本?