Android AVD set custom hardware - android

I am trying to decrease the ridiculous CPU usage of my Android emulator.
Thanks to this answer I found out that the CPU usage can be greatly decreased by disabling audio.
Solutions
I found out there are three ways to run the emulator without audio.
As a command line flag:
$ emulator -avd <name> -noaudio
By editing ~/.android/<name>.avd/config.ini and replacing this line:
hw.audioInput=yes
with these two:
hw.audioInput=no
hw.audioOutput=no
Instead of using the graphical AVD manager, use the following command to create an emulator:
$ android create avd -n <name> -t <target>
Cons
All of these methods have downsides though.
Requires to pass the -noaudio flag each time. This means it can't be run from AVD manager.
config.ini is reset each time an edit is made using AVD manager.
Requires to explicitly set every property of the device instead of just being able to use a preset configuration.
Attempted (failed) solution
I decided it might help to just clone an existing device and disable the audio there.
However¸ this just created ~/.android/devices.xml and I couldn't fine any reference how to disable audio by default nor any ini files containing hardware definitions.
Question
Is it possible to create a predefined hardware configuration that has sound disabled by default? If so, how?

Related

What is command to run android AOSP image in plain QEMU?

I want to test TrustZone feature in mainline QEMU and let QEMU run android image. The TrustZone feature is not in qemu-ranchu which is emulator of android built on top of old version qemu. Qemu-ranchu does not include TrustZone feature. So I have to use plain qemu to run trustzone feature on android.
I already compiled the AOSP with arm64 option and I have following image file: ramdisk.img, system.img, cache.img, userdata.img. I want to use qemu-system-aarch64 run these AOSP images.
Could anyone provide some guide line what command should I use to let qemu run these android images? Thanks in advance.
Although I don't know what "TrustZone" is, I think you are confused - "ranchu" is a hardware definition that the new Emulator can use, and it, in turn is based on a much newer Qemu code base.
In any case, you can see exactly what options are being used to run qemu by the Android Emulator (which "wraps" qemu) by starting it from the command line with the -verbose flag, for example:
~/.android-sdk/tools/emulator -avd Nexus_10_API_19 -verbose
I've had some luck running qemu directly by copying those options, and by experimenting with the values that are printed out by the Emulator "wrapper" code.
BTW, you will first need to use Studio's "AVD Manager" to make an avd to use in that command. More information about the command line use of the Emulator can be found here:
Android Emulator Command Line
Good luck!

Using an auto-proxy configuration script with the android emulator

