Ubuntu/Android/SDK/AVD

From r00tedvw.com wiki
Jump to: navigation, search

Contents

Overview

Done on Ubuntu 20.04 LTS.
Installed without Android Studio

Download Prerequisites

Get the commandline tools.
https://developer.android.com/studio > Download options > commandlinetools-linux-7583922_latest.zip

~$ wget https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip

Make the directory Android SDK/AVD will live in.

~$ sudo mkdir /opt/android

Unzip

~$ sudo unzip ~/commandlinetools-linux-7583922_latest.zip -d /opt/android

Move sdkmanager

~$ sudo mkdir /opt/android/cmdline-tools/latest
~$ sudo mv /opt/android/cmdline-tools/bin/sdkmanager /opt/android/cmdline-tools/latest

Set Env Vars and Path

I had to do this in a few places. root, user, and sudoers.

root & user

Create a bash_alias for root, modify .profile for user. Same data in both.

~$ sudo touch /root/.bash_aliases
~$ sudo vim /root/.bash_aliases
~$ sudo vim ~/.profile

# set PATH so it includes android sdk emulator if it exists
if [ -d "/opt/android/emulator" ] ; then
    PATH="/opt/android/emulator:$PATH"
fi

# set PATH so it includes android sdk platform tools if it exists
if [ -d "/opt/android/platform-tools" ] ; then
    PATH="/opt/android/platform-tools:$PATH"
fi

# set PATH so it includes android sdk command line tools if it exists
if [ -d "/opt/android/cmdline-tools" ] ; then
    PATH="/opt/android/cmdline-tools:$PATH"
fi

# set PATH so it includes android sdk command line tools bin if it exists
if [ -d "/opt/android/cmdline-tools/bin" ] ; then
    PATH="/opt/android/cmdline-tools/bin:$PATH"
    ANDROID_SDK_ROOT="/opt/android"
    ANDROID_HOME="/opt/android"
fi

# set PATH so it includes android sdk command line tools if it exists
if [ -d "/opt/android/cmdline-tools/latest" ] ; then
    PATH="/opt/android/cmdline-tools/latest:$PATH"
fi

sudoers

use sudo visudo then add the following to the Defaults secure_path=

Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/opt/android/cmdline-tools/bin:/opt/android/cmdline-tools/latest:/opt/android/emulator:/opt/android/platform-tools"

Install Android packages

~$ cd /opt/android/
~$ sudo sdkmanager --sdk_root="/opt/android" --install "platforms;android-31"
~$ sudo sdkmanager --sdk_root="/opt/android" --install "system-images;android-31;google_apis_playstore;x86_64"
~$ sudo sdkmanager --sdk_root="/opt/android" --install "build-tools;31.0.0"
~$ sudo sdkmanager --sdk_root="/opt/android" --licenses

Verify you can see them.

~$ sudo avdmanager list target
Warning: Observed package id 'build-tools;31.0.0' in inconsistent location '/opt/android/build-tools/31.0.0' (Expected '/opt/build-tools/31.0.0')
Warning: Observed package id 'emulator' in inconsistent location '/opt/android/emulator' (Expected '/opt/emulator')
Warning: Observed package id 'patcher;v4' in inconsistent location '/opt/android/patcher/v4' (Expected '/opt/patcher/v4')
Warning: Observed package id 'platform-tools' in inconsistent location '/opt/android/platform-tools' (Expected '/opt/platform-tools')
Warning: Observed package id 'platforms;android-31' in inconsistent location '/opt/android/platforms/android-31' (Expected '/opt/platforms/android-31')
Warning: Observed package id 'system-images;android-31;google_apis_playstore;x86_64' in inconsistent location '/opt/android/system-images/android-31/google_apis_playstore/x86_64' (Expected '/opt/system-images/android-31/google_apis_playstore/x86_64')
Warning: Observed package id 'tools' in inconsistent location '/opt/android/tools' (Expected '/opt/tools')
Available Android targets:==============] 100% Fetch remote repository...       
----------
id: 1 or "android-31"
     Name: Android API 31
     Type: Platform
     API level: 31
     Revision: 1

Create AVD

~$ /opt/android/cmdline-tools/bin/avdmanager create avd --force -n Tablet -k "system-images;android-31;google_apis_playstore;x86_64"
Warning: Observed package id 'build-tools;31.0.0' in inconsistent location '/opt/android/build-tools/31.0.0' (Expected '/opt/build-tools/31.0.0')
Warning: Observed package id 'emulator' in inconsistent location '/opt/android/emulator' (Expected '/opt/emulator')
Warning: Observed package id 'patcher;v4' in inconsistent location '/opt/android/patcher/v4' (Expected '/opt/patcher/v4')
Warning: Observed package id 'platform-tools' in inconsistent location '/opt/android/platform-tools' (Expected '/opt/platform-tools')
Warning: Observed package id 'platforms;android-31' in inconsistent location '/opt/android/platforms/android-31' (Expected '/opt/platforms/android-31')
Warning: Observed package id 'system-images;android-31;google_apis_playstore;x86_64' in inconsistent location '/opt/android/system-images/android-31/google_apis_playstore/x86_64' (Expected '/opt/system-images/android-31/google_apis_playstore/x86_64')
Warning: Observed package id 'tools' in inconsistent location '/opt/android/tools' (Expected '/opt/tools')
Auto-selecting single ABI x86_64========] 100% Fetch remote repository...       
Do you wish to create a custom hardware profile? [no]

Verify you can see it:

avdmanager list avd
Available Android Virtual Devices:
    Name: Tablet
    Path: /root/.android/avd/Tablet.avd
  Target: Google Play (Google Inc.)
          Based on: Android 12 Preview (S) Tag/ABI: google_apis_playstore/x86_64
  Sdcard: 512 MB

Launch emulator

Verify you can see the AVD

~$ emulator -list-avds
Tablet

Launch

~$ emulator -avd Tablet
emulator: Android emulator version 30.7.5.0 (build_id 7491168) (CL:N/A)
PANIC: Broken AVD system path. Check your ANDROID_SDK_ROOT value [/opt/android]!
Personal tools
Namespaces

Variants
Actions
Navigation
Mediawiki
Confluence
DevOps Tools
Ubuntu
Ubuntu 22
Mac OSX
Oracle Linux
AWS
Windows
OpenVPN
Grafana
InfluxDB2
TrueNas
OwnCloud
Pivotal
osTicket
OTRS
phpBB
WordPress
VmWare ESXI 5.1
Crypto currencies
HTML
CSS
Python
Java Script
PHP
Raspberry Pi
Canvas LMS
Kaltura Media Server
Plex Media Server
MetaSploit
Zoneminder
ShinobiCE
Photoshop CS2
Fortinet
Uploaded
Certifications
General Info
Games
Meal Plans
NC Statutes
2020 Election
Volkswagen
Covid
NCDMV
Toolbox