Skip to content

Commit c8063ee

Browse files
committed
升级 Bugly 版本到 4.4.7.3 并适配 16k so 库特性
1 parent 02e463f commit c8063ee

9 files changed

Lines changed: 47 additions & 32 deletions

File tree

app/build.gradle

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ android {
3131
// 混淆配置
3232
proguardFiles 'proguard-sdk.pro', 'proguard-app.pro'
3333

34-
// 日志打印开关
34+
// 日志开关
3535
buildConfigField('boolean', 'LOG_ENABLE', '' + LOG_ENABLE + '')
36-
// 测试包下的 BuglyId
37-
buildConfigField('String', 'BUGLY_ID', '"' + BUGLY_ID + '"')
38-
// 测试服务器的主机地址
36+
// 主机地址
3937
buildConfigField('String', 'HOST_URL', '"' + HOST_URL + '"')
38+
// BuglyId
39+
buildConfigField('String', 'BUGLY_ID', '"' + BUGLY_ID + '"')
40+
// BuglyKey
41+
buildConfigField('String', 'BUGLY_KEY', '"' + BUGLY_KEY + '"')
4042
}
4143

4244
sourceSets {
@@ -224,9 +226,8 @@ dependencies {
224226
// 手势 ImageView:https://github.com/Baseflow/PhotoView
225227
implementation 'com.github.Baseflow:PhotoView:2.3.0'
226228

227-
// Bugly 异常捕捉:https://bugly.qq.com/docs/user-guide/instruction-manual-android/?v=20190418140644
228-
implementation 'com.tencent.bugly:crashreport:4.1.9.3'
229-
implementation 'com.tencent.bugly:nativecrashreport:3.9.2'
229+
// Bugly 异常捕捉:https://bugly.tds.qq.com/docs/sdk/android/
230+
implementation 'com.tencent.bugly_16kb:bugly-pro:4.4.7.3'
230231

231232
// 动画解析库:https://github.com/airbnb/lottie-android
232233
// 动画资源:https://lottiefiles.com、https://icons8.com/animated-icons

app/src/main/java/com/hjq/demo/manager/InitManager.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
import com.hjq.toast.Toaster;
3636
import com.hjq.umeng.UmengClient;
3737
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
38-
import com.tencent.bugly.crashreport.CrashReport;
38+
import com.tencent.bugly.library.Bugly;
39+
import com.tencent.bugly.library.BuglyBuilder;
3940
import com.tencent.mmkv.MMKV;
4041
import okhttp3.OkHttpClient;
4142
import timber.log.Timber;
@@ -115,7 +116,9 @@ public static void preInitSdk(Application application) {
115116
CrashHandler.register(application);
116117

117118
// Bugly 异常捕捉
118-
CrashReport.initCrashReport(application, AppConfig.getBuglyId(), AppConfig.isDebug());
119+
BuglyBuilder builder = new BuglyBuilder(AppConfig.getBuglyId(), AppConfig.getBuglyKey());
120+
builder.debugMode = AppConfig.isDebug();
121+
Bugly.init(application, builder);
119122

120123
// Activity 栈管理初始化
121124
ActivityManager.getInstance().init(application);
@@ -171,11 +174,12 @@ public void onParseMapItemException(TypeToken<?> typeToken, String fieldName, St
171174
}
172175

173176
private void handlerGsonParseException(String message) {
177+
IllegalArgumentException e = new IllegalArgumentException(message);
174178
if (AppConfig.isDebug()) {
175-
throw new IllegalArgumentException(message);
179+
throw e;
176180
} else {
177181
// 上报到 Bugly 错误列表中
178-
CrashReport.postCatchedException(new IllegalArgumentException(message));
182+
Bugly.handleCatchException(Thread.currentThread(), e, e.getMessage(), null, true);
179183
}
180184
}
181185
});

app/src/main/java/com/hjq/demo/other/AppConfig.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,23 @@ public static int getVersionCode() {
5353
}
5454

5555
/**
56-
* 获取 Bugly Id
56+
* 获取服务器主机地址
57+
*/
58+
public static String getHostUrl() {
59+
return BuildConfig.HOST_URL;
60+
}
61+
62+
/**
63+
* 获取 BuglyId
5764
*/
5865
public static String getBuglyId() {
5966
return BuildConfig.BUGLY_ID;
6067
}
6168

6269
/**
63-
* 获取服务器主机地址
70+
* 获取 BuglyKey
6471
*/
65-
public static String getHostUrl() {
66-
return BuildConfig.HOST_URL;
72+
public static String getBuglyKey() {
73+
return BuildConfig.BUGLY_KEY;
6774
}
6875
}

app/src/main/java/com/hjq/demo/ui/activity/common/CrashActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.hjq.demo.app.AppActivity;
2626
import com.hjq.demo.manager.ThreadPoolManager;
2727
import com.hjq.demo.other.AppConfig;
28-
import com.tencent.bugly.crashreport.CrashReport;
28+
import com.tencent.bugly.library.Bugly;
2929
import java.io.PrintWriter;
3030
import java.io.StringWriter;
3131
import java.net.InetAddress;
@@ -210,7 +210,7 @@ protected void initData() {
210210

211211
} catch (PackageManager.NameNotFoundException e) {
212212
e.printStackTrace();
213-
CrashReport.postCatchedException(e);
213+
Bugly.handleCatchException(Thread.currentThread(), e, e.getMessage(), null, true);
214214
}
215215
}
216216

