- 集成SDK和NDK
在Module的build.gradle文件中添加依赖和属性配置:
参数配置
- 在AndroidManifest.xml中添加权限:
-
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.READ_LOGS" />
注:如果您的App需要上传到google play store,您需要将READ_PHONE_STATE权限屏蔽掉或者移除,否则可能会被下架。
- 请避免混淆Bugly,在Proguard混淆文件中增加以下配置:
-
-dontwarn com.tencent.bugly.** -keep public class com.tencent.bugly.**{*;}
最简单的初始化
获取APP ID并将以下代码复制到项目Application类onCreate()中,Bugly会为自动检测环境并完成配置:
CrashReport.initCrashReport(getApplicationContext(), "注册时申请的APPID", false);
为了保证运营数据的准确性,建议不要在异步线程初始化Bugly。
-
在“AndroidManifest.xml”的“Application”中增加“meta-data”配置项:
-
<application <!-- 配置APP ID --> <meta-data android:name="BUGLY_APPID" android:value="<APP_ID>" /> <!-- 配置APP版本号 --> <meta-data android:name="BUGLY_APP_VERSION" android:value="<APP_Version>" /> <!-- 配置APP渠道号 --> <meta-data android:name="BUGLY_APP_CHANNEL" android:value="<APP_Channel>" /> <!-- 配置Bugly调试模式(true或者false)--> <meta-data android:name="BUGLY_ENABLE_DEBUG" android:value="<isDebug>" /> </application>
不同于“android:versionName”,“BUGLY_APP_VERSION”配置的是Bugly平台的APP版本号。
通过“AndroidManifest.xml”配置后的初始化方法如下:
CrashReport.initCrashReport(getApplicationContext());
Bugly默认从“AndroidManifest.xml”文件中读取“VersionName”作为版本号,自定义设置请使用参考“高级设置”。
-
/* * 初始化bugly * */ private void initBugly(){ // 这里实现SDK初始化,appId替换成你的在Bugly平台申请的appId // 调试时,将第三个参数改为true /* Bugly.init(getApplication(), "70f17237f5", DEBUG); CrashReport.initCrashReport(getApplicationContext()); CrashReport.initCrashReport(getApplicationContext(), "70f17237f5", DEBUG);*/ Beta.enableHotfix = true; //设置是否自动下载补丁,默认为true Beta.canAutoDownloadPatch = true; //设置是否自动合成补丁,默认为true Beta.canAutoPatch = true; //设置是否提示用户重启,默认为false Beta.canNotifyUserRestart = true; //补丁回调接口 Beta.betaPatchListener = new BetaPatchListener() { @Override public void onPatchReceived(String s) { Toast.makeText(getApplication(), "补丁下载地址" + s, Toast.LENGTH_SHORT).show(); } @Override public void onDownloadReceived(long savedLength, long totalLength) { Toast.makeText(getApplication(), String.format(Locale.getDefault(),"%s %d%%",Beta.strNotificationDownloading, (int) (totalLength == 0 ? 0 : savedLength * 100 / totalLength)), Toast.LENGTH_SHORT).show(); } @Override public void onDownloadSuccess(String s) { Toast.makeText(getApplication(), "补丁下载成功", Toast.LENGTH_SHORT).show(); } @Override public void onDownloadFailure(String s) { Toast.makeText(getApplication(), "补丁下载失败", Toast.LENGTH_SHORT).show(); } @Override public void onApplySuccess(String s) { Toast.makeText(getApplication(), "补丁应用成功", Toast.LENGTH_SHORT).show(); } @Override public void onApplyFailure(String s) { Toast.makeText(getApplication(), "补丁应用失败", Toast.LENGTH_SHORT).show(); } @Override public void onPatchRollback() { } } ; // 设置开发设备,默认为false,上传补丁如果下发范围指定为“开发设备”,需要调用此接口来标识开发设备 Bugly.setIsDevelopmentDevice(getApplication(),DEBUG); //多渠道需求塞入 String channel = WalleChannelReader.getChannel(getApplication()); Bugly.setAppChannel(getApplication(),channel); // 这里实现SDK初始化,appId替换成你的在Bugly平台申请的appId // Bugly.init(getApplication(), "70f17237f5", DEBUG); Bugly.init(getApplication(), DEBUG ? BuylyConstant.dev_app_id : BuylyConstant.release_app_id, DEBUG); }