Android How-Tos
How to install Java JDK on macOS
Android Studio requires Java JDK to work properly. Please check JDK installation instructions here.
How to check which Java versions are installed on your machine:
ls -lsah /Library/Java/JavaVirtualMachines/
Setting up path for Java path & Android Studio
## Set JAVA_HOME environment variable
echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.zshrc
## If you have multiple JDK versions installed and you want it to be a specific one, use -v flag
echo export "JAVA_HOME=\$(/usr/libexec/java_home -v 1.7)" >> ~/.zshrc
# Setting up path for JDK
export PATH="/usr/local/opt/openjdk@8/bin:$PATH"
# Setting up path for Android Studio
export ANDROID_HOME=/Users/your-username/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/tools/bin
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
Setting up Appium on your machine
Check connected devices:
To see list of devices attached to your machine:
adb devices
Install app on Simulator using adb command:
adb install /app-folder-location/app-name.apk
Capturing logs on real device:
adb log -s <device_id> logcat -v threadtime
Note that -s <device_id>
is optional if only one device is connected to your pc.
How to share/mirror your real device screen
You can share your Android device screen with the teammates using Vysor. Vysor lets you view and control your mobile/device on your computer. It's basically a window to your Android.
Setting up Vysor:
-
Install Vysor for chrome using link
-
Once installed, you'll find it under your installed apps.
-
Connect your Device to your system using USB cable.
-
Make Sure your Android have USB debugging ON, If not, go to 'Settings' on your device, search for USB Debugging, and make it enabled.
-
Open Vysor app. It will show you a notification about your connected device.
-
Now to see your Device screen, just click on 'View' button and you'll be able to see your device screen on your desktop.
-
You can also record the android activity displayed by vysor by using Quicktime Player (or any other screen recording tool). Shortcut for mac to see recording option: Command + Shift + 5.
How to run UIAutomatorViewer?
- Navigate to
~/Library/Android/sdk/tools/bin
- Type
uiautomatorviewer
and press enter.
- Issue: Unable to launch uiautomatorviewer on macOS Big Sur, resulting in an error
java.lang.NullPointerException
- Solution:
- Download the latest
swt.jar
from https://download.eclipse.org/eclipse/downloads/index.html, rename downloadedswt.jar
toswt2.jar
- Copy
swt2.jar
toAndroid/sdk/tools/lib/x86_64/
andAndroid/sdk/tools/lib/x86/
folders.
Don't REPLACE, Don't DELETE, just copy the new swt2.jar.