Skip to content

Instantly share code, notes, and snippets.

@tw-Frey
Last active July 28, 2022 06:00
Show Gist options
  • Select an option

  • Save tw-Frey/4425a30f62a3d474009350a7e63c1e88 to your computer and use it in GitHub Desktop.

Select an option

Save tw-Frey/4425a30f62a3d474009350a7e63c1e88 to your computer and use it in GitHub Desktop.
如何 push 檔案到 Android Emulator 的 /system (USE -writable-system)

因為項目需要
要調整 /system/framework/framework-res.apk
網路上可以查到很多方法寫入 /system (下面會再補充)
但因為 Android Emulator 不斷更新
很多方法已經失效 (有的方法以前有用過能 work, 現在已經不行了)
後來注意到 這篇 (Read only file system on Android) 回應
才想起 Emulator 有個參數: -writable-system
為了寫入 system partition 新增的
要注意是

-writable-system

Use this option to have a writable system image during your emulation session. To do so:

  1. Start a virtual device with the -writable-system option.
  2. Enter the adb remount command from a command terminal to tell the emulator to remount system/ as read/write (it’s mounted as read-only by default).

Note that using this flag will create a temporary copy of the system image that can be very large (several hundred MBs), but will be destroyed when the emulator exits.

所以會有種情況就是:
使用 -writable-system 開啟 AVD 寫入資料後 關閉AVD
然後 正常地 (from GUI) 開啟 AVD 是看不到上面寫入的資料

@tw-Frey
Copy link
Author

tw-Frey commented Oct 31, 2019

  1. 可以在 Android StudioRun ConfigurationsAndroid AppDebugger
    LLDB Startup Commands 輸入參數,以下操作環境是 command-line

  2. emulator.exe @<AVD Id> -writable-system
    e.g. emulator.exe @Nexus_4_API_21_x86_ -writable-system
    該命令可以任意地方執行,只是記得 emulator.exe 要設好路徑
    其中 AVD Id 可參考以下圖徑

    {441F6BDC-A91B-4109-95EC-C088AC707A4C}
    {CEC1C738-130A-4372-A70B-7858E143DD1B}

  3. adb root

  4. adb remount

  5. adb push <來源檔案> <目的檔案>

  6. 之後使用 AVD 時使用 步驟1 指令,才會套用上述檔案

@tw-Frey
Copy link
Author

tw-Frey commented Oct 31, 2019

參考資料

adb shell stop
adb shell mkdir /data/local/tmp/empty
adb shell mount -o bind /data/local/tmp/empty /system/app/webview
adb shell start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment