Ubuntu/Android/SDK/AVD
From r00tedvw.com wiki
(Difference between revisions)
(→Launch emulator) |
|||
(3 intermediate revisions by one user not shown) | |||
Line 59: | Line 59: | ||
~$ sudo sdkmanager --sdk_root="/opt/android" --licenses</nowiki> | ~$ sudo sdkmanager --sdk_root="/opt/android" --licenses</nowiki> | ||
Verify you can see them. | Verify you can see them. | ||
− | <nowiki>~$ sudo avdmanager list avd | + | <nowiki>~$ sudo avdmanager list target |
− | Available Android Virtual Devices:</nowiki> | + | 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</nowiki> | ||
+ | |||
+ | =Create AVD= | ||
+ | <nowiki>~$ /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]</nowiki> | ||
+ | Verify you can see it: | ||
+ | <nowiki>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</nowiki> | ||
+ | |||
+ | =Launch emulator= | ||
+ | Verify you can see the AVD | ||
+ | <nowiki>~$ emulator -list-avds | ||
+ | Tablet</nowiki> | ||
+ | Launch | ||
+ | <nowiki>~$ 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]!</nowiki> |
Latest revision as of 03:37, 12 August 2021
Contents |
[edit] Overview
Done on Ubuntu 20.04 LTS.
Installed without Android Studio
[edit] 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
[edit] Set Env Vars and Path
I had to do this in a few places. root, user, and sudoers.
[edit] 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
[edit] 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"
[edit] 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
[edit] 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
[edit] 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]!