Android Studio Won't Use Brew Cask Android-SDK Directory - android

We try to maintain scripts to rapidly onboard new developers and maintain consistency across teams/members. We used to install the Android SDK and NDK tools via command line as part of our scripts, download all the platforms we need and tools, and then setup android studio to use them. Since the release of Android 26 this doesn't seem possible and Android wants it to all be done via Studio. Is there any reason why the below scenario would not work?
Mac OSX
Android Studio: 2.3.3 - Installed via brew cask install android-studio (Homebrew)
Android-SDK 26: Installed via brew cask install android-sdk
Android rc file (sourced in bash_profile)
export ANDROID_SDK_ROOT=/usr/local/share/android-sdk
export ANDROID_HOME=/usr/local/share/android-sdk/
export ANDROID_NDK_HOME=/usr/local/share/android-ndk
Steps to reproduce:
Install above dependencies using homebrew cask.
Update environment variables (export them in bash profile or the like).
Open android studio - It should prompt to install the SDK.
Attempt to use the share sdk (android sdk root path above).
Android Studio says sdks is not valid nor empty.

Try running sdkmanager "platforms;android-26". This is because the basic tools are not installed to be recognised as a valid SDK directory.

To make Android Studio happy with brew I had to "brew" this:
brew cask install android-sdk
brew cask install android-platform-tools
sdkmanager "platforms;android-27"
sdkmanager "build-tools;27.0.3"
sdkmanager "extras;android;m2repository"
sdkmanager "extras;google;m2repository"
sdkmanager "sources;android-27"
and my ANDROID_HOME is:
/usr/local/share/android-sdk

For osx and the new Android Studio (2.3.3 at this time) the sdk is now in ~/Library/Android/platforms and the tools are in ~/Library/Android/platform-tools so add those to our path instead of using brew.

Related

android-sdk has been officially discontinued upstream

When installing android sdk using home-brew I get this message
android-sdk has been officially discontinued upstream.
But I can't find an alternative package to use. Is there a different one I should be using?
If you don't want the full android-studio development app (Intellij IDE, etc) and just want the new command line tools...
Per the discontinuation notice...
This SDK Tools package is deprecated and no longer receiving updates. Instead, please use the new command-line tools package.
A quick search reveals that in homebrew land, this new "command-line tools" package is called android-commandlinetools.
$ brew remove android-sdk
$ brew install --cask android-commandlinetools
If you are looking for adb and such, these are "SDK Platform Tools" and can be installed using sdkmanager (which was installed by the new android-commandlinetools package)...
$ sdkmanager --install platform-tools
Depending on where sdkmanager installs platform-tools you might need to update your $PATH or add symlinks in order to run adb and other platform-tools without an absolute path.
...or if you just want adb/etc you can skip the full commandlinetools and install platform-tools directly with homebrew. This has the side benefit of ensuring the newly installed adb is within your $PATH and is probably the best option for people that aren't doing android development and just want the latest adb, fastboot, etc.
$ brew install --cask android-platform-tools
Per https://developer.android.com/studio/releases/sdk-tools
Note: This SDK Tools package is deprecated and no longer receiving updates. Instead, please use the new command-line tools package.
check out https://developer.android.com/studio
brew install android-studio

Mac OSX Android Studo: Install the Android build tools version 19.1.0 or higher

