美文网首页
kotlin接入bugly tinker 热更新

kotlin接入bugly tinker 热更新

作者: honglei92 | 来源:发表于2019-02-18 10:36 被阅读0次

    build文件

    1.project build.gradle

     //热更新
    classpath "com.tencent.bugly:tinker-support:1.1.5"
    

    2,app build.gradle

    dependencies {
        //工具
        implementation 'com.android.support:multidex:1.0.3'
        implementation 'com.tencent.bugly:crashreport_upgrade:1.3.6'
        // 指定tinker依赖版本(注:应用升级1.3.5版本起,不再内置tinker)
        implementation 'com.tencent.tinker:tinker-android-lib:1.9.11'
    }
    

    application

    1. App.kt
    package com.cnpc.logistics
    
    import com.cnpc.logistics.utils.RootUtil
    import com.cnpc.logistics.utils.T
    import com.tencent.tinker.loader.shareutil.ShareConstants
    import com.tencent.tinker.loader.app.TinkerApplication
    
    //使用热更新时使用当前application类。
    class App : TinkerApplication(ShareConstants.TINKER_ENABLE_ALL, "项目路径.MyTinkerApplicationLike", "com.tencent.tinker.loader.TinkerLoader", false) {
        override fun onCreate() {
            super.onCreate()
            INSTANCE = this
    //        Bugly.init(applicationContext, C.APP_ID_BUGLY, BuildConfig.DEBUG)
        }
    
        companion object {
            private var INSTANCE: App? = null
            fun getInstance(): App = INSTANCE!!
        }
    }
    

    2.MyTinkerApplicationLike.java

    package com.cnpc.logistics;
    
    import android.annotation.TargetApi;
    import android.app.Application;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Build;
    import android.support.multidex.MultiDex;
    
    import com.tencent.bugly.Bugly;
    import com.tencent.bugly.beta.Beta;
    
    /**
     * @author:honglei92
     * @time:2018/7/25
     */
    public class MyTinkerApplicationLike extends com.tencent.bugly.beta.tinker.TinkerApplicationLike {
        public MyTinkerApplicationLike(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(), "你自己的buglyId", false);
        }
    
    
        @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);
        }
    }
    
    

    3,打包

    生成基准包,


    基准包.png

    生成热更新包


    补丁包.png

    其他的参照官方bugly demo。

    4.附录

    1参考文档:https://bugly.qq.com/docs/user-guide/instruction-manual-android-hotfix-demo/

    相关文章

      网友评论

          本文标题:kotlin接入bugly tinker 热更新

          本文链接:https://www.haomeiwen.com/subject/wlooeqtx.html