Install Android Command-Line Tools
First of all, android create project
no longer works.
In fact, tools/android
has been removed in SDK Tools 25.3.0:
*************************************************************************
The "android" command is deprecated.
For manual SDK, AVD, and project management, please use Android Studio.
For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager
*************************************************************************
Some of its functionalities have been moved to tools/bin/sdkmanager
and
tools/bin/avdmanager
as stated above. However, other functionalities are
effectively lost.
RIP: android create project
.
So let’s see what’s still remaining.
It’s amazing that they still keep command line tools as a separate
download. I bet this separate download will also be removed in at most a few
years. But for now the document says you can use the downloaded sdkmanager
to
further download other SDK packages. So let’s try this.
Running sdkmanager --list
gives a list of packages to download. You no longer
have the auto-selection provided by the old android
tool. So you have to
figure out which packages to install by yourself. If you have good memory, you
know these packages are frequently used:
build-tools;27.0.1
platform-tools
platforms;android-27
system-images;android-27;google_apis;x86
tools
Running sdkmanager --help
and you will find a --package_file
option. That
looks good because it saves you typing package names in each run of the command.
So put those packages in a text file packages.txt
and run sdkmanager
with
this option:
sdkmanager --package_file=packages.txt
Wait a moment and the packages are downloaded. Not bad.
However, now, if you run the same command again, it will fail. Something just bit you, right? Yes it’s either a bug (1, 2) or a feature.
You may also want to run this command to accept licenses so they won’t block you from other operations:
sdkmanager --licenses
Now you have familiar stuff back there in a usable state. Congratulations! Next,
you may want to write a simple app and run it on the emulator. Now that you
understand android create project
doesn’t exist any more. But let’s say you
somehow get the project ready and successfully build it with gradle. Then you
only have to run it on an emulator. Since an emulator requires an AVD, you have
to create an AVD first.
Creating an AVD named test
can be done with:
avdmanager -n test -k system-images;android-27;google_apis;x86
Now run emulator with this AVD:
emulator @test
Oops…You saw it crash and you knew you just bit yourself again. Let’s fix this:
cd $ANDROID_HOME/emulator/lib64
mv libstdc++ libstdc++.bak
mkdir libstdc++
Now the emulator will be using libs on your system instead of the buggy libs shipped with the Android download. Running emulator again and you will be able to see the power-up screen.
After so much exercise, you finally get something working. Congratulations.
Download historical versions of Android SDK
As mentioned at the beginning, android
was removed in SDK Tools 25.3.0.
According to SDK Tools Release Notes, the version right before
25.3.0 is 25.2.5. So we download this version.
Actually, historical versions of SDK tools are still available from the server:
https://dl-ssl.google.com/android/repository/tools_r[revision]-windows.zip
https://dl-ssl.google.com/android/repository/tools_r[revision]-linux.zip
https://dl-ssl.google.com/android/repository/tools_r[revision]-macosx.zip
Simply replace [revision]
with the revision number. For example, we are going
to download SDK Tools Revision 25.2.5 for Linux at:
https://dl-ssl.google.com/android/repository/tools_r25.2.5-linux.zip
Yes, it’s there.
After downloading this zip file, unzip it and run tools/android
. You will be
able to see the familiar package selection window. This is really not bad.
Write an app with historical versions of Android SDK
When you start writing an app, you realise things are actually trickier. The SDK Tools revision is not everything. You still need to find compatible versions of platforms and build tools. Well, you don’t seem to be able to select version of platform tools. Plus, if you use Eclipse+ADT, then things get even more complicated.
To make things simpler, we just use the latest version of ADT by adding this URL in Eclipse:
https://dl-ssl.google.com/android/eclipse/
When we are using SDK Tools Revision 25.2.5, ADT is not happy with the latest version of build tools (27.0.1). So we revert to an older version of build tools (25.0.2). With environment variables properly set, this combination seems to work:
Android SDK Tools == 25.2.5
Android SDK Platform-tools == 26.0.2
Android SDK Build-tools == 25.0.2
SDK Platform == 19
Android Support Repository == 47
So finally I successfully made a HelloWorld app with historical versions of Android SDK.