Select Page
Essential Android SDK Emulator Commands for CLI

Some of us are grumpy old folks who really don’t want or need some heavy IDE just to edit some text files. Some of us are folks that just want to debug or QA an Android App but don’t want or need to install a bunch of extra junk just to do it.

For whatever your reason, you’re here because you want to use the Android SDK’s emulator but you don’t want to deal with the IDE. First off, if you need help installing the Android Emulator via the command line, I wrote an article about that already — read that for basic instructions.

Now that you have the emulator installed, how do you do stuff like install your APK or read the “console” output? When the emulator whines that it needs an update and would you please just launch the SDK so it can update, how do you brazenly ignore it and update via CLI? Well, let me show you a few helpful commands.

Please note that all these instructions assume that you are in your ‘android’ folder. That would be where you unpacked the SDK zip and has the “emulator”, “platforms”, “tools”, and a few other directories.

Updating via the CLI

Let’s start easy. Assuming you’re in your android directory:

cd tools
./bin/sdkmanager --update

That’s all there is to it. Please note that Android SDK seems pretty sensitive to what your current directory is, so I am pretty sure being in the “tools” directory is necessary. You can try it from other directories if you wish, but if it doesn’t work, try doing it from tools. Alternatively, you can also set an environment variable to make sure it knows the right path (I want to say it is ANDROID_HOME or ANDROID_SDK, but my personal preference is to just run it from the correct directory).

Installing Your APK

Assuming you have an APK to install, the command line to install it is fairly easy. First, make sure your Android emulator is running (see my previous article). Then, from your android directory, type:

./platform-tools/adb install -r path/file.apk

Of course modifying path/file.apk to whatever file you wish to install. The -r option tells adb to replace an existing version first. In my experience, however, this doesn’t work so your mileage may vary. It may depend on if the application is running at the time or not. Anyway, I usually uninstall the app from the emulated device, but adb has an “uninstall” command you can dig into if you wish.

Accessing Logs

Android emits a ton of logs that aren’t easily visible within the device. The adb command allows you to see them. The way it works, is you ask adb to emit logs that match some kind of pattern and severity level. For instance, again from your android directory and again with the emulator running:

/platform-tools/adb logcat net.epicforce:D ReactNativeJS:D \*:s

So what does this mean? It means show me logs for net.epicforce at DEBUG level, ReactNativeJS at DEBUG level, and everything else is SILENT (not shown).

Please note that just searching for your application’s package doesn’t always cut it; because my application uses React Native, it gets two kinds of log messages. In fact, the majority of the logs I get come from React Native instead of my own application.

You can use V (Verbose), D (Debug), I (Info), W (Warning), E (Error), F (Fatal), and S (Silent) to configure your log filters.

For more information on logcat, here’s the official documentation.

Conclusion

So that should get you started. In particular, adb is a powerful tool and there’s a lot you can do with it. Reading the docs is recommended, but, for what I’m doing these commands cover pretty much everything.

Good luck and have fun!

Related Reads