Tencent /mars

Mars is a cross-platform network component developed by WeChat.

★ 17,667⑂ 3,689👁 761⑃ 253● 1,125▤ 6
C++NOASSERTIONCreated 2016-12-12
Download: v1.3.0v1.3.0 ↓1.3.02019-04-01
+1
Daily
17,667
stars
3,689
forks
761
watchers
253
prs
1,125
issues
6
releases

README

Mars





![WeChat Approved-%20iOS%20%7C%20OS%20X%20%7C%20Android(ndkr20)%20%7C%20Windows(vs2015)%20-brightgreen.svg)](https://github.com/Tencent/mars/wiki)

(中文版本请参看这里)

Mars is a cross-platform infrastructure component developed by WeChat Mobile Team.
It has been proved to be effective by billions of WeChat users.

1. Cross platform, easy to deploy if you are developing multi-platform or multi-business application.
2. Suitable for small amount data transmission
3. Mobile platform friendly, low power and traffic consumption
4. A network solution fit for mobile application

!mars

 comm: common library, including socket, thread, message queue, coroutine, etc.
 Xlog: a reliable log component with high-performance.
 SDT: a network detection component.
 STN: a signaling network component, the major part of Mars.

 Samples

Start with sample usage here.

 Getting started

python scripts only support python3.10 or higher

Choose Android or iOS/OS X or Windows.

 Android

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.

 mars-wrapper

Add dependencies by adding the following lines to your app/build.gradle.

xml
dependencies {
    compile 'com.tencent.mars:mars-wrapper:1.2.5'
}


OR

 mars-core

Add dependencies by adding the following lines to your app/build.gradle.

xml
dependencies {
    compile 'com.tencent.mars:mars-core:1.2.5'
}

OR
 mars-xlog
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.

xml
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.

 Xlog Init

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.

java
System.loadLibrary("c++_shared");
System.loadLibrary("marsxlog");

final String SDCARD = Environment.getExternalStorageDirectory().getAbsolutePath();
final String logPath = SDCARD + "/marssample/log";

// this is necessary, or may crash for SIGBUS
final String cachePath = this.getFilesDir() + "/xlog"

//init xlog
Xlog xlog = new Xlog();
Log.setLogImp(xlog);

if (BuildConfig.DEBUG) {
    Log.setConsoleLogOpen(true);
  	Log.appenderOpen(Xlog.LEVEL_DEBUG, Xlog.AppednerModeAsync, "", logPath, logFileName, 0);
} else {
    Log.setConsoleLogOpen(false);
  	Log.appenderOpen(Xlog.LEVEL_INFO, Xlog.AppednerModeAsync, "", logPath, logFileName, 0);
}



Uninitialized Xlog when your app exits


java
Log.appenderClose();


 STN Init

If you add dependencies of mars-core to your project, you need to initialize and release STN.
Initialize 

Top issues

Latest release

v1.3.0 v1.3.0 2019-04-01
1. ndk 升级为 ndk-r16b 编译
2. 构建方案改为 cmake
3. stl 库从 stlport_shared 改为 c++_shared

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON