Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass command line options to the emulator in Android Studio?

I use Android Studio 2.1.3. When I run an Android app I pick an AVD, where can I pass command line options such as -http-proxy? I don't even find a way in the run configuration.

like image 713
Maxime Laval Avatar asked Sep 08 '16 17:09

Maxime Laval


People also ask

How do I run an emulator from command prompt?

Starting the emulator Use the emulator command to start the emulator, as an alternative to running your project or starting it through the AVD Manager. Here's the basic command-line syntax for starting a virtual device from a terminal prompt: emulator -avd avd_name [ {- option [ value ]} … ]

How do I open the command line in Android Studio?

Open a command line—from Android Studio, select View > Tool Windows > Terminal—and navigate to the directory where your unsigned APK is located. zipalign ensures that all uncompressed data starts with a particular byte alignment relative to the start of the file, which may reduce the amount of RAM consumed by an app.

What is command line in Android Studio?

The Android SDK Command-Line Tools package contains various tools for building and debugging Android apps. It is released concurrently with Android Studio and is installed in the android_sdk /cmdline-tools/ version /bin/ directory.


1 Answers

I found a hacky solution to add parameters to the Android Studio AVD.

Android Studio by default uses the binary $ANDROID_SDK/emulator/emulator. In my case the path in MacOS is /Users/martin/Library/Android/sdk/emulator/emulator. What I did is:

  1. Rename the binary to emulator-original

  2. Create a bash script with the name emulator that contains:

    /Users/<YOUR_USERNAME>/Library/Android/sdk/emulator/emulator-original <PARAMS> $@```  
  3. Change the script permissions with chmod +x emulator

Now Android Studio runs my script instead of running the binary

Update: try Stef's solution first, it looks better than this hack

like image 164
MartinCR Avatar answered Sep 20 '22 00:09

MartinCR