Android集成腾讯bugly-tinker热更新步骤

在Androidstudio中新建MyBuglyTinkerDemo;

1. 在项目project的build.gradle中配置如下:
buildscript {    repositories {        jcenter()    }    dependencies {     //------------------------bugly-tinker配置第一步-------------------        // tinkersupport插件, 其中lastest.release指拉取最新版本,也可以指定明确版本号,例如1.0.4        classpath "com.tencent.bugly:tinker-support:1.1.1"    }}
2. 在项目project下app Module的build.gradle中配置如下:
defaultConfig {        applicationId "com.example.jackguo.mybuglytinkerdemo"        minSdkVersion 15        targetSdkVersion 26        versionCode 100        versionName "1.0.0"        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"        //------------------------bugly-tinker配置第二步-------------------        ndk {            //设置支持的SO库架构            abiFilters 'armeabi' , 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'        }    }dependencies {    implementation fileTree(dir: 'libs', include: ['*.jar'])    implementation 'com.android.support:appcompat-v7:26.1.0'    implementation 'com.android.support.constraint:constraint-layout:1.0.2'    testImplementation 'junit:junit:4.12'    androidTestImplementation 'com.android.support.test:runner:1.0.1'    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'    //------------------------bugly-tinker配置第二步-------------------    compile "com.android.support:multidex:1.0.2" // 多dex配置    //注释掉原有bugly的仓库    //compile 'com.tencent.bugly:crashreport:latest.release'//其中latest.release指代最新版本号,也可以指定明确的版本号,例如2.3.2    compile 'com.tencent.bugly:crashreport_upgrade:1.3.4'    compile 'com.tencent.bugly:nativecrashreport:3.3.1' //其中latest.release指代最新版本号,也可以指定明确的版本号,例如3.3.1}
3. 配置tinker-support.gradle:

(1)在app module的build.gradle文件中添加:

// 依赖插件脚本apply from: 'tinker-support.gradle'

(2) 在app module的build.gradle文件同级目录中创建tinker-support.gradle文件:(tinker-support.gradle内容如下所示:示例配置)

apply plugin: 'com.tencent.bugly.tinker-support'def bakPath = file("${buildDir}/bakApk/")/** * 此处填写每次构建生成的基准包目录 */def baseApkDir = "app-0205-17-38-13"/** * 对于插件各参数的详细解析请参考 */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}/yichufang-release-mapping.txt"    // 对应tinker插件applyResourceMapping    baseApkResourceMapping = "${bakPath}/${baseApkDir}/app-release-R.txt"    // 构建基准包和补丁包都要指定不同的tinkerId,并且必须保证唯一性    tinkerId = "mybuglytinkerdemo-v1.0.0-20180205-patch1"    // 构建多渠道补丁时使用    // buildAllFlavorsDir = "${bakPath}/${baseApkDir}"    // 是否启用加固模式,默认为false.(tinker-spport 1.0.7起支持)    isProtectedApp = true    // 是否开启反射Application模式    enableProxyApplication = false    // 是否支持新增非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 = "2.0.0-base"        //applyMapping = "${bakPath}/${appName}/app-release-mapping.txt" //  可选,设置mapping文件,建议保持旧apk的proguard混淆方式        //applyResourceMapping = "${bakPath}/${appName}/app-release-R.txt" // 可选,设置R.txt文件,通过旧apk文件保持ResId的分配    }}
4. 在app module中自定义MyApplication,并继承TinkerApplication;代码示例如下:
/** * @author jack.guo  2018/2/5. * * 配置thinker第4步,自定义MyApplication继承TinkerApplication *  * 注意:这个类集成TinkerApplication类,这里面不做任何操作,所有Application的代码都会放到ApplicationLike继承类当中 */public class MyApplication extends TinkerApplication {    public MyApplication() {        super(ShareConstants.TINKER_ENABLE_ALL, "com.example.jackguo.mybuglytinkerdemo.SampleApplicationLike",                "com.tencent.tinker.loader.TinkerLoader", false);    }}
5. 自定义ApplicationLike,并继承DefaultApplicationLike ;代码示例如下:
/** * @author jack.guo  on 2018/2/5. */public class SampleApplicationLike extends DefaultApplicationLike {    public static final String TAG = "Tinker.SampleApplicationLike";    public SampleApplicationLike(Application application, int tinkerFlags,                                 boolean tinkerLoadVerifyFlag, long applicationStartElapsedTime,                                 long applicationStartMillisTime, Intent tinkerResultIntent) {        super(application, tinkerFlags, tinkerLoadVerifyFlag, applicationStartElapsedTime, applicationStartMillisTime, tinkerResultIntent);    }    @Override    public void onCreate() {        super.onCreate();        // 这里实现SDK初始化,appId替换成你的在Bugly平台申请的appId        // 调试时,将第三个参数改为true        Bugly.init(getApplication(), "12035232cf", true);    }    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)    @Override    public void onBaseContextAttached(Context base) {        super.onBaseContextAttached(base);        // you must install multiDex whatever tinker is installed!        MultiDex.install(base);        // 安装tinker        // TinkerManager.installTinker(this); 替换成下面Bugly提供的方法        Beta.installTinker(this);    }    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)    public void registerActivityLifecycleCallback(Application.ActivityLifecycleCallbacks callbacks) {        getApplication().registerActivityLifecycleCallbacks(callbacks);    }}

==到此为止,你的热更新demo配置已经基本完成了。==

接下来就在bugly后台添加你的APP,添加成功会生成APP Id,把SampleApplicationLike的onCreate()中替换成你的id就可以了。
bugly地址:https://bugly.qq.com/v2/index

6. 其他配置:

(1)混淆配置:

为了避免混淆SDK,在Proguard混淆文件中增加以下配置:

-dontwarn com.tencent.bugly.**-keep public class com.tencent.bugly.**{*;}

如果你使用了support-v4包,你还需要配置以下混淆规则:

-keep class android.support.**{*;}

(2)AndroidManifest.xml配置:(无需配置)

==注:1.3.1及以上版本,可以不用进行以上配置,aar已经在AndroidManifest配置了,并且包含了对应的资源文件。==

如需更多配置,请点击进入官网查看详细文档:Bugly Android热更新使用指南

(完)

更多相关文章

  1. NPM 和webpack 的基础使用
  2. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  3. android中判断网络和WIFI是否连接
  4. android中判断网络和WIFI是否连接
  5. android背景选择器selector用法汇总
  6. Android(安卓)利用Android(安卓)studio打包jar包
  7. TensorFlow集成Android工程的框架
  8. android 超简单的下载功能,进度条 异步下载
  9. vim+ctags+cscope 打造Android源码阅读工具

随机推荐

  1. [置顶] Android(安卓)轻松实现仿QQ消息下
  2. Android以最简单的方式接入支付
  3. android核心基础(1)_什么是3G
  4. Android有效获取状态栏(StatusBar)高度的
  5. Android 崩溃分析 方法论
  6. android之多线程
  7. Android安全模型之Android安全机制(进程沙
  8. 学习 Android 平台 OpenGL ES API,了解 Op
  9. Google手机OS大战:Android挟免费开源优势
  10. Android Market v3.3.11 APK 正式释出,增