bugly 接入后------我想记录的点

2019-09-27  本文已影响0人  一个冬季
参考文章

APG 不支持3.6.0,Gradle 5.x

无法使用的版本说明

APG 3.3.3 无法使用 tinker lib 1.9.14.10, tinker-support版本1.2.1

开发的版本&&bugly版本

gradle版本:3.3.1
com.tencent.bugly:tinker-support:1.2.0
com.tencent.bugly:crashreport_upgrade:1.4.5
com.tencent.tinker:tinker-android-lib:1.9.14.3

问题

1、如何不在build/bakApk目录下,出现那么多的APK文件
2、在minSdkVersion为21 无法生成base包
3、接入了bugly后,会跟我自己写的全局捕获异常冲突么?
4、isProtectedApp 的解释
5、自己application的代码,所有代码必须放到代理的SampleApplicationLike里面?
6、编译补丁包的流程
7、打包完补丁&&上传后是否会立即生效?
8、发包的时候 isProtectedApp = false && 加固 ,打补丁包 isProtectedApp 改为true 会有效果么?
9、可以通过热更的方式,更改APP名字,APP图标,APP启动图么?

1、如何不在build/bakApk目录下,出现那么多的APK文件
tinkerSupport {
    enable = false
    overrideTinkerPatchConfiguration = false
}
2、在minSdkVersion为21 无法生成base包
tinkerPatch {
    removeLoaderForAllDex = true
    allowLoaderInAnyDex =true
    ignoreWarning = true
}
3、接入了bugly后,会跟我自己写的全局捕获异常冲突么?

我的写法是先初始化bugly,然后再初始化自己的异常捕获的类,所以没有冲突。

public class MyApplication extends TinkerApplication{
    ...省略
}

我是集成了TinkerApplication,TinkerApplication也是集成Application的

public abstract class TinkerApplication extends Application {

    protected TinkerApplication(int tinkerFlags, String delegateClassName,
                                String loaderClassName, boolean tinkerLoadVerifyFlag) {
        this.tinkerFlags = tinkerFlags;
        this.delegateClassName = delegateClassName;
        this.loaderClassName = loaderClassName;
        this.tinkerLoadVerifyFlag = tinkerLoadVerifyFlag;
    }

    private void loadTinker() {
        try {
            //reflect tinker loader, because loaderClass may be define by user!
            Class<?> tinkerLoadClass = Class.forName(loaderClassName, false, TinkerApplication.class.getClassLoader());
            Method loadMethod = tinkerLoadClass.getMethod(TINKER_LOADER_METHOD, TinkerApplication.class);
            Constructor<?> constructor = tinkerLoadClass.getConstructor();
            tinkerResultIntent = (Intent) loadMethod.invoke(constructor.newInstance(), this);
        } catch (Throwable e) {
            //has exception, put exception error code
            tinkerResultIntent = new Intent();
            ShareIntentUtil.setIntentReturnCode(tinkerResultIntent, ShareConstants.ERROR_LOAD_PATCH_UNKNOWN_EXCEPTION);
            tinkerResultIntent.putExtra(INTENT_PATCH_EXCEPTION, e);
        }
    }

    这里是获取我们的代理类 SampleApplicationLike
    private ITinkerInlineFenceBridge createInlineFence(int tinkerFlags,
                                                       String delegateClassName,
                                                       boolean tinkerLoadVerifyFlag,
                                                       long applicationStartElapsedTime,
                                                       long applicationStartMillisTime,
                                                       Intent resultIntent) {
        try {
            final Class<?> inlineFenceClazz = Class.forName(
                    "com.tencent.tinker.entry.TinkerApplicationInlineFence",
                    true, super.getClassLoader());
            final Constructor<?> ctor = inlineFenceClazz.getConstructor(int.class, String.class,
                    boolean.class, long.class, long.class, Intent.class);
            ctor.setAccessible(true);
            return (ITinkerInlineFenceBridge) ctor.newInstance(tinkerFlags, delegateClassName,
                    tinkerLoadVerifyFlag, applicationStartElapsedTime,
                    applicationStartMillisTime, resultIntent);
        } catch (Throwable thr) {
            throw new TinkerRuntimeException("fail to create inline fence instance.", thr);
        }
    }


    private void onBaseContextAttached(Context base) {
        try {
            final long applicationStartElapsedTime = SystemClock.elapsedRealtime();
            final long applicationStartMillisTime = System.currentTimeMillis();
            loadTinker();
            创建代理类
            mBridge = createInlineFence(tinkerFlags, delegateClassName,
                    tinkerLoadVerifyFlag, applicationStartElapsedTime, applicationStartMillisTime,
                    tinkerResultIntent);
            调用代理类的 attachBaseContext
            mBridge.attachBaseContext(this, base);
            //reset save mode
            if (useSafeMode) {
                ShareTinkerInternals.setSafeModeCount(this, 0);
            }
        } catch (TinkerRuntimeException e) {
            throw e;
        } catch (Throwable thr) {
            throw new TinkerRuntimeException(thr.getMessage(), thr);
        }
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        此处bugly开始设置捕获异常的地方
        Thread.setDefaultUncaughtExceptionHandler(new TinkerUncaughtHandler(this));
        去创建代理类
        onBaseContextAttached(base);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        if (mBridge != null) {
            mBridge.onCreate(this);
        }
    }
}
4、isProtectedApp 的理解

加固的app怎么热更新

isProtectedApp = true,表示你打出的基础包,是准备拿去加固的。所以流程是
基础包----->加固----->重新签名----->上线
当线上遇到BUG,先修复bug----->重新拿出基础包(不是加固的)----->生成插件----->发布。
isProtectedApp = true仍旧不需要改变

5、自己application的代码,所有代码必须放到代理的SampleApplicationLike里面?

关于使用腾讯热补丁库Tinker的问题

是的没错,必须要全部放到SampleApplicationLike里面,自定义的application,只能含有

public class BaseApplication extends TinkerApplication {
    public BaseApplication () {
        super(ShareConstants.TINKER_ENABLE_ALL, THINKER_APPLICATION_LIKE, "com.tencent.tinker.loader.TinkerLoader", false);
    }
}

现在我们的代码,全部都在SampleApplicationLike ,可能有人会问,我要怎么跟代理类的SampleApplicationLike 进行交互呢?我们可以这样

public class SampleApplicationLike extends DefaultApplicationLike implements Application.ActivityLifecycleCallbacks {
    private String name;
    ....省略get/set();
}


某处activity里面 获取name
Log.i("TAG",((SampleApplicationLike )TinkerManager.getTinkerApplicationLike()).getName());
6、编译补丁包的流程

基准版(bug版本)上线(assembleRelease--->bakApk目录copy出文件目录进行保存,将APK拿去上线)----->产品说发现BUG------>开始修复BUG&&运行检查------>重新拿出基础包(不是加固的)----->修改tinker-support-gradle-----编译补丁包(Tasks---->tinker-support--->buildTinkerPatchRelease)

7、打包完补丁&&上传后是否会立即生效?

在我多次测试中,发现有时候会出现补丁不会立即下发的情况,需要等个5-8分钟左右

8、发包的时候 isProtectedApp = false && 加固,打补丁包 isProtectedApp 改为true 会有效果么?

有效果。如果你打补丁包的时候,依旧isProtectedApp = false,就会补丁失败

9、可以通过热更的方式,更改APP名字,APP图标,APP启动图么?

我尝试过,不行

上一篇 下一篇

猜你喜欢

热点阅读