I need to get the android emulator to use an auto-config proxy script.
I already know the basics of having android emulator utilize a proxy, one must either submit the http-proxy argument when starting the emulator program, or have the http_proxy environmental variable set on the system. (See here http://developer.android.com/tools/help/emulator.html)
However, my company uses an auto configuration script for its proxy, like this:
http://autoproxy.company.org/proxy/west.pac which turns out to be some java script like functions, actually.
So, I need the android emulator to be able to utalize this automatic configuration script. Now, I have tried a few things, such as:
set HTTP_PROXY=http://autoproxy.company.org/proxy/west.pac
and I also tried adding it as the last parameter too.
start /b emulator-x86.exe -netdelay none -netspeed full -avd Nexus_5_API_22_x86 -no-audio -http-proxy %HTTPS_PROXY%
The above gave me the following error:
emulator: http_proxy format unsupported, try 'proxy:port' or username:password#proxy:port'
I can't find much detail on this on Google. Everyone seems to be able to use the tradition proxy means of user:pass#proxy:port but this simply doesn't work. In fact, it ends up getting my windows account locked out!

Is there a way to set AVD Default Language when creating on command line?

I setup a couple of robotium tests and stuff for our CI.
Everthing works fine so far. I just cant figure out how i can define the Default Language for the AVD i creating.
I read Managing AVD but there is no option listed for this.
How you do this when your Robotium Tests also make use of the "searchText" feature, but fail because the emulator runs on different language ?
Using the android avd command also don't show any option for that. I had a quick look in the config files for for AVDs created and there also is no language setting.
You can try to set Android emulator default language on starting command using -change-locale:
emulator -avd <avd-name> -change-locale fr-CA
Relase note - https://androidstudio.googleblog.com/2019/09/emulator-29112-stable.html
Here is one way to switch the language after the emulator was started:
adb shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE EN
source

Changing the Android emulator locale automatically

For automated testing (using Hudson) I have a script that generates a bunch of emulators for many combinations of Android OS version, screen resolution, screen density and language.
This works fine, except for the language part.
I need to find a way to change the Android system locale automatically. Here's some approaches I can think of, in order of preference:
Extracting/editing/repacking a QEMU image directly before starting the emulator
Running some sort of system-locale-changing APK on the emulator after startup
Changing the locale settings on the emulator filesystem after startup
Changing the locale settings in some SQLite DB on the emulator after startup
Running a key sequence (via the emulator's telnet interface) that would open the settings app and change the locale
Manually starting the emulator for each platform version, changing the locale by hand in the settings, saving it and archiving the images for later deployment
Any ideas whether this can be done, either via the above methods or otherwise?
Do you know where locale settings are persisted to/read from by the system?
Solution:
Thanks to dtmilano's info about the relevant properties, and some further investigation on my part, I came up with a solution even better and simpler than all the ideas above!
I have updated his answer below with the details.
Personally I think the simplest way is to start the emulator, probably a clean instance unless you are running integration tests that depends on other applications and then change locale using adb:
$ adb shell '
setprop persist.sys.language en;
setprop persist.sys.country GB;
stop;
sleep 5;
start'
or whatever locale you want to set.
To verify that your change was successful just use
$ adb shell 'getprop persist.sys.language'
You may also want to run emulators on know ports, check my answer in this thread.
Note that you can also set system properties directly when starting the emulator:
emulator -avd my_avd -prop persist.sys.language=en -prop persist.sys.country=GB
This way, you can create a plain old emulator of any type then start it up immediately using the locale of your choice, without first having to make any modifications to the emulator images.
This locale will persist for future runs of the emulator, though of course you can always change it again at startup or during runtime.
Accepted answer doesn't work anymore. persist.sys.language and persist.sys.country are gone from emulator properties.
My solution is to use preinstalled on android emulator "Custom locale" application. Simply send intent with extra language parameter to it as below:
adb shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE EN
More information here - prepare android emulator for UI test automation.
UPDATE: based on comment from Jonas Alves the following command works on API 28+:
adb shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE "en_US" com.android.customlocale2
Seems that Android emulator now supports setting the locale when starting it:
emulator -avd <avd-name> -change-locale fr-CA
Source - https://androidstudio.googleblog.com/2019/09/emulator-29112-stable.html

How to increase storage for Android Emulator? (INSTALL_FAILED_INSUFFICIENT_STORAGE)

I get this sometimes(not often) for one of my projects, couple of classes only
Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE
How do I increase emulator's storage?
On Android Studio
Open the AVD Manager.
Click Edit Icon to edit the AVD.
Click Show Advanced settings.
Change the Internal Storage, Ram, SD Card size as necessary.
Click Finish.
Confirm the popup by clicking yes.
Wipe Data on the AVD and confirm the popup by clicking yes.
Important: After increasing the size, if it doesn't automatically ask you to wipe data, you have to do it manually by opening the AVD's pull-down menu and choosing Wipe Data.
Now start and use your Emulator with increased storage.
Update
This answer is, as I write this, nearly eight years old, and about five years stale. But it's still (as I write this) the "accepted" answer, because it answered the question when it was asked.
The newer answer, that applies to the newer Android Studio tools, can be found here: https://stackoverflow.com/a/35828035/62 -- it's a great answer with screen shots. If you're using Android Studio, ignore the Eclipse answer below.
Original Eclipse-based Answer
I was searching for the answer to this question, and was unsatisfied with the above answers. But then I found the answer, so here it is for future reference:
To summarize (and clarify), in Eclipse, go to "Debug Configurations". You can find that in the drop-down under the "debug" icon. Select "target", and select a preferred emulator target to launch. Then under "additional emulator command line options," add this:
-partition-size 1024
Then CLOSE the emulator (and remove any devices), and click the debug icon, which will launch the preferred emulator you selected. This is important: Eclipse needs to launch the debugger, not AVD.
That fixed the problem for me.
Add the following to the avd config.ini
disk.dataPartition.size=1024MB
Let me know if this works for you also.
I added in the line
Run AVD Manager
Select your AVD and click "Details..." button.
In my case AVD Manager sets disk size as
disk.dataPartition.size=4000M
This invalid value, disk is approx 500MB despite numbers specified.
Go to AVR's folder by path in "AVD details".
Edit it in config.ini to
disk.dataPartition.size=4000MB
and remove all .img files.
Just start emulator by command line as follow:
emulator -avd <your avd name> -partition-size 1024 -wipe-data
I was doing an install of an apk:
adb install /home/me/jones_android-arm.apk
And I was getting an error message telling me that
/data/local/tmp/jones_android-arm.apk
was too big. Using the sdk tools from r15, and ADT 15 I was able to use the AVD manager
to manipulate some of my existing emulator's settings:
Window-> AVD Manager -> (select you virtual machine) -> Edit
then going to the Hardware properties window just below "Skin:" I was able to select
with the Hardware: New button 'Ideal size of partition'. I was not, however, able to
set the value other than to '0'. Undaunted, I went to my ${HOME}/.android/avd directory
There was a 'MyVm.avd' directory. Going into that directory I found a 'config.ini'
file. There was the entry :
disk.dataPartition.size=0
I set this to:
disk.dataPartition.size=1024
.. then went back to the AVD Manager, selected MyVm, selected 'Start', opted to
wipe user data win the dialog following, and was able to run and install.
avd manager has an option "ideal size of system partition", try setting that to 1024MB, or use the commandline launch option that does the same.
fyi, I only encountered this problem with the 4.0 emulator image.
If you have the M1 Mac and the preview version of Android Emulator, then you'll need to go to /Applications/Android Emulator.app/Contents/MacOS/api30-gphone-arm64-v8a/config.ini (as an example) and change the disk.dataPartition.size property to your desired size.
something like this:
The reference is in the GitHub repo.
Best regards.
this problem comes with android 1.5 .. try 2.0 or 2.1 or 2.2
you need to increase virtual memory of emulator
How to increase virtual memory of emulator
emulator -avd "Emulator Name" -partition-size 2024
after then try to install your apk
To resize the storage of the Android emulator in Linux:
1) install qemu
2) Locate the directory containing the img files of the virtual machine. Something like ~/.android/avd/.avd and cd to it.
3) Resize the ext4 images: i.e. for growing from 500Mb to 4Gb execute
qemu-img resize userdata.img +3.5GB
qemu-img resize userdata-qemu.img +3.5GB
4) grow the filesystem:
e2fsck -f userdata.img
resize2fs userdata.img
e2fsck -f userdata-qemu.img
resize2fs userdata-qemu.img
5) For the sd card image, optional: rescue the data:
mkdir 1
mount -o loop sdcard.img 1
cp -a 1 2
umount 1
6) resize the image from 100Mb to Gb:
qemu-img resize sdcard.img +3.9GB
7) re-generate the filesystem:
mkfs.vfat sdcard.img
8) optional: restore the old data:
mount -o loop sdcard.img 1
cp -a 2/* 1
mount -o loop sdcard.img 1
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.junkfoodian"
android:installLocation="preferExternal" // this line can work for Installation error: // // INSTALL_FAILED_INSUFFICIENT_STORAGE
I'm a beginner, but I had that problem while playing around with the "Hello Grid View". I was trying to use my own photos, which were all very large in file size.
The quick fix was to reduce the number of photos, thus reducing the size of the APK file.
But, I guess my follow up question for anybody else who hits this thread is this: How do I attach large files like JPGs and MP3s to an app and make sure they save on the SD Card so the APK remains small?
Update your settings in AVD Manager and start the device by enabling 'Wipe user data'. This worked for me.
I guess you should restart the emulator with "emulator -wipe-data -avd YourAvdName" or check "Wipe User Data" in run configuration if you are using Eclipse.
The only time I've seen this happen it was when the host filesystem was basically out of space. Do you have much free space on the filesystem where the VM's filesystem is stored?
It is defenetly not a appropriate answer, but it is a small hint.
If you want to make use of static files in your App. You should put them as resources or as assets.
But, if U have memory concerns like to keep your APK small, then you need to change your App design in such a way that,
instead of putting them as resources, while running your App(after installation) you can take the files(defenately different files as user may not keep files what you need) from SD Card. For this U can use ContentResolver to take audio, Image files on user selection.
With this you can give the user another feature like he can load audio/image files to the app on his own choice.
you can start the one when selecting one item from the left tree "virtual device" in AVD manager dialog on the platform of eclipse, the start UI has the option "Wipe User Data"
The following approach worked for me
Navigate to your android SDK/tools folder in the terminal window (in case you didn't added the path for it)
Make sure the virtual device you're planning to clean is powered off.
Run the command "./emulator -wipe-data -avd YourAvdName" where YourAvdName is the name of your virtual android device
I am using VSCode and my AVD setup is from an older Android Studio setup that I had not used for a while.
I was able to fix this issue by finding the location where the AVD Images are located and then searching for files that had the text
disk.dataPartition.size
Run a find . -name "avd*" and a grep "disk" * once you find the directory for the AVD.
Modifying the disk.dataPartition.size value in the hardware-qemu.ini file worked for me.
The problem can be solved by changing your partition size of emulator.
Go to the your \Android\Sdk\emulator path and type the following command.
emulator -avd android_emulator_name -partition-size 1500 -wipe-data
Now it will work , you have increased the size of your partition size.
You can observe the change in size by using the following command before and after running the above command.
adb shell df
I'm using bitrise and I increased internal space by passing the parameter '-partition-size 2047' in the AVD step (only if you're using cli)
Example:
/home/user/Android/Sdk/emulator/emulator "#Pixel_6_API_31" "-verbose" "-show-kernel" "-no-audio" "-netdelay" "none" "-no-snapshot" "-wipe-data" "-gpu" "auto" "-no-window" "-no-boot-anim" "-camera-back" "none" "-camera-front" "none" "-partition-size" "2047"
Try choosing project -> clean. A simple clean may fix it up.

Categories

Resources