对Android的模拟器,如果要修改其system分区里的文件,除了remount之外,还需要对数据进行持久化——因为默认情况下emulator会以只读的形式加载system.img,即便remount之后对其进行的修改也不会实际被保存下来。

下面介绍一种简单的方法对数据进行持久化:


1. 创建一个AVD,在这个例子里,我们用Android 4.3.1,命名为Android4.3.1。

2. 将SDK(E:\Android\sdk\system-images\android-18\default\armeabi-v7a)下这个系统的system.img,kernel-qemu,ramdisk.img文件拷贝至emulator的目录下一份E:\Android\sdk\.android\avd\Android4.3.1.avd.目录结构如下:



3.修改hardware-qemu.ini文件的kernel.path,disk.ramdisk.path ,disk.systemPartition.initPath字段路径

hw.cpu.arch = armhw.cpu.model = cortex-a8hw.cpu.ncore = 2hw.ramSize = 500hw.screen = touchhw.mainKeys = truehw.trackBall = falsehw.keyboard = truehw.keyboard.lid = falsehw.keyboard.charmap = qwerty2hw.dPad = falsehw.gsmModem = truehw.gps = truehw.battery = truehw.accelerometer = truehw.audioInput = truehw.audioOutput = truehw.sdCard = truehw.sdCard.path = E:\Android\sdk\.android\avd\Android4.3.1.avd/sdcard.imgdisk.cachePartition = truedisk.cachePartition.path = E:\Android\sdk\.android\avd\Android4.3.1.avd/cache.imgdisk.cachePartition.size = 66mhw.lcd.width = 480hw.lcd.height = 800hw.lcd.depth = 16hw.lcd.density = 240hw.lcd.backlight = truehw.gpu.enabled = falsehw.gpu.mode = autohw.gpu.blacklisted = nohw.initialOrientation = portraithw.camera.back = nonehw.camera.front = nonevm.heapSize = 32hw.sensors.light = truehw.sensors.pressure = truehw.sensors.humidity = truehw.sensors.proximity = truehw.sensors.magnetic_field = truehw.sensors.orientation = truehw.sensors.temperature = truehw.useext4 = truekernel.path = E:\Android\sdk\.android\avd\Android4.3.1.avd\/kernel-qemukernel.parameters =  androidboot.hardware=goldfish android.checkjni=1kernel.newDeviceNaming = nokernel.supportsYaffs2 = yesdisk.ramdisk.path = E:\Android\sdk\.android\avd\Android4.3.1.avd\/ramdisk.imgdisk.systemPartition.initPath = E:\Android\sdk\.android\avd\Android4.3.1.avd\/system.imgdisk.systemPartition.size = 218mdisk.dataPartition.path = E:\Android\sdk\.android\avd\Android4.3.1.avd/userdata-qemu.imgdisk.dataPartition.size = 500mavd.name = Android4.3.1



4. 手工指定挂载参数地启动它:

C:\Users\Administrator>emulator -avd Android4.3.1 -qemu -nand system,size=0x1f400000,file=E:\Android\sdk\.android\avd\Android4.3.1.avd\system.img

其中,0x1f400000是指给/system分区500MB的空间。


4. 系统启动后,adb remount一下,然后通过adb shell mount可以看到system分区已经变为rw了。

C:\Users\Administrator>adb shell mountrootfs / rootfs ro 0 0tmpfs /dev tmpfs rw,nosuid,mode=755 0 0devpts /dev/pts devpts rw,mode=600 0 0proc /proc proc rw 0 0sysfs /sys sysfs rw 0 0none /acct cgroup rw,cpuacct 0 0tmpfs /mnt/secure tmpfs rw,mode=700 0 0tmpfs /mnt/asec tmpfs rw,mode=755,gid=1000 0 0tmpfs /mnt/obb tmpfs rw,mode=755,gid=1000 0 0none /dev/cpuctl cgroup rw,cpu 0 0/dev/block/mtdblock0 /system yaffs2 rw 0 0/dev/block/mtdblock2 /data yaffs2 rw,nosuid,nodev 0 0/dev/block/mtdblock3 /cache yaffs2 rw,nosuid,nodev 0 0/dev/block/vold/179:0 /storage/sdcard vfat rw,dirsync,nosuid,nodev,noexec,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0/dev/block/vold/179:0 /mnt/secure/asec vfat rw,dirsync,nosuid,nodev,noexec,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0tmpfs /storage/sdcard/.android_secure tmpfs ro,size=0k,mode=000 0 0


5. 现在可以对/system分区做持久化修改。


6. 修改完成后,关掉模拟器。之后启动即可。


emulator说明如下:

C:\Users\Administrator>emulator -help-disk-images  The emulator needs several key image files to run appropriately.  Their exact location depends on whether you're using the emulator  from the Android SDK, or not (more details below).  The minimal required image files are the following:    kernel-qemu      the emulator-specific Linux kernel image    ramdisk.img      the ramdisk image used to boot the system    system.img       the *initial* system image    userdata.img     the *initial* data partition image  It will also use the following writable image files:    userdata-qemu.img  the persistent data partition image    system-qemu.img    an *optional* persistent system image    cache.img          an *optional* cache partition image    sdcard.img         an *optional* SD Card partition image    snapshots.img      an *optional* state snapshots image  If you use a virtual device, its content directory should store  all writable images, and read-only ones will be found from the  corresponding platform/add-on directories. See -help-sdk-images  for more details.  If you are building from the Android build system, you should  have ANDROID_PRODUCT_OUT defined in your environment, and the  emulator shall be able to pick-up the right image files automatically.  See -help-build-images for more details.  If you're neither using the SDK or the Android build system, you  can still run the emulator by explicitely providing the paths to  *all* required disk images through a combination of the following  options: -sysdir, -datadir, -kernel, -ramdisk, -system, -data, -cache  -sdcard and -snapstorage.  The actual logic being that the emulator should be able to find all  images from the options you give it.  For more detail, see the corresponding -help-


更多相关文章

  1. 一款常用的 Squid 日志分析工具
  2. GitHub 标星 8K+!一款开源替代 ls 的工具你值得拥有!
  3. RHEL 6 下 DHCP+TFTP+FTP+PXE+Kickstart 实现无人值守安装
  4. Linux 环境下实战 Rsync 备份工具及配置 rsync+inotify 实时同步
  5. Android(安卓)Studio动态调试smali
  6. NDK集成libjpeg和libpng
  7. androidStudio 4.0 打包jar、找不到jar一系列问题、classes.jar
  8. Android加壳native实现
  9. 仿豌豆荚实现android连接pc方法

随机推荐

  1. 技术干货 | mPaaS 框架下如何使用 Crash
  2. 排查指南 | mPaaS 小程序被卡在了三个蓝
  3. 技术干货 | “选图预览并上传”的场景如
  4. 排查指南 | 当 mPaaS 小程序真机扫码时提
  5. 技术干货 | 深度解构 Android 应用面临紧
  6. 技术干货 | mPaaS 小程序高玩带你起飞:客
  7. 绝密文档公开!首次揭秘数栈导航设计思路
  8. 腾讯企业邮箱启用超大附件
  9. 货运物流移动端解决方案:为货运物流行业打
  10. 开发技巧 | mPaaS 小程序自定义事件,如何