app/src/main/java/com/hjq/demo/ui/activity/common/ImageCropActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import com.hjq.demo.permission.PermissionInterceptor;
1919
import com.hjq.permissions.XXPermissions;
2020
import com.hjq.permissions.permission.PermissionLists;
21-
import com.tencent.bugly.crashreport.CrashReport;
21+
import com.tencent.bugly.library.Bugly;
2222
import java.io.File;
2323
import java.text.SimpleDateFormat;
2424
import java.util.Date;
@@ -200,7 +200,7 @@ protected void initData() {
200200
});
201201
} catch (ActivityNotFoundException e) {
202202
e.printStackTrace();
203-
CrashReport.postCatchedException(e);
203+
Bugly.handleCatchException(Thread.currentThread(), e, e.getMessage(), null, true);
204204
setResult(RESULT_ERROR, new Intent().putExtra(INTENT_KEY_OUT_ERROR, getString(R.string.image_crop_error_not_support)));
205205
finish();
206206
}

app/src/main/java/com/hjq/demo/ui/activity/common/VideoSelectActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import com.hjq.permissions.XXPermissions;
3434
import com.hjq.permissions.permission.PermissionLists;
3535
import com.hjq.widget.view.FloatActionButton;
36-
import com.tencent.bugly.crashreport.CrashReport;
36+
import com.tencent.bugly.library.Bugly;
3737
import java.io.File;
3838
import java.util.ArrayList;
3939
import java.util.HashMap;
@@ -546,7 +546,7 @@ public static VideoBean newInstance(String videoPath) {
546546
// 荣耀 LLD AL20 Android 8.0 出现:java.lang.IllegalArgumentException
547547
// 荣耀 HLK AL00 Android 10.0 出现:java.lang.RuntimeException:setDataSource failed: status = 0x80000000
548548
e.printStackTrace();
549-
CrashReport.postCatchedException(e);
549+
Bugly.handleCatchException(Thread.currentThread(), e, e.getMessage(), null, true);
550550
}
551551

552552
long videoSize = new File(videoPath).length();

