<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                四、加載補丁 4.1 思路 通過上一篇博文,我們知道dex 保存在這個位置 ``` BaseDexClassLoader–>pathList–>dexElements ``` apk 的classes.dex 可以從應用本身的DexClassLoader 中獲取。 path_dex 的dex 需要new 一個DexClassLoader 加載后再獲取。 分別通過反射取出dex 文件,重新合并成一個數組,然后賦值給盈通本身的ClassLoader 的dexElements 4.2 代碼實現 加載外部dex,我們可以在Application 中操作。 首先新建一個HotPatchApplication,然后在清單文件中配置,順便加上讀取sdcard 的權限,因為補丁就保存在那里。 HotPatchApplication 代碼如下: ``` package com.aitsuki.hotpatchdemo; import android.app.Application;import android.os.Environment;import andr oid.util.Log;import java.io.File;import java.lang.reflect.Array;import j ava.lang.reflect.Field;import dalvik.system.DexClassLoader; /** * Created by hp on 2016/4/6. */ public class HotPatchApplication extends Application { @Override public void onCreate() { super.onCreate(); // 獲取補丁,如果存在就執行注入操作 String dexPath = Environment.getExternalStorageDirectory().getAb solutePath().concat("/patch_dex.jar"); File file = new File(dexPath); if (file.exists()) { inject(dexPath); } else { Log.e("BugFixApplication", dexPath + "不存在"); } } /** * 要注入的dex 的路徑 * * @param path */ private void inject(String path) { try { // 獲取classes 的dexElements Class<?> cl = Class.forName("dalvik.system.BaseDexClassLoader "); Object pathList = getField(cl, "pathList", getClassLoader()); Object baseElements = getField(pathList.getClass(), "dexEleme nts", pathList); // 獲取patch_dex 的dexElements(需要先加載dex) String dexopt = getDir("dexopt", 0).getAbsolutePath(); DexClassLoader dexClassLoader = new DexClassLoader(path, dexo pt, dexopt, getClassLoader()); Object obj = getField(cl, "pathList", dexClassLoader); Object dexElements = getField(obj.getClass(), "dexElements", obj); // 合并兩個Elements Object combineElements = combineArray(dexElements, baseElemen ts); // 將合并后的Element 數組重新賦值給app 的classLoader setField(pathList.getClass(), "dexElements", pathList, combin eElements); //======== 以下是測試是否成功注入================= Object object = getField(pathList.getClass(), "dexElements", pathList); int length = Array.getLength(object); Log.e("BugFixApplication", "length = " + length); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } } /** * 通過反射獲取對象的屬性值 */ private Object getField(Class<?> cl, String fieldName, Object object) throws NoSuchFieldException, IllegalAccessException { Field field = cl.getDeclaredField(fieldName); field.setAccessible(true); return field.get(object); } /** * 通過反射設置對象的屬性值 */ private void setField(Class<?> cl, String fieldName, Object object, O bject value) throws NoSuchFieldException, IllegalAccessException { Field field = cl.getDeclaredField(fieldName); field.setAccessible(true); field.set(object, value); } /** * 通過反射合并兩個數組 */ private Object combineArray(Object firstArr, Object secondArr) { int firstLength = Array.getLength(firstArr); int secondLength = Array.getLength(secondArr); int length = firstLength + secondLength; Class<?> componentType = firstArr.getClass().getComponentType(); Object newArr = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { if (i < firstLength) { Array.set(newArr, i, Array.get(firstArr, i)); } else { Array.set(newArr, i, Array.get(secondArr, i - firstLengt h)); } } return newArr; } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看