I've been doing some research on this issue, which has been asked on StackOverflow many times, yet all previous answers tend to dismiss the question with something like "Set the environment variables."
I just downloaded Android Studio to my Mac. I'm trying to get it to import a Cordova/Ionic app, but I get this error:
No installed build tools found. Install the Android build tools version 19.1.0 or higher.
I figured I would follow the advice here:
https://gist.github.com/patrickhammond/4ddbe49a67e5eb1b9c03
and run:
brew install ant
brew install maven
brew install gradle
brew install android-sdk
brew install android-ndk
but some of these packages have been moved, so I had to follow the advice here:
https://github.com/Homebrew/homebrew-core/issues/11656
brew tap caskroom/cask
and then:
brew cask install android-sdk
brew cask install android-ndk
brew cask install android-platform-tools
This command:
brew cask install android-ndk
offered this tip:
==> Caveats
You may want to add to your profile:
'export ANDROID_NDK_HOME="/usr/local/share/android-ndk"'
If I do this:
ls -al /usr/local/share/android-ndk
I see:
lrwxr-xr-x /usr/local/share/android-ndk -> /usr/local/Caskroom/android-ndk/16b/android-ndk-r16b
I check both paths to be sure both are owned by me, as user.
I open
~/.bash_profile
and put this in place:
export ANDROID_HOME="/usr/local/share/android-sdk"
export ANDROID_NDK_HOME="/usr/local/share/android-ndk"
export PATH=$PATH:ANDROID_NDK_HOME:$ANDROID_HOME:$ANDROID_HOME/tools/:$ANDROID_HOME/platform-tools/
And then:
source ~/.bash_profile
I open Android Studio again, and again I get the same error:
No installed build tools found. Install the Android build tools version 19.1.0 or higher.
I open Preferences in Android Studio and, under Path Variables I add:
ANDROID_HOME
/usr/local/share/android-sdk
I restart Android Studio.
I get the same error as before.
What might I be doing wrong?
If I do this:
sdkmanager --list
I see:
Available Updates:
ID | Installed | Available
------- | ------- | -------
tools | 26.0.1 | 26.1.1

How to install android SDK tools without installing Android studio on ubuntu?

I was trying to install Android SDK with the help of the SDK command line tools downloaded from the link https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip on my Linux Ubuntu 16.04 PC.
i run the command following command for installation
./android update sdk
sudo ./android update sdk
but getting the this
error
how to solve this error ?or suggest me a proper way to install build tools.
FYI
and also i read that ~/.android should contain androidtool.cfg file which has below data in it.
http.proxyPort=proper_port
http.proxyHost=Proper_proxy_ip
sdkman.show.update.only=true
sdkman.ask.adb.restart=false
sdkman.force.http=true
It says that android script is deprecated, so you must use $ANDROID_HOME/tools/bin/sdkmanager --update for update all the installed packages, and $ANDROID_HOME/tools/bin/sdkmanager --list for see a list of installed, updates and available packages.
See more options at: https://developer.android.com/studio/command-line/sdkmanager.html or with $ANDROID_HOME/tools/bin/sdkmanager --help
$ANDROID_HOME refer to the location of your Android SDK. by example:
export ANDROID_HOME=$HOME/android/sdk

How to install Android SDK on Ubuntu?

