Tuesday, March 1, 2022

How to run Android Emulator on ChromeOS

(1) You need a ChromeOS machine with x86_64 CPU, 8GB RAM or above and for Intel CPU say i5 or above and 128GB storage.

(2) Setup Linux Environment (here) in ChromeOS with at least 20GB linux file size and Download the installation file here and while downloading the file Open the Terminal app then do step 3 below and then follow the Installation Steps of Android Studio in ChromeOS (here).

(3) In Linux Terminal, you have to install libnns3
sudo apt update && sudo apt upgrade
sudo apt install libnss3-dev libgdk-pixbuf2.0-dev libgtk-3-dev libxss-dev


(4) After the acceptance of the license and Finish with the download of SDK platform and tools and this might take some time to download and unzip. Then start Android Studio and with create a new blank project or import a project from github and wait for the update of gradle sync then goto Tools -> SDK Manager to check whether the required SDK are proerly installed and then goto Tools -> Device Manager and click Create device.

(5) Choose a Hardware layout e.g. Phone Pixel 4 XL and then click Next to select a system image e.g. Release Name S, API 31, x86_64 Andoird 12.0 (Google APIs) and then click the Download next to Release Name. This may take a much longer time to download and unzip and would occupy a lot of Linux System storage space if you download more than one image.

(6) After download is done, click Finish and then Next to name the device and fill in Advanced Settings if any and then click Finish to create.

(7) Then start the emulator by Running your project to the emulator and check whether the compileSdkVersion (e.g. 32) in build.gradle for Module match with your download and first click the Build -> Make Project (Ctrl+F9) to see if there is any error. Then, start the project by clicking the Run -> Run App (Shift+F10) or start the Emulator manually in Device Manager. After this step your ChromeOS will experience a significant slow down when the Emulator is running. My testing is that Intel 10th generation i5 CPU with 8GB Ram and 128 GB storage can run reasonably well for the simple project in Android Emulator.

(8) If you want a larger screen or floating window for the Emulator, you can click the Settings button of the elumlator window and set it to View Mode -> Window and then resize the detached window.

(9) You can debug the project source code with the Emulator if you click Run -> Debug App (Shift+F9). If you have enabled Developer Mode in ChromeOS (which is default for Brunch framework). Alternatively, you could build the apk and side load it to the ChromeOS or real device for test run, but debugging on ChromeOS or real device has to first powerwash the ChromeOS machine and then open the ADB port

(10) If you like to have this android studio project (written in Java) for testing, you can download it from here PeamonCalculator.zip

There is another Android Studio Project on Calculator which is written in Kotlin GitHub project source code download here. You might have to change the build SDK version for this project to your Settings in SDK, e.g. compileSdkVersion 32 which is the default SDK version currently for newly installed Android Studio.


(11) If you want to use the JRE from Android Studio in Terminal, add these lines in your ~/.profile
# set JAVA_HOME for Android Studio
export JAVA_HOME=/opt/android-studio/jre
export ANDROID_HOME="$HOME/Android"
export ANDROID_SDK_ROOT="$ANDROID_HOME/Sdk"
PATH="$JAVA_HOME/bin:$ANDROID_SDK_ROOT/build-tools/30.0.3:$PATH"


(12) If you want to install decompile tools on ChromeOS
sudo apt install -y curl unzip
export ANDROID_DECOMPILE_TOOLS=="$ANDROID_HOME/DecompileTools"
# install apktool (d) decompile apk file to smali and resource folders or (b) build them to apk file
mkdir -p $ANDROID_DECOMPILE_TOOLS/apktool && pushd $ANDROID_DECOMPILE_TOOLS/apktool && curl -OL https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_2.6.0.jar && ln -s apktool_2.6.0.jar apktool.jar && curl -OL https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool && chmod +x apktool && popd
# install jadx (to compile smali file to java source code and support whole project or single file conversion)
curl -OL https://github.com/skylot/jadx/releases/download/v1.3.3/jadx-1.3.3.zip && unzip jadx-1.3.3.zip -d $ANDROID_DECOMPILE_TOOLS/jadx && rm -v jadx-1.3.3.zip
PATH="$ANDROID_HOME/DecompileTools/apktool:$ANDROID_HOME/DecompileTools/jadx/bin:$PATH"


# install jadx (to compile java/kotlin project files to smali code, but does not support single file conversion)
For Java2Smali, install the plugin version in Android Studio. File -> Settings (Ctrl-ALt-S ) -> Plugins and search java2smali to install.


No comments: