10

I'm configuring my build pipeline for an Android project. So far, all of my steps are working perfectly on Hosted VS2017 agent, including fetching the code, building with gradlew, publishing the artifact and deploying it to AppCenter.

However, on Hosted Ubuntu 1604, there are a few problems with gradlew step.

On VS2017 agent, this works with just: .\gradlew assembleDebug

On Ubuntu 1604, this is what I'm having right now:

chmod 775 gradlew
chmod 775 /usr/local/lib/android/sdk --> The fix I'm working on
./gradlew assembleDebug

Running the build without the 2nd line, agent will throw this exception:

What went wrong: A problem occurred configuring project ':app'.
Failed to install the following SDK components: build-tools;28.0.3 Android SDK Build-Tools 28.0.3
The SDK directory is not writable (/usr/local/lib/android/sdk)

I'm a beginner with Ubuntu... why is it not writable? I tried to chmod but I got the exception while doing so: chmod: changing permissions of '/usr/local/lib/android/sdk': Operation not permitted.

Which direction should I look at to solve this problem now... ? Thank you all in advance!

Lam Le
  • 1,489
  • 3
  • 14
  • 31

3 Answers3

23

Change the ownership of Android SDK:

sudo chown -R $(whoami) $ANDROID_HOME
Eytan Manor
  • 346
  • 2
  • 4
  • 1
    On a more recent installation of the SDK, `ANDROID_HOME` is deprecated and replaced with `ANDROID_SDK_ROOT` so this command becomes `sudo chown -R $(whoami) $ANDROID_SDK_ROOT` – brianjohnhanna Mar 18 '21 at 18:01
  • `ANDROID_SDK_ROOT` doesn't work for me. `ANDROID_HOME` works just as the answer have suggested so I'm sticking with that. – mokpi May 02 '23 at 09:28
3

I had the same problem on a standard Ubuntu install.

The solution: install the Android SDK in your home directory.

The problem is, building a project with Gradle fails to work with a read-only SDK. Installing the Android SDK with apt leaves it read-only.

More precisely, everything in /usr/ is supposed to be read-only data, so it's owned by root with permissions set to 755. Your user doesn't have write access to it, only the owner does. Installing the SDK in your home directory (and making sure your user owns it) should solve the issue.

Installing the SDK

I haven't seen a good way to install just the SDK. There's another SO question addressing this; one of the ways listed there ought to work. However, you may find it easier to just install Android Studio, and pick a custom location for the SDK.

Hope it helps!

De117
  • 351
  • 2
  • 11
  • 2
    Even if this answer is correct for most people. It does not work for the specific question because OP is building in Azure Devops on a hosted agent. The android SDK is preinstalled there (for some reason under /usr/lib). – Andre Sep 18 '19 at 09:48
1

there is no need to reinstall something at all...

giving the write privilege to the currently logged in user solves the problem.

Asqan
  • 4,319
  • 11
  • 61
  • 100