├── .gitignore
├── README.md
├── apks
└── log-rocket.apk
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── dream
│ │ └── logrocket
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── dream
│ │ │ └── logrocket
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── ic_launcher_background.xml
│ │ └── shape_grey.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.webp
│ │ ├── ic_launcher_round.webp
│ │ └── icon_logo.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── values-night
│ │ └── themes.xml
│ │ ├── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── themes.xml
│ │ └── xml
│ │ ├── backup_rules.xml
│ │ └── data_extraction_rules.xml
│ └── test
│ └── java
│ └── com
│ └── dream
│ └── logrocket
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── htmls
└── index.html
├── images
├── app_cut.jpg
├── icon_logo.png
└── index_info.png
├── log-rocket
├── .gitignore
├── README.MD
├── build.gradle
├── consumer-rules.pro
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── cn
│ │ └── net
│ │ └── yto
│ │ └── logrocket
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ └── java
│ │ └── cn
│ │ └── net
│ │ └── yto
│ │ └── logrocket
│ │ ├── LogRocket.java
│ │ ├── callback
│ │ └── UploadLogCallback.java
│ │ ├── impl
│ │ └── WebSocketServerImpl.java
│ │ ├── lifecycle
│ │ └── ActivityLifecycleCallbackImpl.java
│ │ ├── meta
│ │ └── MetaParseUtil.kt
│ │ ├── provider
│ │ ├── ContentProviderImpl.kt
│ │ └── LogRocketProvider.java
│ │ ├── refect
│ │ └── ReflectLogRocket.java
│ │ └── utils
│ │ ├── LogCatUtil.java
│ │ └── NetworkUtils.java
│ └── test
│ └── java
│ └── cn
│ └── net
│ └── yto
│ └── logrocket
│ └── ExampleUnitTest.kt
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 | .idea
17 | /.idea/*
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # LogRocket
2 |
3 |
4 |
5 | > 好久没发布jitpack了,失败了好几次,导致版本直接干到了v1.0.5,成功后又把之前的删除了,目前只保留了v1.0.1,上面这个图片不想删除,以后迭代上去了,就会保持同步了
6 |
7 | ### 版本
8 | - v1.0.1 「2024-12-06」
9 |
10 |
11 |

12 |
13 |
14 | ### 简介
15 | 当前开发者可在AS控制台查看日志,或者通过adb查看日志,对于开发大有帮助;发生异常也可通过日志上报到日志平台去查看,十分便捷;
16 |
17 | LogRocket换了一个角度,从测试者的角度出发;
18 |
19 | 开发者应该遇到过一些情况:
20 | - 接口数据不对,测试人员直接拿着手机找过来,说报错了,好一点的可能会自己会抓包查看网络接口;不好的就不说了。
21 | - 一些日志崩溃也是如此,测着测着,突然闪退,接了日志系统还好,还能去查看到底什么原因导致的,如果没接入,则需要测试人员反复的去猜测复现,十分不便;
22 | - 接口出了问题,后端找测试要参数,然后测试自己去抓包或者去找移动端开发;
23 | - ....
24 |
25 | > 真想给每个测试人员安装一个AS
26 |
27 | 整个就是基于这种小处境出发,解决测试人员查看日志的问题;
28 |
29 | LogRocket基于此出发,将终端设备作为Server,直接将logcat的日志通过ws直接发送出来,开发者可在日志中加入网络接口打印,以及一些日常打印,测试人员可直接访问对应的ws地址就可直接阅读网络请求以及崩溃日志。
30 |
31 | 可第一时间发现问题并保留日志信息及时反馈,减少中间流转时间,提升效率。
32 |
33 | ### 对代码的影响
34 | LogRocket建议仅仅在开发环境中使用,不建议上生产环境,以免引发不必要的错误;
35 |
36 | 为了实现这种解耦,于是将WebSocket得开启和关闭放在了Provider中,然后通过「debugImplementation」得方式进行依赖,这样在生产环境自动剔除,避免了对生产环境的干扰。
37 |
38 | 另外,终端既然作为Server端,那他就得提供一个ws地址,开发者可直接在wifi链接页面去查看自己手机的ip;通过LogRocket也提供了方法去获取对应终端的ip。
39 |
40 | 端口号是采用随机分配的空闲端口号,因为一个人可能会负责多个应用的开发,同一台设备,同一个网络下,不能同一个端口,故每次生成的ws链接端口号都不同。
41 |
42 | 这里LogRocket也提供的方法来获取整个ws的访问地址;
43 |
44 | 于是这里就会有一个问题,既然是采用「debugImplementation」得方式进行依赖,那肯定不能直接使用LogRocket的方法,不然在生产环境会因为没有依赖找不到对应的Class而报错,所以这里又提供了一个类,专门用于反射获取ws地址的。
45 |
46 | 对于知负责一个应用的开发者,如果会觉得每次更换端口显得很麻烦,想固定端口,这个也是提供了解决办法,可以在AndroidManifest.xml中配置;
47 | 在application节点中加入以下配置(默认值为false):
48 | ```xml
49 |
52 | ```
53 |
54 | 这里又有了一个问题,ws有了,难道还要找个ws测试网站去看日志?这个可以开发者自行实现,但是LogRocket也提供了一个默认h5页面,可以直接去查看,对应的文件为index.html。
55 |
56 | 这个index.html也是我去找ChatGpt生成的,还带了日志过滤,方便使用者过滤日志。如果您觉得UI不太好看,或者功能过于简陋,可以自行找ChatGpt去定制生成,或者让前端同学帮忙搞搞。
57 |
58 | 因为就只是临时起意的一个小工具,所以就不想去搭服务器放网页,所以直接把h5文件放到了github上,或者直接通过浏览器访问github上的这个index.html即可。
59 |
60 | [日志查看](https://htmlpreview.github.io/?https://github.com/xieyang94/LogRocket/blob/dev/htmls/index.html)
61 |
62 | 对于index.html,输入ws链接,回车即可;
63 |
64 | 
65 |
66 | ### 注意点
67 | 需要保持ws的Server和Client在同一网络
68 |
69 | ### 接入使用方式
70 |
71 | #### 仓库引入
72 | ```gradle
73 | repositories {
74 | maven { url = uri("https://jitpack.io") }
75 | google()
76 | mavenCentral()
77 | }
78 | ```
79 | #### 依赖引入
80 | ```gradle
81 | debugImplementation 'com.logrocket:logrocket:lastVersion'
82 | ```
83 | #### 固定端口配置
84 | 默认非固定端口(false)
85 | ```xml
86 |
89 | ```
90 |
91 | ### 反射获取ws链接
92 | ```java
93 | class Test {
94 |
95 | public String getWsAddress(Context context) {
96 | String result = null; // 默认值,如果反射调用失败则返回此值
97 | try {
98 | // 获取MetaUtil类的Class对象
99 | Class> metaUtilClass = Class.forName("cn.net.yto.logrocket.refect.ReflectLogRocket");
100 | // 获取getPort方法的Method对象
101 | Method getPortMethod = metaUtilClass.getMethod("wdAddress", Context.class);
102 | // 调用getPort方法
103 | // 注意:如果getPort是非公开方法,可能需要设置accessible为true
104 | getPortMethod.setAccessible(true);
105 | // 创建MetaUtil类的实例
106 | Object metaUtilInstance = metaUtilClass.newInstance();
107 | // 调用invoke方法执行getPort(context)
108 | result = (String) getPortMethod.invoke(metaUtilInstance, context);
109 | } catch (Exception e) {
110 | e.printStackTrace();
111 | }
112 | return result;
113 | }
114 | }
115 | ```
116 | 被反射的类:
117 | ```java
118 | public class ReflectLogRocket {
119 |
120 | /**
121 | * 反射获取ws地址
122 | *
123 | * @param context
124 | * @return
125 | */
126 | public String wdAddress(Context context) {
127 | return LogRocket.getInstance().getWsAddress(context);
128 | }
129 | }
130 | ```
131 | 您也可以不采用这种用法,可以直接把代码拷贝到您的项目中,然后直接调用。
132 |
133 | ### Demo
134 | Demo样式
135 | 
136 |
137 | > 可下载apks目录下的apk体验下,在github上的index.html进行ws的访问好像存在点问题,后面有时间在处理,可以把htmls下的index.html下载下来本地打开使用
138 |
139 | ### 其他
140 |
141 | 有问题可以反馈,我会尽最大的努力解决或采纳。
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
--------------------------------------------------------------------------------
/apks/log-rocket.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/apks/log-rocket.apk
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | }
4 |
5 | android {
6 | compileSdkVersion 34
7 |
8 | defaultConfig {
9 | applicationId "com.dream.logrocket"
10 | minSdkVersion 17
11 | targetSdkVersion 34
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | compileOptions {
25 | sourceCompatibility JavaVersion.VERSION_1_8
26 | targetCompatibility JavaVersion.VERSION_1_8
27 | }
28 | }
29 |
30 | dependencies {
31 |
32 | implementation 'androidx.core:core-ktx:1.6.0'
33 | implementation 'androidx.appcompat:appcompat:1.3.0'
34 | implementation 'com.google.android.material:material:1.4.0'
35 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
36 | testImplementation 'junit:junit:4.13.2'
37 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
38 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
39 |
40 | implementation 'androidx.core:core-ktx:1.3.2'
41 | implementation 'androidx.activity:activity-ktx:1.3.0'
42 | implementation 'androidx.fragment:fragment-ktx:1.3.6'
43 |
44 |
45 | //debugImplementation project(path: ':log-rocket')
46 | debugImplementation 'com.github.xieyang94.LogRocket:log-rocket:v1.0.1'
47 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/dream/logrocket/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.dream.logrocket;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 | assertEquals("com.dream.logrocket", appContext.getPackageName());
25 | }
26 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dream/logrocket/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.dream.logrocket;
2 |
3 | import android.content.ClipData;
4 | import android.content.ClipboardManager;
5 | import android.content.Context;
6 | import android.os.Bundle;
7 | import android.util.Log;
8 | import android.view.View;
9 | import android.widget.Button;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 |
13 | import androidx.appcompat.app.AppCompatActivity;
14 | import androidx.core.widget.NestedScrollView;
15 |
16 | import java.io.BufferedReader;
17 | import java.io.IOException;
18 | import java.io.InputStreamReader;
19 | import java.lang.reflect.Method;
20 | import java.text.SimpleDateFormat;
21 | import java.util.Date;
22 | import java.util.concurrent.CopyOnWriteArrayList;
23 | import java.util.concurrent.ExecutorService;
24 | import java.util.concurrent.Executors;
25 | import java.util.concurrent.atomic.AtomicBoolean;
26 |
27 | public class MainActivity extends AppCompatActivity {
28 |
29 | private static final String TAG = "MainActivity";
30 | private NestedScrollView scrollView;
31 | private TextView mTvWsAddress;
32 | private TextView tv_log;
33 | private Button mBtnConnect;
34 | private Button mBtnDisconnect;
35 | private Button mBtnTestStart;
36 | private Button mBtnTestStop;
37 |
38 | private ExecutorService executorService;
39 | private final AtomicBoolean interrupt = new AtomicBoolean(false);
40 |
41 | @Override
42 | protected void onCreate(Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 | setContentView(R.layout.activity_main);
45 |
46 | initView();
47 | initListener();
48 |
49 | String wsAddress = getWsAddress(this);
50 | if (wsAddress != null) {
51 | mTvWsAddress.setText(wsAddress);
52 | }
53 | }
54 |
55 | private void initView() {
56 | scrollView = (NestedScrollView) findViewById(R.id.scrollView);
57 | mTvWsAddress = (TextView) findViewById(R.id.tv_ws_address);
58 | tv_log = (TextView) findViewById(R.id.tv_log);
59 | mBtnConnect = (Button) findViewById(R.id.btn_connect);
60 | mBtnDisconnect = (Button) findViewById(R.id.btn_disconnect);
61 | mBtnTestStart = (Button) findViewById(R.id.btn_test_start);
62 | mBtnTestStop = (Button) findViewById(R.id.btn_test_stop);
63 |
64 | executorService = Executors.newCachedThreadPool();
65 |
66 | executorService.execute(() -> {
67 | CopyOnWriteArrayList contentList = new CopyOnWriteArrayList<>();
68 | uploadLog(new Callback() {
69 | @Override
70 | public void upload(String log) {
71 | if (contentList.size() > 30) {
72 | contentList.remove(0);
73 | }
74 | contentList.add(log);
75 | String contentStr = "";
76 | for (String content : contentList) {
77 | contentStr += content + "\n";
78 | }
79 | String finalContentStr = contentStr;
80 | runOnUiThread(() -> {
81 | tv_log.setText(finalContentStr);
82 | scrollView.fullScroll(View.FOCUS_DOWN);
83 | });
84 | }
85 | });
86 | });
87 |
88 | }
89 |
90 | public String getWsAddress(Context context) {
91 | String result = null; // 默认值,如果反射调用失败则返回此值
92 | try {
93 | // 获取MetaUtil类的Class对象
94 | Class> metaUtilClass = Class.forName("cn.net.yto.logrocket.refect.ReflectLogRocket");
95 | // 获取getPort方法的Method对象
96 | Method getPortMethod = metaUtilClass.getMethod("wdAddress", Context.class);
97 | // 调用getPort方法
98 | // 注意:如果getPort是非公开方法,可能需要设置accessible为true
99 | getPortMethod.setAccessible(true);
100 | // 创建MetaUtil类的实例
101 | Object metaUtilInstance = metaUtilClass.newInstance();
102 | // 调用invoke方法执行getPort(context)
103 | result = (String) getPortMethod.invoke(metaUtilInstance, context);
104 | } catch (Exception e) {
105 | e.printStackTrace();
106 | }
107 | return result;
108 | }
109 |
110 | private void copyText(TextView view) {
111 | // 创建一个剪贴板管理器
112 | ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
113 | // 创建一个剪贴数据集
114 | ClipData clip = ClipData.newPlainText("label", view.getText());
115 | // 将剪贴数据集放到剪贴板
116 | clipboard.setPrimaryClip(clip);
117 | // 显示一个短暂的提示,表明复制成功
118 | Toast.makeText(getApplicationContext(), "已复制到剪贴板", Toast.LENGTH_SHORT).show();
119 | }
120 |
121 | private void initListener() {
122 | mTvWsAddress.setOnClickListener(new View.OnClickListener() {
123 | @Override
124 | public void onClick(View v) {
125 | copyText(mTvWsAddress);
126 | }
127 | });
128 | mBtnTestStart.setOnClickListener(v -> {
129 | testLog();
130 | });
131 | mBtnTestStop.setOnClickListener(v -> {
132 | interrupt.set(false);
133 | });
134 | }
135 |
136 | private void testLog() {
137 | interrupt.set(true);
138 | executorService.execute(() -> {
139 | try {
140 | while (interrupt.get()) {
141 | try {
142 | Thread.sleep(1000);
143 | Log.e("ccer", currentTime() + "----请注意,这里是测试日志,产生频率为1秒钟一条");
144 | } catch (Exception e) {
145 | e.printStackTrace();
146 | }
147 | }
148 | } catch (Exception e) {
149 | e.printStackTrace();
150 | }
151 | });
152 | }
153 |
154 | public void uploadLog(Callback callback) {
155 | try {
156 | // 执行logcat命令
157 | Process process = Runtime.getRuntime().exec("logcat");
158 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
159 | String line = "";
160 | while ((line = bufferedReader.readLine()) != null) {
161 | if (callback != null) {
162 | callback.upload(line);
163 | }
164 | }
165 | // 关闭流
166 | bufferedReader.close();
167 | } catch (IOException e) {
168 | e.printStackTrace();
169 | }
170 | }
171 |
172 | interface Callback {
173 | void upload(String log);
174 | }
175 |
176 | private String currentTime() {
177 | try {
178 | // 创建一个Date对象,它将包含当前日期和时间
179 | Date now = new Date();
180 | // 创建一个SimpleDateFormat对象,用于指定输出格式
181 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
182 | // 使用format方法将Date对象格式化为字符串
183 | String currentDateTime = dateFormat.format(now);
184 | return currentDateTime;
185 | } catch (Exception e) {
186 | e.printStackTrace();
187 | }
188 | return System.currentTimeMillis() + "";
189 | }
190 |
191 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_grey.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
26 |
27 |
40 |
41 |
47 |
48 |
55 |
56 |
63 |
64 |
65 |
66 |
71 |
72 |
79 |
80 |
87 |
88 |
89 |
90 |
96 |
97 |
103 |
104 |
110 |
111 |
118 |
119 |
120 |
121 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/icon_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/app/src/main/res/mipmap-xxhdpi/icon_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FF000000
4 | #FFFFFFFF
5 | #FFBB86FC
6 | #FF6200EE
7 | #FF3700B3
8 | #FF03DAC5
9 | #FF018786
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | LogRocket
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/app/src/test/java/com/dream/logrocket/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.dream.logrocket;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = "1.6.21"
3 | repositories {
4 | maven { url = uri("https://jitpack.io") }
5 | maven { url 'https://maven.aliyun.com/repository/public' }
6 | maven { url 'https://maven.aliyun.com/repository/google' }
7 | maven {
8 | allowInsecureProtocol = true
9 | url 'http://mvn.cloud.alipay.com/nexus/content/repositories/releases/'
10 | name 'alipay'
11 | credentials {
12 | username 'mvn_read_ws'
13 | password 'mrk8929'
14 | }
15 | }
16 | google()
17 | mavenCentral()
18 | }
19 |
20 | dependencies {
21 | classpath 'com.android.tools.build:gradle:4.1.3'
22 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
23 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
24 | }
25 | }
26 |
27 | allprojects {
28 | repositories {
29 | maven { url = uri("https://jitpack.io") }
30 | maven { url 'https://maven.aliyun.com/repository/public' }
31 | maven { url 'https://maven.aliyun.com/repository/google' }
32 | mavenCentral()
33 | google()
34 | maven {
35 | allowInsecureProtocol = true
36 | url 'http://mvn.cloud.alipay.com/nexus/content/repositories/releases/'
37 | name 'alipay'
38 | credentials {
39 | username 'mvn_read_ws'
40 | password 'mrk8929'
41 | }
42 | }
43 |
44 | }
45 | }
46 |
47 | task clean(type: Delete) {
48 | delete rootProject.buildDir
49 | }
50 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. For more details, visit
12 | # https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Enables namespacing of each library's R class so that its R class includes only the
19 | # resources declared in the library itself and none from the library's dependencies,
20 | # thereby reducing the size of the R class for that library
21 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jul 13 15:28:03 CST 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/htmls/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | LogRocket
7 |
70 |
71 |
72 |
73 |
74 |
75 | 未连接
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
223 |
224 |
225 |
226 |
--------------------------------------------------------------------------------
/images/app_cut.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/images/app_cut.jpg
--------------------------------------------------------------------------------
/images/icon_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/images/icon_logo.png
--------------------------------------------------------------------------------
/images/index_info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/images/index_info.png
--------------------------------------------------------------------------------
/log-rocket/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/log-rocket/README.MD:
--------------------------------------------------------------------------------
1 | # 日志小火箭
2 |
3 | 实时日志流
--------------------------------------------------------------------------------
/log-rocket/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | id 'org.jetbrains.kotlin.android'
4 | id 'maven-publish'
5 | }
6 | group = 'com.github.xieyang94'
7 |
8 | android {
9 | compileSdk 34
10 | defaultConfig {
11 | minSdk 16
12 | targetSdk 35
13 | versionCode 1
14 | versionName '1.0.1'
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | consumerProguardFiles "consumer-rules.pro"
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | compileOptions {
27 | sourceCompatibility JavaVersion.VERSION_1_8
28 | targetCompatibility JavaVersion.VERSION_1_8
29 | }
30 | kotlinOptions {
31 | jvmTarget = '1.8'
32 | }
33 | }
34 |
35 | afterEvaluate {
36 | publishing {
37 | publications {
38 | // Creates a Maven publication called "release".
39 | release(MavenPublication) {
40 | // Applies the component for the release build variant.
41 | from components.release
42 |
43 | // You can then customize attributes of the publication as shown below.
44 | groupId = 'cn.net.yto.logrocket'
45 | artifactId = 'log-rocket'
46 | version = '1.0.1'
47 | }
48 | // Creates a Maven publication called “debug”.
49 | debug(MavenPublication) {
50 | // Applies the component for the debug build variant.
51 | from components.debug
52 |
53 | groupId = 'cn.net.yto.logrocket'
54 | artifactId = 'log-rocket-debug'
55 | version = '1.0.1'
56 | }
57 | }
58 | }
59 | }
60 |
61 | dependencies {
62 |
63 | implementation 'androidx.core:core-ktx:1.6.0'
64 | implementation 'com.google.android.material:material:1.4.0'
65 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2'
66 |
67 | //网络库*********************
68 | //implementation 'com.squareup.okhttp3:okhttp:4.9.3'
69 | //脱糖(Android低版本在编译时将高版本语法转化为低版本语法 https://blog.csdn.net/vitaviva/article/details/109422961)
70 | coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
71 | implementation 'org.java-websocket:Java-WebSocket:1.5.2'
72 |
73 | testImplementation 'junit:junit:4.13.2'
74 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
75 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
76 |
77 |
78 | }
--------------------------------------------------------------------------------
/log-rocket/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieyang94/LogRocket/37f531d8c244abd63f99f9efa355c6e41d983a5a/log-rocket/consumer-rules.pro
--------------------------------------------------------------------------------
/log-rocket/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/log-rocket/src/androidTest/java/cn/net/yto/logrocket/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package cn.net.yto.logrocket
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("cn.net.yto.logrocket.test", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/log-rocket/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/log-rocket/src/main/java/cn/net/yto/logrocket/LogRocket.java:
--------------------------------------------------------------------------------
1 | package cn.net.yto.logrocket;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 |
6 | import org.java_websocket.WebSocket;
7 |
8 | import java.net.InetSocketAddress;
9 | import java.util.Collection;
10 | import java.util.concurrent.ExecutorService;
11 | import java.util.concurrent.Executors;
12 |
13 | import cn.net.yto.logrocket.callback.UploadLogCallback;
14 | import cn.net.yto.logrocket.impl.WebSocketServerImpl;
15 | import cn.net.yto.logrocket.utils.LogCatUtil;
16 | import cn.net.yto.logrocket.utils.NetworkUtils;
17 |
18 | /**
19 | * *****************************************
20 | *
21 | * @Author : Davis
22 | * @Email : 1192171830@qq.com
23 | * @Create Time : 2024/12/5 15:15
24 | * @Description :
25 | * *****************************************
26 | */
27 | public class LogRocket {
28 |
29 | private WebSocketServerImpl mServer;
30 | private final ExecutorService executorService;
31 | private static int PORT = 9527;
32 | private boolean hasStart = false;
33 | private boolean uniquePort = false;
34 |
35 | //单例
36 | private static class SingletonHandler {
37 | private static final LogRocket instance = new LogRocket();
38 | }
39 |
40 | private LogRocket() {
41 | executorService = Executors.newCachedThreadPool();
42 | mServer = new WebSocketServerImpl(new InetSocketAddress(port()));
43 | }
44 |
45 | public static LogRocket getInstance() {
46 | return SingletonHandler.instance;
47 | }
48 |
49 | private int port() {
50 | if (uniquePort) {
51 | return uniquePort();
52 | }
53 | return randomPort();
54 | }
55 |
56 | private int uniquePort() {
57 | PORT = 9527;
58 | return PORT;
59 | }
60 |
61 | private int randomPort() {
62 | PORT = NetworkUtils.getRandomAvailablePort();
63 | return PORT;
64 | }
65 |
66 | private Collection connections() {
67 | return mServer.getConnections();
68 | }
69 |
70 | public String getWsAddress(Context context) {
71 | String wiFiIPAddress = NetworkUtils.getWiFiIPAddress(context);
72 | return "ws://" + wiFiIPAddress + ":" + PORT;
73 | }
74 |
75 | private void sendAll(String msg) {
76 | Collection connections = connections();
77 | if (connections.isEmpty()) return;
78 | for (WebSocket webSocket : connections) {
79 | send(webSocket, msg);
80 | }
81 | }
82 |
83 | private void send(WebSocket webSocket, String msg) {
84 | try {
85 | if (webSocket != null && webSocket.isOpen() && !TextUtils.isEmpty(msg) && !webSocket.isClosed() && !webSocket.isClosing()) {
86 | webSocket.send(msg);
87 | }
88 | } catch (Exception e) {
89 | e.printStackTrace();
90 | }
91 | }
92 |
93 | public LogRocket uniquePort(boolean uniquePort) {
94 | this.uniquePort = uniquePort;
95 | return this;
96 | }
97 |
98 | public LogRocket start() {
99 | if (hasStart) return this;
100 | try {
101 | stop();
102 | mServer = new WebSocketServerImpl(new InetSocketAddress(port()));
103 | mServer.start();
104 | } catch (Exception e) {
105 | e.printStackTrace();
106 | }
107 | hasStart = true;
108 | return this;
109 | }
110 |
111 | public LogRocket stop() {
112 | try {
113 | mServer.stop();
114 | hasStart = false;
115 | } catch (InterruptedException e) {
116 | throw new RuntimeException(e);
117 | }
118 | return this;
119 | }
120 |
121 | public LogRocket startUploadLog() {
122 | executorService.execute(() -> {
123 | LogCatUtil.getInstance().uploadLog(new UploadLogCallback() {
124 | @Override
125 | public void upload(String log) {
126 | sendAll(log);
127 | }
128 | });
129 | });
130 | return this;
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/log-rocket/src/main/java/cn/net/yto/logrocket/callback/UploadLogCallback.java:
--------------------------------------------------------------------------------
1 | package cn.net.yto.logrocket.callback;
2 |
3 | /**
4 | * *****************************************
5 | *
6 | * @Author : Davis
7 | * @Email : 1192171830@qq.com
8 | * @Create Time : 2024/12/5 15:42
9 | * @Description :
10 | * *****************************************
11 | */
12 | public interface UploadLogCallback {
13 |
14 | void upload(String log);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/log-rocket/src/main/java/cn/net/yto/logrocket/impl/WebSocketServerImpl.java:
--------------------------------------------------------------------------------
1 | package cn.net.yto.logrocket.impl;
2 |
3 | /**
4 | * *****************************************
5 | *
6 | * @Author : Davis
7 | * @Email : 1192171830@qq.com
8 | * @Create Time : 2024/12/5 10:12
9 | * @Description :
10 | * *****************************************
11 | */
12 |
13 | import android.util.Log;
14 |
15 | import org.java_websocket.WebSocket;
16 | import org.java_websocket.handshake.ClientHandshake;
17 | import org.java_websocket.server.WebSocketServer;
18 |
19 | import java.net.InetSocketAddress;
20 |
21 | public class WebSocketServerImpl extends WebSocketServer {
22 |
23 |
24 | public WebSocketServerImpl(InetSocketAddress address) {
25 | super(address);
26 | }
27 |
28 |
29 | @Override
30 | public void onOpen(WebSocket conn, ClientHandshake handshake) {
31 | //log("New connection: " + conn.getRemoteSocketAddress());
32 | log("Hello , New connector [" + conn.getRemoteSocketAddress().toString().replace("/", "") + "] , Welcome to the Log Rocket , Provides technical services by Davis !");
33 | //conn.send("Welcome to the Log Rocket , Provides technical services by Davis !");
34 | }
35 |
36 | @Override
37 | public void onClose(WebSocket conn, int code, String reason, boolean remote) {
38 | //conn.send("Log Rocket closed !");
39 | log("Connection closed: " + conn.getRemoteSocketAddress());
40 | }
41 |
42 | @Override
43 | public void onMessage(WebSocket conn, String message) {
44 | log("Message received: " + message);
45 | // Echo the message back to the client
46 | //conn.send("Echo: " + message);
47 | }
48 |
49 | @Override
50 | public void onError(WebSocket conn, Exception ex) {
51 | log("Error occurred: " + ex.getMessage());
52 |
53 | ex.printStackTrace();
54 | }
55 |
56 | @Override
57 | public void onStart() {
58 | log("WebSocket Server started successfully!");
59 | }
60 |
61 |
62 | private void log(String message) {
63 | Log.e("ccer", message);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/log-rocket/src/main/java/cn/net/yto/logrocket/lifecycle/ActivityLifecycleCallbackImpl.java:
--------------------------------------------------------------------------------
1 | package cn.net.yto.logrocket.lifecycle;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 | import android.os.Bundle;
6 |
7 | import androidx.annotation.NonNull;
8 | import androidx.annotation.Nullable;
9 |
10 | /**
11 | * *****************************************
12 | *
13 | * @Author : Davis
14 | * @Email : 1192171830@qq.com
15 | * @Create Time : 2024/12/5 20:06
16 | * @Description :
17 | * *****************************************
18 | */
19 | public class ActivityLifecycleCallbackImpl implements Application.ActivityLifecycleCallbacks{
20 | @Override
21 | public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
22 |
23 | }
24 |
25 | @Override
26 | public void onActivityStarted(@NonNull Activity activity) {
27 |
28 | }
29 |
30 | @Override
31 | public void onActivityResumed(@NonNull Activity activity) {
32 |
33 | }
34 |
35 | @Override
36 | public void onActivityPaused(@NonNull Activity activity) {
37 |
38 | }
39 |
40 | @Override
41 | public void onActivityStopped(@NonNull Activity activity) {
42 |
43 | }
44 |
45 | @Override
46 | public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
47 |
48 | }
49 |
50 | @Override
51 | public void onActivityDestroyed(@NonNull Activity activity) {
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/log-rocket/src/main/java/cn/net/yto/logrocket/meta/MetaParseUtil.kt:
--------------------------------------------------------------------------------
1 | package cn.net.yto.logcat.meta
2 |
3 | import android.content.Context
4 | import android.content.pm.PackageManager
5 |
6 | /**
7 | * @Author xiey
8 | * @Date 2024/4/12-09:47
9 | * @Email 02724892@yto.net.cn
10 | * @Description
11 | */
12 | object MetaParseUtil {
13 |
14 | private const val TAG_KEY = "uniquePort"
15 |
16 | @JvmStatic
17 | fun parseMeta(context: Context): Boolean {
18 | try {
19 | val info = context.packageManager.getApplicationInfo(
20 | context.packageName,
21 | PackageManager.GET_META_DATA
22 | )
23 | val uniquePort = info.metaData.getBoolean(TAG_KEY)
24 | return uniquePort
25 | } catch (e: Exception) {
26 | e.printStackTrace()
27 | }
28 | return false;
29 | }
30 |
31 |
32 | }
--------------------------------------------------------------------------------
/log-rocket/src/main/java/cn/net/yto/logrocket/provider/ContentProviderImpl.kt:
--------------------------------------------------------------------------------
1 | package cn.net.yto.logrocket.provider
2 |
3 | import android.content.ContentProvider
4 | import android.content.ContentValues
5 | import android.content.Context
6 | import android.database.Cursor
7 | import android.net.Uri
8 |
9 | /**
10 | * @Author xiey
11 | * @Date 2024/4/12-14:21
12 | * @Email 02724892@yto.net.cn
13 | * @Description
14 | */
15 | abstract class ContentProviderImpl : ContentProvider() {
16 |
17 | abstract fun doWork(context: Context)
18 |
19 | override fun onCreate(): Boolean {
20 | if (context != null && context?.applicationContext != null) {
21 | context?.applicationContext?.let { doWork(it) }
22 | }
23 | return true
24 | }
25 |
26 | override fun query(
27 | uri: Uri,
28 | projection: Array?,
29 | selection: String?,
30 | selectionArgs: Array?,
31 | sortOrder: String?
32 | ): Cursor? {
33 |
34 | return null
35 | }
36 |
37 | override fun getType(uri: Uri): String? {
38 |
39 | return null
40 | }
41 |
42 | override fun insert(uri: Uri, values: ContentValues?): Uri? {
43 |
44 | return null
45 | }
46 |
47 | override fun delete(uri: Uri, selection: String?, selectionArgs: Array?): Int {
48 |
49 | return -1
50 | }
51 |
52 | override fun update(
53 | uri: Uri,
54 | values: ContentValues?,
55 | selection: String?,
56 | selectionArgs: Array?
57 | ): Int {
58 |
59 | return -1
60 | }
61 | }
--------------------------------------------------------------------------------
/log-rocket/src/main/java/cn/net/yto/logrocket/provider/LogRocketProvider.java:
--------------------------------------------------------------------------------
1 | package cn.net.yto.logrocket.provider;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 | import android.content.Context;
6 | import android.os.Bundle;
7 | import android.util.Log;
8 |
9 | import androidx.annotation.NonNull;
10 | import androidx.annotation.Nullable;
11 |
12 | import cn.net.yto.logcat.meta.MetaParseUtil;
13 | import cn.net.yto.logrocket.LogRocket;
14 | import cn.net.yto.logrocket.lifecycle.ActivityLifecycleCallbackImpl;
15 |
16 | /**
17 | * *****************************************
18 | *
19 | * @Author : Davis
20 | * @Email : 1192171830@qq.com
21 | * @Create Time : 2024/12/5 20:04
22 | * @Description :
23 | * *****************************************
24 | */
25 | public class LogRocketProvider extends ContentProviderImpl {
26 |
27 | private int mCount = 0;
28 |
29 | @Override
30 | public void doWork(@NonNull Context context) {
31 | registerLifecycle(context);
32 | }
33 |
34 | private void registerLifecycle(Context context) {
35 | if (context instanceof Application) {
36 | ((Application) context).registerActivityLifecycleCallbacks(new ActivityLifecycleCallbackImpl() {
37 | @Override
38 | public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
39 | super.onActivityCreated(activity, savedInstanceState);
40 | if (mCount <= 0) {
41 | boolean uniquePort = MetaParseUtil.parseMeta(context);
42 | LogRocket.getInstance()
43 | .uniquePort(uniquePort)
44 | .startUploadLog()
45 | .start();
46 | }
47 | mCount++;
48 | }
49 |
50 | @Override
51 | public void onActivityDestroyed(@NonNull Activity activity) {
52 | super.onActivityDestroyed(activity);
53 | mCount--;
54 | if (mCount <= 0) {
55 | Log.e("ccer","===========stop====================>");
56 | LogRocket.getInstance().stop();
57 | }
58 | }
59 |
60 | @Override
61 | public void onActivityStopped(@NonNull Activity activity) {
62 | super.onActivityStopped(activity);
63 | }
64 | });
65 | }
66 | }
67 |
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/log-rocket/src/main/java/cn/net/yto/logrocket/refect/ReflectLogRocket.java:
--------------------------------------------------------------------------------
1 | package cn.net.yto.logrocket.refect;
2 |
3 | import android.content.Context;
4 |
5 | import cn.net.yto.logrocket.LogRocket;
6 | import cn.net.yto.logrocket.utils.NetworkUtils;
7 |
8 | /**
9 | * *****************************************
10 | *
11 | * @Author : Davis
12 | * @Email : 1192171830@qq.com
13 | * @Create Time : 2024/12/5 20:13
14 | * @Description :
15 | * *****************************************
16 | */
17 | public class ReflectLogRocket {
18 |
19 | /**
20 | * 反射获取ws地址
21 | *
22 | * @param context
23 | * @return
24 | */
25 | public String wdAddress(Context context) {
26 | return LogRocket.getInstance().getWsAddress(context);
27 | }
28 |
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/log-rocket/src/main/java/cn/net/yto/logrocket/utils/LogCatUtil.java:
--------------------------------------------------------------------------------
1 | package cn.net.yto.logrocket.utils;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStreamReader;
6 |
7 | import cn.net.yto.logrocket.callback.UploadLogCallback;
8 |
9 | /**
10 | * *****************************************
11 | *
12 | * @Author : Davis
13 | * @Email : 1192171830@qq.com
14 | * @Create Time : 2024/12/5 15:17
15 | * @Description :
16 | * *****************************************
17 | */
18 | public class LogCatUtil {
19 |
20 | //单例
21 | private static class SingletonHandler {
22 | private static LogCatUtil instance = new LogCatUtil();
23 | }
24 |
25 | private LogCatUtil() {
26 | }
27 |
28 | public static LogCatUtil getInstance() {
29 | return SingletonHandler.instance;
30 | }
31 |
32 | public void uploadLog(UploadLogCallback callback) {
33 | try {
34 | // 执行logcat命令
35 | Process process = Runtime.getRuntime().exec("logcat");
36 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
37 | String line = "";
38 | while ((line = bufferedReader.readLine()) != null) {
39 | if (callback != null) {
40 | callback.upload(line);
41 | }
42 | }
43 | // 关闭流
44 | bufferedReader.close();
45 | } catch (IOException e) {
46 | e.printStackTrace();
47 | }
48 | }
49 |
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/log-rocket/src/main/java/cn/net/yto/logrocket/utils/NetworkUtils.java:
--------------------------------------------------------------------------------
1 | package cn.net.yto.logrocket.utils;
2 |
3 | import android.content.Context;
4 | import android.net.wifi.WifiManager;
5 | import android.text.format.Formatter;
6 |
7 | import java.io.IOException;
8 | import java.net.Inet6Address;
9 | import java.net.InetAddress;
10 | import java.net.NetworkInterface;
11 | import java.net.ServerSocket;
12 | import java.util.Collections;
13 |
14 | /**
15 | * *****************************************
16 | *
17 | * @Author : Davis
18 | * @Email : 1192171830@qq.com
19 | * @Create Time : 2024/12/5 17:05
20 | * @Description :
21 | * *****************************************
22 | */
23 | public class NetworkUtils {
24 |
25 | public static String getWiFiIPAddress(Context context) {
26 | WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
27 | if (wifiMgr != null && wifiMgr.getConnectionInfo() != null) {
28 | int ipAddress = wifiMgr.getConnectionInfo().getIpAddress();
29 | return Formatter.formatIpAddress(ipAddress);
30 | }
31 | return null;
32 | }
33 |
34 | public static String getMobileIPAddress() {
35 | try {
36 | String ipAddress = "";
37 | for (java.net.NetworkInterface intf : Collections.list(NetworkInterface.getNetworkInterfaces())) {
38 | for (InetAddress addr : Collections.list(intf.getInetAddresses())) {
39 | if (!addr.isLoopbackAddress() && !(addr instanceof Inet6Address)) {
40 | ipAddress = addr.getHostAddress();
41 | }
42 | }
43 | }
44 | return ipAddress;
45 | } catch (Exception ex) {
46 | ex.printStackTrace();
47 | }
48 | return null;
49 | }
50 |
51 | public static int getRandomAvailablePort() {
52 | ServerSocket serverSocket = null; // 0 表示让系统自动分配一个空闲端口
53 | try {
54 | serverSocket = new ServerSocket(0);
55 | int port = serverSocket.getLocalPort();
56 | serverSocket.close();
57 | return port;
58 | } catch (IOException e) {
59 | e.printStackTrace();
60 | }
61 | return 9527;
62 | }
63 |
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/log-rocket/src/test/java/cn/net/yto/logrocket/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package cn.net.yto.logrocket
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | maven { url = uri("https://jitpack.io") }
4 | maven { url 'https://maven.aliyun.com/repository/public' }
5 | maven { url 'https://maven.aliyun.com/repository/google' }
6 | google()
7 | mavenCentral()
8 | }
9 | }
10 |
11 | rootProject.name = "LogRocket"
12 | include ':app'
13 | include ':log-rocket'
--------------------------------------------------------------------------------