For my Ubuntu machine, I downloaded the latest version of Android SDK from this page.
After extracting the downloaded .tgz file, I was trying to search for installation instructions and found:
To get started on Linux:
Unpack the .zip file you've downloaded. The SDK files are download separately to a user-specified directory.
Make a note of the name and location of the SDK directory on your system—you will need to refer to the SDK directory later when using the SDK tools from the command line.
What exactly are we supposed to do?
Option 1:
sudo apt update && sudo apt install android-sdk
The location of Android SDK on Linux can be any of the following:
/home/AccountName/Android/Sdk
/usr/lib/android-sdk
/Library/Android/sdk/
/Users/[USER]/Library/Android/sdk
Option 2:
Download the Android Studio.
Extract downloaded .zip file.
The extracted folder name will read somewhat like android-studio
To keep navigation easy, move this folder to Home directory.
After moving, copy the moved folder by right clicking it. This action will place folder's location to clipboard.
Use Ctrl Alt T to open a terminal
Go to this folder's directory using cd /home/(USER NAME)/android-studio/bin/
Type this command to make studio.sh executable: chmod +x studio.sh
Type ./studio.sh
A pop up will be shown asking for installation settings. In my particular case, it is a fresh install so I'll go with selecting I do not have a previous version of Studio or I do not want to import my settings.
If you choose to import settings anyway, you may need to close any old project which is opened in order to get a working Android SDK.
From now onwards, setup wizard will guide you.
Android Studio can work with both Open JDK and Oracle's JDK (recommended). Incase, Open JDK is installed the wizard will recommend installing Oracle Java JDK because some UI and performance issues are reported while using OpenJDK.
The downside with Oracle's JDK is that it won't update with the rest of your system like OpenJDK will.
The wizard may also prompt about the input problems with IDEA .
Select install type
Verify installation settings
An emulator can also be configured as needed.
The wizard will start downloading the necessary SDK tools
The wizard may also show an error about Linux 32 Bit Libraries, which can be solved by using the below command:
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1
After this, all the required components will be downloaded and installed automatically.
After everything is upto the mark, just click finish
To make a Desktop icon, go to 'Configure' and then click 'Create Desktop Entry'
source
To install it on a Debian based system simply do
# Install latest JDK
sudo apt install default-jdk
# get latest sdk tools - link will change. go to https://developer.android.com/studio/#downloads and look for "Command line tools only" download from webpage as you will need to accept terms. Then extract.
mkdir cmdline-tools
mv <folder-you-extracted> android-sdk/cmdline-tools
# So after this step is done you will have ~/cmdline-tools/tools with bin/ and lib/ in it.
Then add the Android SDK to your PATH, open ~/.bashrc in editor and add the following lines into the file
# Export the Android SDK path
export ANDROID_HOME=$HOME/cmdline-tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
Run
source ~/.bashrc
Show all available sdk packages
sdkmanager --list
Identify latest android platform (here it's 33) and run
sdkmanager "platform-tools" "platforms;android-33"
Now you have adb, fastboot and the latest sdk tools installed
Android SDK Manager
sudo snap install androidsdk
Usage
You can use the sdkmanager to perform the following tasks.
List installed and available packages
androidsdk --list [options]
Install packages
androidsdk packages [options]
The packages argument is an SDK-style path as shown with the --list command, wrapped in quotes (for example, "build-tools;29.0.0" or "platforms;android-28"). You can pass multiple package paths, separated with a space, but they must each be wrapped in their own set of quotes.
For example, here's how to install the latest platform tools (which includes adb and fastboot) and the SDK tools for API level 28:
androidsdk "platform-tools" "platforms;android-28"
Alternatively, you can pass a text file that specifies all packages:
androidsdk --package_file=package_file [options]
The package_file argument is the location of a text file in which each line is an SDK-style path of a package to install (without quotes).
To uninstall, simply add the --uninstall flag:
androidsdk --uninstall packages [options]
androidsdk --uninstall --package_file=package_file [options]
Update all installed packages
androidsdk --update [options]
Note
androidsdk it is snap wraper of sdkmanager
all options of sdkmanager work with androidsdk
Location of installed android sdk files : /home/user/AndroidSDK
See all sdkmanager options in google documentation
UPDATE: This method is no longer recommended and installation is as easy as downloading it from the official website, then running the downloaded binary.
ORIGINAL ANSWER:
There is no need to download any binaries or files or follow difficult installation instructions.
All you really needed to do is:
sudo apt update && sudo apt install android-sdk
Update: Ubuntu 18.04 only
I can tell you the steps for installing purely via command line from scratch.
I tested it on Ubuntu on 22 Feb 2021.
create sdk folder
export ANDROID_SDK_ROOT=/usr/lib/android-sdk
sudo mkdir -p $ANDROID_SDK_ROOT
install openjdk
sudo apt-get install openjdk-8-jdk
download android sdk
Go to https://developer.android.com/studio/index.html
Then down to Command line tools only
Click on Linux link, accept the agreement and instead of downloading right click and copy link address
cd $ANDROID_SDK_ROOT
sudo wget https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip
sudo unzip commandlinetools-linux-6858069_latest.zip
move folders
Rename the unpacked directory from cmdline-tools to tools,
and place it under $ANDROID_SDK_ROOT/cmdline-tools,
so now it should look like: $ANDROID_SDK_ROOT/cmdline-tools/tools.
And inside it, you should have: NOTICE.txt bin lib source.properties.
set path
PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin
This had no effect for me, hence the next step
browse to sdkmanager
cd $ANDROID_SDK_ROOT/cmdline-tools/tools/bin
accept licenses
yes | sudo sdkmanager --licenses
create build
Finally, run this inside your project
chmod 777 gradlew
sudo ./gradlew assembleDebug
This creates an APK named -debug.apk at //build/outputs/apk/debug
The file is already signed with the debug key and aligned with zipalign,
so you can immediately install it on a device.
REFERENCES
https://gist.github.com/guipmourao/3e7edc951b043f6de30ca15a5cc2be40
Android Command line tools sdkmanager always shows: Warning: Could not create settings
"Failed to install the following Android SDK packages as some licences have not been accepted" error
https://developer.android.com/studio/build/building-cmdline#sign_cmdline
If you are on Ubuntu 17.04 (Zesty), and you literally just need the SDK (no Android Studio), you can install it like on Debian:
sudo apt install android-sdk android-sdk-platform-23
export ANDROID_HOME=/usr/lib/android-sdk
In build.gradle, change compileSdkVersion to 23 and buildToolsVersion to 24.0.0
run gradle build
install the android SDK for me was not the problem, having the right JRE and JDK was the problem.
To solve this install the JVM 8 (the last fully compatible, for now):
sudo apt-get install openjdk-8-jre
Next use update-alternative to switch to the jre-8 version:
sudo update-alternatives --config java
You can revert JVM version when you want with the same update-alternatives command
Note that you problably have to do the same after this with javac also (now you have only java command at version 8)
first do:
sudo apt-get install openjdk-8-jdk
next:
sudo update-alternatives --config javac
After this you can install android SDK that require this specific Java version
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer oracle-java7-set-default
wget https://dl.google.com/dl/android/studio/ide-zips/2.2.0.12/android-studio-ide-145.3276617-linux.zip
unzip android-studio-ide-145.3276617-linux.zip
cd android-studio/bin
./studio.sh
Install Android Studio with
sudo snap install android-studio --classic
when you open it for the first time it will install the SDK for you (with options) .

Where does homebrew install android-sdk?

Where does homebrew install the android-sdk when you run the command:
brew cask install android-sdk
I want to be able to add it to the PATH.
use brew info --cask android-sdk
after installing, you can get some basic information about what needs to be set and where:
› brew cask info android-sdk
...etc
/usr/local/Caskroom/android-sdk/3859397,26.0.1/build-tools/26.0.1/aapt (binary)
/usr/local/Caskroom/android-sdk/3859397,26.0.1/tools/bin/avdmanager
...etc
==> Caveats
We will install android-sdk-tools, platform-tools, and build-tools for
you. You can control android sdk packages via the sdkmanager command.
You may want to add to your profile:
'export ANDROID_SDK_ROOT=/usr/local/share/android-sdk'
notes
Prior to March 2017 you could run brew info android-sdk
The installation folder of android-sdk is:
/usr/local/Cellar/android-sdk/<VERSION>
Therefore, if you want to add it to PATH, you need to add the following line to ~/.bashrc
export PATH=$PATH:/usr/local/Cellar/android-sdk/<VERSION>/tools:/usr/local/Cellar/android-sdk/<VERSION>/platform-tools
Don't forget to replace <VERSION> with an installed version, just take a look inside of android-sdk folder to see what version you have installed.
Unfortunately, brew has now changed where android-sdk is installed, so all of these older questions are no longer correct.
When installing via brew cask install android-sdk, you'll now be informed that you should add export ANDROID_SDK_ROOT=/usr/local/share/android-sdk to your profile, and, indeed, that directory is now a symlink to the version android-sdk directory (currently /usr/local/Caskroom/android-sdk/25.2.3).
To summarise, add the following to your .profile/.bashrc/.whatever:
export ANDROID_SDK_ROOT=/usr/local/share/android-sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools
You would be better off using the symlink that Homebrew creates to ANDROID_HOME, as it will always be the newest version:
/usr/local/opt/android-sdk/
So your PATH would be:
export PATH=$PATH:/usr/local/opt/android-sdk/tools:/usr/local/opt/android-sdk/platform-tools
in my machine, at /usr/local/share/android-sdk
My Homebrew installation (brew install --cask android-platform-tools) use this Path:
/usr/local/Caskroom/android-platform-tools/30.0.0/platform-tools
Homebrew installs things in the Cellar:
/usr/local/Cellar

Categories

Resources