<>第一步老规矩导架包
1.在项目的根目录的配置文件中的dependencies添加
classpath "com.tencent.bugly:tinker-support:1.1.5"
2.在module的配置文件中添加
// 多dex配置 compile 'com.android.support:multidex:1.0.2' // 本地集成aar方式 //
compile(name: 'bugly_crashreport_upgrade-1.3.6', ext: 'aar') // 远程依赖集成方式(推荐)
compile'com.tencent.bugly:crashreport_upgrade:1.3.6' //
指定tinker依赖版本(注:应用升级1.3.5版本起,不再内置tinker) compile
'com.tencent.tinker:tinker-android-lib:1.9.9'
然后再添加
apply from: 'tinker-support.gradle'
3.创建tinker-support.gradle
apply plugin: 'com.tencent.bugly.tinker-support' def bakPath = file(
"${buildDir}/bakApk/") /** * 此处填写每次构建生成的基准包目录 */ def baseApkDir =
"app-1217-17-22-37" /** * 对于插件各参数的详细解析请参考 */ tinkerSupport { //
开启tinker-support插件,默认值true enable = true // 指定归档目录,默认值当前module的子目录tinker
autoBackupApkDir= "${bakPath}" // 是否启用覆盖tinkerPatch配置功能,默认值false //
开启后tinkerPatch配置不生效,即无需添加tinkerPatch overrideTinkerPatchConfiguration = true //
编译补丁包时,必需指定基线版本的apk,默认值为空 // 如果为空,则表示不是进行补丁包的编译 // @{link tinkerPatch.oldApk }
baseApk= "${bakPath}/${baseApkDir}/app-release.apk" // 对应tinker插件applyMapping
baseApkProguardMapping= "${bakPath}/${baseApkDir}/app-release-mapping.txt" //
对应tinker插件applyResourceMapping baseApkResourceMapping =
"${bakPath}/${baseApkDir}/app-release-R.txt" //
构建基准包和补丁包都要指定不同的tinkerId,并且必须保证唯一性 tinkerId = "bugpaths-1.0.1" // 构建多渠道补丁时使用 //
buildAllFlavorsDir = "${bakPath}/${baseApkDir}" //
是否启用加固模式,默认为false.(tinker-spport 1.0.7起支持) // isProtectedApp = true //
是否开启反射Application模式 enableProxyApplication = true //
是否支持新增非export的Activity(注意:设置为true才能修改AndroidManifest文件) supportHotplugComponent
= true } /** * 一般来说,我们无需对下面的参数做任何的修改 * 对于各参数的详细介绍请参考: *
https://github.com/Tencent/tinker/wiki/Tinker-%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97
*/ tinkerPatch { //oldApk ="${bakPath}/${appName}/app-release.apk" ignoreWarning
= false useSign = true dex { dexMode = "jar" pattern = ["classes*.dex"] loader =
[] } lib { pattern = ["lib/*/*.so"] } res { pattern = ["res/*", "r/*",
"assets/*", "resources.arsc", "AndroidManifest.xml"] ignoreChange = []
largeModSize= 100 } packageConfig { } sevenZip { zipArtifact =
"com.tencent.mm:SevenZip:1.1.10" // path = "/usr/local/bin/7za" } buildConfig {
keepDexApply= false //tinkerId = "1.0.1-base" //applyMapping =
"${bakPath}/${appName}/app-release-mapping.txt" //
可选,设置mapping文件,建议保持旧apk的proguard混淆方式//applyResourceMapping =
"${bakPath}/${appName}/app-release-R.txt" // 可选,设置R.txt文件,通过旧apk文件保持ResId的分配 } }
<>第二步设置权限
<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" /> <uses-permission android:name=
"android.permission.WRITE_EXTERNAL_STORAGE" />
再在application标签中添加
<activity android:name="com.tencent.bugly.beta.ui.BetaActivity" android:theme=
"@android:style/Theme.Translucent"/> <provider android:name=
"android.support.v4.content.FileProvider" android:authorities=
"com.tencent.bugly.hotfix.easy.fileProvider" android:exported="false" android:
grantUriPermissions="true"> <meta-data android:name=
"android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/> <
/provider>
这时候问题来了,编译出错了,大概是说我们需要一个app来实现热更新
创建之后记得在application标签中加入下面声明代码
android:name="yuexia.com.bugiydemo.MyApplication"
<>第三步创建MyApplication.calss
最简单的是上面这样的,但是为了我自己的体验我就要回调这些方法知道补丁的状态
package yuexia.com.bugiydemo; import android.app.Application; import android.
content.Context; import android.support.multidex.MultiDex; import android.widget
.Toast; import com.tencent.bugly.Bugly; import com.tencent.bugly.beta.Beta;
import com.tencent.bugly.beta.interfaces.BetaPatchListener; import com.tencent.
bugly.beta.upgrade.UpgradeStateListener; import java.util.Locale; /** * Created
by syt98 on 2018/12/17. */ public class MyApplication extends Application {
@Override public void onCreate() { super.onCreate(); Beta.enableHotfix = true;
// 设置是否自动下载补丁 Beta.canAutoDownloadPatch = true; // 设置是否提示用户重启 Beta.
canNotifyUserRestart= true; // 设置是否自动合成补丁 Beta.canAutoPatch = true; /** *
全量升级状态回调 */ Beta.upgradeStateListener = new UpgradeStateListener() { @Override
public void onUpgradeFailed(boolean b) { } @Override public void
onUpgradeSuccess(boolean b) { } @Override public void onUpgradeNoVersion(boolean
b) { Toast.makeText(getApplicationContext(), "最新版本", Toast.LENGTH_SHORT).show()
; } @Override public void onUpgrading(boolean b) { Toast.makeText(
getApplicationContext(), "onUpgrading", Toast.LENGTH_SHORT).show(); } @Override
public void onDownloadCompleted(boolean b) { } }; /** *
补丁回调接口,可以监听补丁接收、下载、合成的回调 */ Beta.betaPatchListener = new BetaPatchListener() {
@Override public void onPatchReceived(String patchFileUrl) { Toast.makeText(
getApplicationContext(), patchFileUrl, Toast.LENGTH_SHORT).show(); } @Override
public void onDownloadReceived(long savedLength, long totalLength) { Toast.
makeText(getApplicationContext(), String.format(Locale.getDefault(), "%s %d%%",
Beta.strNotificationDownloading, (int) (totalLength == 0 ? 0 : savedLength * 100
/ totalLength)), Toast.LENGTH_SHORT).show(); } @Override public void
onDownloadSuccess(String patchFilePath) { Toast.makeText(getApplicationContext()
, patchFilePath, Toast.LENGTH_SHORT).show(); // Beta.applyDownloadedPatch(); }
@Override public void onDownloadFailure(String msg) { Toast.makeText(
getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); } @Override public
void onApplySuccess(String msg) { Toast.makeText(getApplicationContext(), msg,
Toast.LENGTH_SHORT).show(); } @Override public void onApplyFailure(String msg) {
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); }
@Override public void onPatchRollback() { Toast.makeText(getApplicationContext()
, "onPatchRollback", Toast.LENGTH_SHORT).show(); } }; //
这里实现SDK初始化,appId替换成你的在Bugly平台申请的appId // 调试时,将第三个参数改为true Bugly.init(this,
"2382e48482", false); } @Override protected void attachBaseContext(Context base)
{ super.attachBaseContext(base); // you must install multiDex whatever tinker
is installed! MultiDex.install(base); // 安装tinker Beta.installTinker(); } }
<>第四步写错误代码倒基包
1.错误代码就自己想了
2.倒基包
点击后发现打的apk变成了
app-release-unsigned.apk
怎么解决呢
解决教材 <https://blog.csdn.net/l_lhc/article/details/77963683>
之后的流程和第一篇讲的一样
转一 <https://blog.csdn.net/qq_41816123/article/details/85054949>
<>总结
基本的BugIy学习到这里结束了
这篇主要说自己创建项目用BugIy需要注意的点:
1.创建之后记得在application标签中加入声明代码
2.app-release-unsigned.apk的解决方式
3.bugiy总的来说类似于tinker的加强版,比较方便。但还是基于类的修改需要冷启动。有它的优势和缺陷。
<>有啥不懂或者小白写的不好的可以留言
热门工具 换一换