app/src/main/java/com/hjq/demo/ui/dialog/common/AddressDialog.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.hjq.demo.aop.SingleClick;
2020
import com.hjq.demo.app.AppAdapter;
2121
import com.hjq.demo.ui.adapter.common.TabAdapter;
22-
import com.tencent.bugly.crashreport.CrashReport;
22+
import com.tencent.bugly.library.Bugly;
2323
import java.io.ByteArrayOutputStream;
2424
import java.io.IOException;
2525
import java.io.InputStream;
@@ -505,7 +505,7 @@ private static List<AddressBean> getProvinceList(Context context) {
505505

506506
} catch (JSONException e) {
507507
e.printStackTrace();
508-
CrashReport.postCatchedException(e);
508+
Bugly.handleCatchException(Thread.currentThread(), e, e.getMessage(), null, true);
509509
}
510510
return null;
511511
}
@@ -529,7 +529,7 @@ private static List<AddressBean> getCityList(JSONObject jsonObject) {
529529
return list;
530530
} catch (JSONException e) {
531531
e.printStackTrace();
532-
CrashReport.postCatchedException(e);
532+
Bugly.handleCatchException(Thread.currentThread(), e, e.getMessage(), null, true);
533533
return null;
534534
}
535535
}
@@ -553,7 +553,7 @@ private static List<AddressBean> getAreaList(JSONObject jsonObject) {
553553
return list;
554554
} catch (JSONException e) {
555555
e.printStackTrace();
556-
CrashReport.postCatchedException(e);
556+
Bugly.handleCatchException(Thread.currentThread(), e, e.getMessage(), null, true);
557557
return null;
558558
}
559559
}
@@ -575,7 +575,7 @@ private static JSONArray getProvinceJson(Context context) {
575575
return new JSONArray(outStream.toString());
576576
} catch (IOException | JSONException e) {
577577
e.printStackTrace();
578-
CrashReport.postCatchedException(e);
578+
Bugly.handleCatchException(Thread.currentThread(), e, e.getMessage(), null, true);
579579
}
580580
return null;
581581
}

app/src/main/java/com/hjq/demo/ui/fragment/home/HomeMineFragment.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.hjq.demo.ui.activity.common.VideoSelectActivity;
2828
import com.hjq.demo.ui.dialog.common.InputDialog;
2929
import com.hjq.demo.ui.dialog.common.MessageDialog;
30-
import com.tencent.bugly.crashreport.CrashReport;
30+
import com.tencent.bugly.library.Bugly;
3131
import java.util.ArrayList;
3232
import java.util.List;
3333

@@ -167,11 +167,12 @@ public void onCancel() {
167167

168168
} else if (viewId == R.id.btn_home_mine_crash) {
169169

170+
IllegalStateException e = new IllegalStateException("are you ok?");
170171
// 上报错误到 Bugly 上
171-
CrashReport.postCatchedException(new IllegalStateException("are you ok?"));
172+
Bugly.handleCatchException(Thread.currentThread(), e, e.getMessage(), null, true);
172173
// 关闭 Bugly 异常捕捉
173-
CrashReport.closeBugly();
174-
throw new IllegalStateException("are you ok?");
174+
Bugly.setCrashMonitorAble(Bugly.JAVA_CRASH, false);
175+
throw e;
175176

176177
} else if (viewId == R.id.btn_home_mine_donate) {
177178

configs.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ ext {
4646
case SERVER_TYPE_TEST:
4747
case SERVER_TYPE_PREVIEW:
4848
LOG_ENABLE = true
49-
BUGLY_ID = "请自行替换 Bugly 上面的 AppID"
49+
BUGLY_ID = "请自行替换 Bugly 上面的 AppId"
50+
BUGLY_KEY = "请自行替换 Bugly 上面的 AppKey"
5051
if (serverType == SERVER_TYPE_PREVIEW) {
5152
HOST_URL = "https://www.pre.baidu.com/"
5253
} else {
@@ -55,7 +56,8 @@ ext {
5556
break
5657
case SERVER_TYPE_PRODUCT:
5758
LOG_ENABLE = false
58-
BUGLY_ID = "请自行替换 Bugly 上面的 AppID"
59+
BUGLY_ID = "请自行替换 Bugly 上面的 AppId"
60+
BUGLY_KEY = "请自行替换 Bugly 上面的 AppKey"
5961
HOST_URL = "https://www.baidu.com/"
6062
break
6163
}

0 commit comments

Comments
 (0)