I have a weird problem with the Android emulator. I have created a virtual device through Android AVD manager (newly created emulator with platform 2.1 and API level 7). I have tried with standard settings and with added hardware parameter for larger (256 MB) device RAM size but nothing changed.
I need to come files to the system partition to test a project (called haggle), but for some reason the system partition has no space from start.
aa a@aa开发者_StackOverflow中文版a /home/haggle-0.2-android
$ adb -s emulator-5554 shell
# df
df
/dev: 47084K total, 0K used, 47084K available (block size 4096)
/sqlite_stmt_journals: 4096K total, 0K used, 4096K available (block size 4096)
/system: 73600K total, 73600K used, 0K available (block size 4096)
/data: 65536K total, 18464K used, 47072K available (block size 4096)
/cache: 65536K total, 1156K used, 64380K available (block size 4096)
As you can see the system partition has 0K space available. When a connect a non-rooted HTC Nexus One and do the same I get these values:
/dev: 108896K total, 0K used, 108896K available (block size 4096)
/sqlite_stmt_journals: 4096K total, 0K used, 4096K available (block size 4096)
/system: 148480K total, 116364K used, 32116K available (block size 4096)
/data: 200960K total, 22296K used, 178664K available (block size 4096)
/cache: 97280K total, 1852K used, 95428K available (block size 4096)
/sdcard: 3864064K total, 118496K used, 3745568K available (block size 32768)
Why does the system partition on the emulator have 0K free space from beginning, and what can I do to change that? Even if I make the partition write-able with mount/remount I get the same 0K values.
Any tips?
Found the answer :)
When starting the emulator you can specify the partition size by -partition-size x emulator_name.
done through the terminal that is. Example:
emulator -partition-size 125 @AVD1
OR
emulator -partition-size 125 -avd AVD1
Note that the size must be bigger than your current system partition size. For the Android4.0.3 emulator the default size is already 168 so set your new partition-size to something bigger like 256
Nowadays, -partition-size
changes the /system/data partition, but not the /system partition space.
If you want to install the full GApps, for example, you will need more space.
The general procedure to do so in Unix is documented at https://unix.stackexchange.com/questions/104790/how-to-setup-a-growable-loopback-device
In short:
- Make a copy of system.img so that you don't modify the original one in the SDK (
cp system.img system-extended.img
) - Grow your
system-extended.img
to your desired size (e.g.,truncate system-extended.img -s 2G
) - Resize the inner ext4 filesystem (
resizefs system-extended.img
ORresize2fs system-extended.img
) - Use the new img file when calling the emulator via the
-system <path/to/system-extended.img>
parameter. The-writable-system
parameter may also come in handy for you.
I had problem trying @ssice's answer on Android Q (Android TV if that matters).
Apparently the system.img is now a GPT partitioned disk image.
You can confirm this by running file system.img
:
system.img: DOS/MBR boot sector; partition 1 : ID=0xee, start-CHS (0x0,0,2), end-CHS (0x87,130,59), startsector 1, 2177023 sectors, extended partition table (last)
If this is also the case for you, here's what you can do on Linux:
- Resize system.img:
truncate -s 3G system.img
- Recreate the partition table and create a partition that spans across it:
fdisk system.img
g
for new GPT partition tablen
for a new partition. choose partition number 1; accept defaults for a partition that will span the entire diskw
for saving the changes
$ fdisk system.img
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): g
Created a new GPT disklabel (GUID: 2E6B87B6-5492-47E0-A164-A148E24445A0).
Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-6291422, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-6291422, default 6291422):
Created a new partition 1 of type 'Linux filesystem' and of size 3 GiB.
Command (m for help): w
The partition table has been altered.
Syncing disks.
- Mount
system.img
as a loopback devicelosetup -fP system.img
- grab allocated
/dev/loopN
(for example,/dev/loop1
) fromlosetup -a | grep system.img
- Resize filesystem:
resize2fs /dev/loop1p1
(/dev/loop1
partition 1)
For Android 10 emulator built from sources the following solutions works well:
$ emulator -partition-size 8192 -writable-system
If an emulator has been launched before it is necessary to clear out and rebuild it again:
$ make installclean
$ rm out/target/product/generic_x86_64/*qcow2
$ make
$ emulator -partition-size 8192 -writable-system
Successfully tested on the aosp_car_x86_64 target.
I found the problem. The SDK_MANAGER folder was inside a NON-STANDARD characters directory in my D disk (D:/ასერ/?dwe + joan/SKD_MANAGER
)
and thats why it couldnt get the correct partition size. I moved **SDK_MANAGER* to D:/**SDK_MANAGER* and problem solved!
( so, who has the error messages like "Invalid system partition size" or "panick: could not open avd1", this post might help)
精彩评论