Search in sources :

Example 1 with MergeCallback

use of com.taobao.atlas.dexmerge.MergeCallback in project atlas by alibaba.

the class Updater method update.

public static void update(final Context context) {
    File updateInfo = new File(context.getExternalCacheDir(), "update.json");
    if (!updateInfo.exists()) {
        Log.e("update", "更新信息不存在,请先 执行 buildTpatch.sh");
        toast("更新信息不存在,请先 执行 buildTpatch.sh", context);
        return;
    }
    String jsonStr = new String(FileUtils.readFile(updateInfo));
    UpdateInfo info = JSON.parseObject(jsonStr, UpdateInfo.class);
    File patchFile = new File(context.getExternalCacheDir(), "patch-" + info.updateVersion + "@" + info.baseVersion + ".tpatch");
    try {
        //            AtlasUpdater.update(info, patchFile);
        PatchMerger patchMerger = new PatchMerger(info, patchFile, new MergeCallback() {

            @Override
            public void onMergeResult(boolean result, String bundleName) {
                if (result) {
                    toast(bundleName + "merge success!", context);
                } else {
                    toast(bundleName + "merge failed!", context);
                }
            }
        });
        try {
            patchMerger.merge();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Log.e("mergeOutputs:", String.valueOf(patchMerger.mergeOutputs.size()));
        PatchInstaller patchInstaller = new PatchInstaller(patchMerger.mergeOutputs, info);
        patchInstaller.install();
        Log.e("update", "update success");
        toast("更新成功,请重启app", context);
    } catch (Throwable e) {
        e.printStackTrace();
        toast("更新失败, " + e.getMessage(), context);
    }
}
Also used : MergeCallback(com.taobao.atlas.dexmerge.MergeCallback) PatchMerger(com.taobao.atlas.update.util.PatchMerger) PatchInstaller(com.taobao.atlas.update.util.PatchInstaller) IOException(java.io.IOException) File(java.io.File) UpdateInfo(com.taobao.atlas.update.model.UpdateInfo)

Example 2 with MergeCallback

use of com.taobao.atlas.dexmerge.MergeCallback in project atlas by alibaba.

the class AtlasUpdater method update.

/**
     * 更新主入口
     * @param updateInfo  更新的基础信息
     * @param patchFile   tpatch包
     * @throws MergeException
     * @throws BundleException
     */
public static void update(UpdateInfo updateInfo, File patchFile) throws MergeException, BundleException {
    MergeCallback mergeCallback = new MergeCallback() {

        @Override
        public void onMergeResult(boolean result, String bundleName) {
            if (result) {
                Log.d("[dexmerge]", "merge bundle " + bundleName + " success ");
            } else {
                Log.e("[dexmerge]", "merge bundle " + bundleName + " fail ");
            }
        }
    };
    PatchMerger patchMerger = new PatchMerger(updateInfo, patchFile, mergeCallback);
    try {
        patchMerger.merge();
    } catch (IOException e) {
        e.printStackTrace();
    }
    PatchInstaller patchInstaller = new PatchInstaller(patchMerger.mergeOutputs, updateInfo);
    patchInstaller.install();
    new PatchCleaner().clearUpdatePath(updateInfo.workDir.getAbsolutePath());
}
Also used : PatchCleaner(com.taobao.atlas.update.util.PatchCleaner) MergeCallback(com.taobao.atlas.dexmerge.MergeCallback) PatchMerger(com.taobao.atlas.update.util.PatchMerger) PatchInstaller(com.taobao.atlas.update.util.PatchInstaller) IOException(java.io.IOException)

Aggregations

MergeCallback (com.taobao.atlas.dexmerge.MergeCallback)2 PatchInstaller (com.taobao.atlas.update.util.PatchInstaller)2 PatchMerger (com.taobao.atlas.update.util.PatchMerger)2 IOException (java.io.IOException)2 UpdateInfo (com.taobao.atlas.update.model.UpdateInfo)1 PatchCleaner (com.taobao.atlas.update.util.PatchCleaner)1 File (java.io.File)1