One of the biggest advantages of using the Android Emulator is that we can do almost everything as if we were on a physical device. Additionally, here we have a large set of configurations that allow us to replicate a large variety of configurations, namely: architectures, Android versions, hardware profiles, etc.
If you create an AVD (Android Virtual Device) and go to the native settings application and look for your SIM information, you should see something identical to this:
If you look closely to the SIM number it seems to be a default number with +1 as the country code and a mix of random numbers. However, if we look closely the last four digits seem oddly familiarly.
If you enter on your console adb devices and assuming that you’ve got only one created you’ll see:
$adb devices List of devices attached emulator-5554 device
So, this last 4 four digits basically correspond to the port in which the emulator is connected… and the first ones… let’s say that they are the default number used by Android:
static const char kDefaultPhonePrefix = “1555521”;
In order to see all of your device (emulator) properties you can enter the following command:
adb shell getprop
And to filter the ones only related to the SIM card we just need to:
adb shell getprop | grep "gsm"
[gsm.current.phone-type]:  [gsm.defaultpdpcontext.active]: [true] [gsm.network.type]: [LTE] [gsm.operator.alpha]: [Android] [gsm.operator.iso-country]: [us] [gsm.operator.isroaming]: [false] [gsm.operator.numeric]:  [gsm.sim.operator.alpha]:  [gsm.sim.operator.iso-country]: [us] [gsm.sim.operator.numeric]:  [gsm.sim.state]: [LOADED] [gsm.version.baseband]: [188.8.131.52] [gsm.version.ril-impl]: [android reference-ril 1.0]
It seems that there are some older emulators where you can define each one of these properties individually via setprop command:
adb shell setprop gsm.sim.operator.iso-country pt
Unfortunately, this seems to not work on the latest version of the emulator; so if it doesn’t we need to follow a second approach.
After a lot of try and error (a special thanks to here that grabbed his pickax and joined me on this quest), we’ve managed to discover an easy way to update the SIM number on the emulator.
- First, you need to check if you’ve got the ANDROID_HOME path defined:
It should print your Android SDK path:
In case you don’t have your ANDROID_HOME defined you’ll need to set it. First, you need to find where your Android SDK folder is located. You can easily check this by opening Android Studio and after selecting your project right click on “Open Module Settings” and then on the left bar select on “SDK Location”.
After copying it, open a new console and type:
And then add it to the environment variables PATH:
and save it (so you don’t need to enter these commands every time you open a new console):
- Next, we will set the EMULATOR variable as well as we did for the ANDROID_HOME :
and then export the LD_LIBARY_PATH
- Now you just need to set the phone_number option with the phone number that you want to use on the emulator:
$EMULATOR//qemu/darwin-x86_64/qemu-system-x86_64 -avd <your_avd_name> -phone-number 351990000001
In order to get
you’ll need to see all the AVD’s available:
In my case, it will output Pixel_2_API_Q, so my command will be:
$EMULATOR//qemu/darwin-x86_64/qemu-system-x86_64 -avd Pixel_2_API_Q -phone-number 351990000001
No need to add the “+” or “00” for the country code, Android will do that automatically for you.
Do you have a better approach? Something didn’t quite work with you? Feel free to send me a message 🙂.