Gibt es eine Möglichkeit, die android sdk Installation zu automatisieren?
-
10-10-2019 - |
Frage
Jetzt muss ich herunterladen und das Android SDK abd AVD Manager installieren, und installieren Sie dann die die APIs, Tools über die Benutzeroberfläche. Gibt es eine Möglichkeit, diesen Prozess zu automatisieren?
Lösung
UPDATE
Die neuesten Versionen einführen sdkmanager
, ein Kommandozeilen-Tool, das Sie anzeigen können, installieren, aktualisieren und deinstallieren Pakete für das Android SDK.
Das sdkmanager
Tool im Android SDK Tools-Paket zur Verfügung gestellt ( 25.2.3 und höher ) und ist in android_sdk/tools/bin/
befindet.
sdkmanager [--uninstall] [<common args>] [--package_file <file>] [<packages>...]
sdkmanager --update [<common args>]
sdkmanager --list [<common args>]
sdkmanager --licenses [<common args>]
In its first form, installs, or uninstalls, or updates packages.
By default, the listed packages are installed or (if already installed)
updated to the latest version.
--uninstall: uninstalled listed packages.
<package> is a sdk-style path (e.g. "build-tools;23.0.0" or
"platforms;android-23").
<package-file> is a text file where each line is a sdk-style path
of a package to install or uninstall.
Multiple --package_file arguments may be specified in combination
with explicit paths.
In its second form (with --update), all installed packages are
updated to the latest version.
In its third form, all installed and available packages are printed
out.
In its fourth form (with --licenses), show and offer the option to
accept licenses for all available packages that have not already been
accepted.
Common Arguments:
--sdk_root=<sdkRootPath>: Use the specified SDK root instead of the SDK
containing this tool
--channel=<channelId>: Include packages in channels up to <channelId>.
Common channels are:
0 (Stable), 1 (Beta), 2 (Dev), and 3 (Canary).
--include_obsolete: With --list, show obsolete packages in the
package listing. With --update, update obsolete
packages as well as non-obsolete.
--no_https: Force all connections to use http rather than https.
--proxy=<http | socks>: Connect via a proxy of the given type.
--proxy_host=<IP or DNS address>: IP or DNS address of the proxy to use.
--proxy_port=<port #>: Proxy port to connect to.
* If the env var REPO_OS_OVERRIDE is set to "windows",
"macosx", or "linux", packages will be downloaded for that OS.
so zu aktualisieren, die Pakete laufen
$ sdkmanager --update
, um die Lizenzen akzeptieren
$ yes | sdkmanager --licenses
ALTE ANTWORT
(Bitte beachten Sie: Der Android Befehl ist überholt)
Je näher man an Automatisierung bekommen wahrscheinlich ist:
$ android update sdk --no-ui
Android bietet diese Optionen für automatisches Updates:
Action "update sdk":
Updates the SDK by suggesting new platforms to install if available.
Options:
-f --force Forces replacement of a package or its parts, even if something has been modified
-u --no-ui Updates from command-line (does not display the GUI)
-o --obsolete Installs obsolete packages
-t --filter A filter that limits the update to the specified types of packages in the form of
a comma-separated list of [platform, tool, platform-tool, doc, sample, extra]
-s --no-https Uses HTTP instead of HTTPS (the default) for downloads
-n --dry-mode Simulates the update but does not download or install anything
Wenn Sie auflisten möchten, die Pakete für die Installation verfügbar sind, können Sie verwenden
$ android list sdk
und Sie werden eine geordnete Liste von Paketen erhalten, zum Beispiel
Packages available for installation or update: 9
1- ARM EABI v7a System Image, Android API 15, revision 2
2- Intel x86 Atom System Image, Android API 15, revision 1
3- Android Support, revision 8
4- Google AdMob Ads SDK, revision 6
5- Google Analytics SDK, revision 2
6- Google Play APK Expansion Library, revision 1
7- Google Play Billing Library, revision 2
8- Google Play Licensing Library, revision 2
9- Google Web Driver, revision 2
Sie können auch das Update beschränken sich nur auf eine gewünschte Komponente, wenn Sie die --filter
Option
$ android update sdk --filter <component> --no-ui
, wobei die Komponente eines oder mehr von
- die von
android list sdk
zurück Zahlen (d 1 , auch bekannt als Paketindex ) - Add-on
- doc
- Extra
- Plattform
- Plattform-Tool
- Probe
- source
- System-Bild
- Werkzeug
oder können eine oder mehrere spezifische Bezeichner sein. Zum Beispiel, wenn Sie einen kleinen Satz von spezifischen Pakete nur herunterladen möchten, können Sie dies tun:
$ android update sdk -u --filter platform-tools,android-16,extra-android-support
und Sie werden nur die Plattform-Tools, api Level 16 und Support-Paket Glas erhalten. Das ist wirklich praktisch, wenn Sie nur eine Maschine zu bauen Gebäude sind und würden für das Herunterladen all zusätzliche Sachen zu zahlen haben, dass Sie nie benutzen.
Um die verfügbaren Optionen sehen Sie verwenden --help können zum Beispiel
$ android --help list sdk
Usage:
android [global options] list sdk [action options]
Global options:
-h --help : Help on a specific command.
-v --verbose : Verbose mode, shows errors, warnings and all messages.
--clear-cache: Clear the SDK Manager repository manifest cache.
-s --silent : Silent mode, shows errors only.
Action "list sdk":
Lists remote SDK repository.
Options:
-o --obsolete : Deprecated. Please use --all instead.
-a --all : Lists all available packages (including obsolete and
installed ones)
--proxy-host: HTTP/HTTPS proxy host (overrides settings if defined)
--proxy-port: HTTP/HTTPS proxy port (overrides settings if defined)
-s --no-https : Uses HTTP instead of HTTPS (the default) for downloads.
-e --extended : Displays extended details on each package
-u --no-ui : Displays list result on console (no GUI) [Default: true]
Andere Tipps
Das hat bei mir nicht funktioniert ...
echo "y" | android ....
so landete ich hier:
expect -c '
set timeout -1 ;
spawn sudo /opt/android-sdk/tools/android update sdk -u;
expect {
"Do you accept the license" { exp_send "y\r" ; exp_continue }
eof
}
'
ich dies verwenden zu installieren und zu aktualisieren, die sdk auf travis-ci
curl --location http://dl.google.com/android/android-sdk_r22.3-linux.tgz | tar -x -z -C $HOME
export ANDROID_HOME=$HOME/android-sdk-linux
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) | android update sdk --no-ui --filter platform-tool,android-19,sysimg-19,build-tools-19.0.1
Um alle Lizenzen mit ‚y‘ beantworten, können Sie dies im Skript ausprobieren können:
(while :
do
echo 'y'
sleep 2
done) | android update sdk -u .....
Für eine noch für eine Methode der Suche aller Android-Pakete zum Download habe ich schrieb ein Skript, das zu tun. Es wird herunterladen alle nicht-obsolete Pakete.
#!/binbash
# Install all non-obsolete android sdk packages.
# author: Tai Le Tien (letientai299 at gmail.com)
function install_sdk {
android update sdk -u -s -a -t "$1"
}
function fetch_non_obsoled_package_indices {
# Fetch the sdk list using non-https connections
android list sdk -u -s -a |\
# Filter obsoleted packages
sed '/\(Obsolete\)/d' |\
# Filter to take only the index number of package
sed 's/^[ ]*\([0-9]*\).*/\1/' |\
# Remove the empty lines
sed -n 's/^[^ $]/\0/p'
}
for package_index in $(fetch_non_obsoled_package_indices)
do
echo "====================================================================="
echo "Start to install package: ${package_index}"
echo "====================================================================="
# Auto accept license
echo -e "y" | install_sdk "${package_index}"
echo
echo
done
Sie können sehen, es auch auf meinem Github Repo
Die gute:
- hängt nicht von
expect
. - Headless.
Die Nachteile:
- Sie noch grundlegenden SDK manuell installieren müssen, und Put-
android
in Ihren Weg. - Script funktioniert nur auf Unix.
Beginnend mit Android Plugin für Gradle Version 2.2.0, fehlt SDK-Komponenten get automatisch heruntergeladen .
Bei neueren Android-Versionen (zB 25.2.5
) sollten wir benutzen sdkmanager (anstelle des android
Befehl)
Beispiel ein Paket installiert wird:
android-sdk/tools/bin/sdkmanager "extras;android;m2repository"
Befehl eine Liste aller verfügbaren Pakete zu bekommen:
android-sdk/tools/bin/sdkmanager --verbose --list
dieser Web-Seite Listen Download-Links für die SDK-Tools:
Hier ist ein Link zu einer Open-Source-Repository Docker-android die Android installieren in einem Docker Bild.
Sie können auch die Antworten finden in dieser SO Frage: Automatisch alle SDK Lizenzen akzeptieren nützlich.
Ich habe einen Ruby-Skript, dass Downloads und das SDK installieren, ohne Aufforderung, die helfen kann. https://github.com/ayvazj/andenv
Noch ein anderes Skript-Download nur dann benötigt, nicht {obsolute, Quelle, Emulator-Bild, doc} Pakete:
#!/bin/bash
set -e
# cd into where tools/android can be found
if [[ -d "$ANDROID_HOME" ]]; then
cd "$ANDROID_HOME"
elif [[ -x "$(dirname "$0")/tools/android" ]]; then
cd "$(dirname "$0")"
else
echo "FAILED: Cannot find ANDROID_HOME/tools/android"
exit 1
fi
android () {
"$(dirname $0)/tools/android" "$@"
}
needed_packages () {
android list sdk -u -s -e \
| grep '^id:' \
| cut -d'"' -f2 \
| grep -v 'source' \
| grep -v 'sys-img' \
| grep -v 'doc' \
| paste -d, -s -
}
main () {
(while : ; do
echo 'y'
sleep 1
done) | android update sdk -u -s -a -t "$(needed_packages)"
}
main
Einige Teile von anderen Antworten in diesem Thread gemacht.
Für einen Neuling Android-Entwickler, sondern einen erfahrenen Java-Entwickler, es ist verwirrend wirklich zu wissen, welche Abhängigkeiten, auch wenn Sie über alle oben genannten Alpträume bekommen. Kollege von mir hat mir geraten, Android Studio zu verwenden (die Intellij basiert :-) speziell wegen der oben Alpträume. Ich folgte seinem Rat. Aber ich habe nicht die Standardeinstellung für die Installation übernehmen, und versuchte, sie in einem Software-Laufwerk von mir zu installieren. Es stellte sich heraus, ein Alptraum zu sein. Der SDK Dialog schien zu hängen und war überhaupt nicht intuitiv. Welches ist, warum ich hier gelandet. Nach dem oben lesen, habe ich Studio einen neuen Versuch, und diesmal alle Standardeinstellungen für die intallation akzeptiert. Schwupps ... es kümmerte sich um alle die SDK-Abhängigkeiten (Kern, die ich bin zu raten) in ein paar Dialoge ohne das heißt aufgefordert werden, Ctl-Umschalt-S und den SKD. Ich würde es für einen Neuling daher empfehlen. Hier haben den Beweis des Puddings während des Herunterladens:
Die Version von sudio ich heruntergeladen und installiert: Version von Windows: Und hier, nachdem er seine gute Sachen tat:
Mit freundlichen Grüßen hoffen, dass es für Sie !!
Um die sdkmanager.bat --licenses
Prompt weg auf Windows zu automatisieren (sagen Sie installieren über Automatisierung für Build-Infrastruktur) ... es nicht laufen. vergeuden Zeit mit dem Versuch nicht, um herauszufinden, wie man Rohr y
hinein. Ich habe es versucht; bitteres versagen.
Rather - führen Sie es einmal, sich selbst, und zur Kenntnis nehmen, dass es Dateien in c:\android\android-sdk\licenses
erzeugt (wo man c:\android\android-sdk\tools\bin\sdkmanager.bat
laufen - Ihre Wurzel installieren können variieren).
Nehmen Sie die Dateien, und legen Sie sie irgendwo Sie sie aus in automatisierten Setup-Skripten greifen kann. Persönlich ansible ist mein Gift, so:
# Note to future-us:
# These are magical files generated by running `c:/android/android-sdk/tools/bin/sdkmanager.bat --licenses`
# This, delightfully, is interactive, and wants to _actually_ read the keyboard buffer.
# That's reputedly possible via SendKeys. I elected to not try that.
# So, instead:
# 1) remote to an instance like a cave-dweller
# 2) run `c:/android/android-sdk/tools/bin/sdkmanager.bat --licenses` in a prompt.
# 3) _actually type_ `y` however many godforsaken times you need to.
# 4) meticulously harvest `c:/android/android-sdk/licenses/*` to this task.
# (you don't need the newline that they thoughtfully put before the hash in each file).
- name: set up android licenses by hand
win_lineinfile:
path: c:/android/android-sdk/licenses/{{ item.name }}
line: "{{ item.line }}"
create: true
with_items:
- {name: "android-googletv-license", line: "SOME HASH"}
- {name: "android-sdk-license", line: "SOME OTHER HASH"}
...