Tencent / tinker

Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.
Other
17.13k stars 3.33k forks source link

疑问: 关于so的abi类型判断, 阿里Sophix热修复方案有一种判断方式,不知是否可行? #1486

Open yaowen369 opened 3 years ago

yaowen369 commented 3 years ago

关于so的修复,Tinker是需要使用者主动调用 TinkerLoadLibrary.java 中api去调用。 并且abi类型需要使用者外部主动传入, tinker的wiki上面表示这么做是因为 部分手机判断不准确. 但是 在 阿里的 Sophix热修复方案中,他们使用了 下述代码来判断 abi的类型。

static {
    try {
        PackageManager pm = mApp.getPackageManager();
        if (pm != null) {
            ApplicationInfo mAppInfo = pm.getApplicationInfo(mApp.getPackageName(), 0);
            if (mAppInfo != null) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {  //sdk >= 21
                    Field thirdField = ApplicationInfo.class.getDeclaredField("primaryCpuAbi");
                    thirdField.setAccessible(true);
                    String cpuAbi = (String) thirdField.get(mAppInfo);
                    primaryCpuAbis = new String[]{cpuAbi};
                } else {  //sdk < 21
                    primaryCpuAbis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
                }
            }
        }

    } catch (Throwable t) {
        LogTool.e(TAG, "SOPatchManger static blook", t);
    }
}

参见《深入探索Android 热修复技术原理》 一书. 电子工业出版社,2018年8月第1版, 第5章 5.4 如何正确复制补丁so库 (P173-P174).

那么这种方式你们验证过吗?还会存在兼容性问题吗? Tinker 后序是否考虑主动帮用户去判断abi类型?

liumazi commented 12 months ago

如果判断abi可能不准 那使用者又该如何判断abi呢