Search code examples
androidandroid-studioandroid-sdk-manager

Cannot add additional platforms/build tools in Android Studio


I installed Android Studio Arctic Fox 2020.3.1 on Ubuntu via the Ubuntu Software Center having previously installed the Java and android SDK's using apt from a terminal, following the official installation instructions and I had no reported issues while installing or after. When I ran Android Studio, its seems to have detected the Android SDK location which is installed at:

 /usr/lib/android-sdk

but when I tried to add additional platform and tools for android nougat in:

Tools->Android SDK->Android SDK Location

The Android SDK location is:

/usr/lib/android-sdk

Which is correct, but when I click Edit and the SDK Components Setup dialog is loaded, the Android SDK location is again displayed and is also correct, however there's a warning message underneath which states:

<!> An existing Android SDK was detected. The setup wizard will only download missing or outdated SDK components.

When that appears to be merely stating the obvious and doesn't need to be said, so why the warning?. I just ignored it anyway and tried to add some additional plaform support. Prior to that, to test android studio was working after install, I rebuilt an existing hello-world project and the target platform from previous builds was 27.0.1 and as a result of rebuiding that existing project Android Studio appears to have created a hard link from 27.0.1 which it installed to the 'debian' folder, so when I list that location in a terminal I get:

$ls -al /usr/lib/android-sdk/build-tools/

lrwxrwxrwx 1 root root 6 Aug 29 2019 27.0.1 -> debian
drwxr-xr-x 3 root root 4096 Aug 11 00:22 debian

As you can see '27.0.1' is a hard link to the debian folder and by checking the properties of the link I can confirm it was created by Android Studio on 11th August which is the date it was installed:

27.0.1 Properties
Name: 27.0.1
Type: Link to folder (inode/ directory)
Parent folder: /usr/lib/android-sdk/build-tools
Modified Wed 11 Aug 2021 12:22:55 BST

When I attempt to install any additional platforms and tools, Android Studio now complains and cannot continue, it tells me to check the log and when I examined the Idea.log it says:

'build-tools;debian' in inconsistent location '/usr/lib/android-sdk/build-tools/27.0.1' (Expected '/usr/lib/android-sdk/build-tools/debian')

when the expected location exists and there appears to be no such issue, since the Android SDK is exactly where the installer put it and exactly where it should be, I dont know why it thinks there is a problem, where there doesn't appear to be one. However I dont know why Android Studio created the hard link for platform 27.0.1 -> debian when it added that platform to build hello world?


Solution

  • I worked out the solution myself. The solution is:

    (Note: you need to ensure your PC is connected to the internet, so Android Studio can download the Android SDK)

    1. Uninstall the Android SDK.

    In my case, I installed the Android SDK via apt in a terminal, so I uninstalled using the following commands:

    sudo apt-get remove android-sdk
    

    and then

    sudo apt-get --purge remove android-sdk
    
    1. Launch Android Studio and it will automatically start the Android Studio Setup Wizard and issue the pop-message:
    Title:  Missing Components
    Message: No Android SDK found
    
    1. Follow the wizard to install the SDK.
      This time the SDK is installed to your home directory and Android Studio has no issues with the SDK.

    To test it all works, I installed the additional build-tools and target platforms for my test app and built and ran it on an AVD and everything works fine.