SDK directory is not writable when building Android project on Ubuntu agent of Azure Pipelines

余生长醉 提交于 2021-02-08 15:53:33

问题


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!


回答1:


Change the ownership of Android SDK:

sudo chown -R $(whoami) $ANDROID_HOME



回答2:


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!




回答3:


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

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



来源:https://stackoverflow.com/questions/53870742/sdk-directory-is-not-writable-when-building-android-project-on-ubuntu-agent-of-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!