Quality of life CLI tips for Android Mobile App Development - 1

I'm not a mobile app developer, but for my day-to-day job, I'm responsible for creating APIs that's consumed by mobile client. This means I often have both iOS and Android simulator running at the same time.

Normally, you would have to open both XCode and Android Studio respectively as that is how things are supposed to work: start each IDE, build the app in the IDE, and then run the app in the simulator through the IDE.

I don't like to do things this way, it is inefficient and will (most likely) consume lots of resources. Therefore, I developed my own scripts to do things efficiently in the command line. In this article, I will share some of the scripts I use when working with Android code, I believe these scripts are huge quality of life improvement for developers like me who need to run mobile apps in a simulator as part of their day-to-day job, but not necessarily modify or commit to the mobile code. Some of the things discussed in this article have already been mentioned briefly last year.

If you are not familiar with deep links, check out article about deep link on android.

I will cover several methods I have found to test deep links.

function sendDeepLink() {
# Define your deep link here the first param passed to this function will
# be the actual deep link

nc localhost 5554 << _EOF > /dev/null 2>&1
auth $(cat $HOME/.emulator_console_auth_token)

sendDeepLink "$URL"

The script above utilize telnet, it is a somewhat ancient protocol that's still implemented in Android Emulators. You can potentially use telnet for many different things. For our purpose, I'm just showing how to send SMS through telnet.

Starting from the line that begins with nc, here I'm using nc to connect to Android telnet port, which is localhost:5554. I'm also utilizing Heredoc, I'm passing the emulator_console_auth_token as the first thing and authenticate the telnet connection: auth $(cat $HOME/.emulator_console_auth_token). If we don't do this, we will have to copy & paste whatever is in the auth_token file manually.

Once authenticated to telnet, we will start sending the fake SMS, because this line sms send SENDER_NAME $URL is still part of the Heredoc, so it is ran through the telnet connection. This is instructing the telnet terminal to send the $URL to the emulator as SENDER_NAME. And we close the Heredoc using _EOF which is what we used to open the Heredoc.

If you would like to know more about telnet, you can checkout the Android docs on telnet console commands

adb shell am start -W -a android.intent.action.VIEW -d "your deep link url"

This is probably way more easier than the telnet method. However, I don't have full Understanding of how this works (and I haven't tested), so I'm not going to try and explain it.

I found Telnet and ADB are really good tools to help Android development. Hope you find the tips above helpful.