This guide will explain how to share the Android SDK between multiple users on an OS X system. Most of the concepts will be similar on other Unix or Linux systems.
I dont think this would work for multiple concurrent users updating the SDK. This blog post is more about the journey of making the SDK more suitable for multiple users rather than an endorsement of the methods below.
Where to put it
I’ve seen guides suggesting that you install the SDK in one of these locations:
This is fine and it will certainly work, but these are not per user locations so I would be reluctant to place the SDK there unless I made some effort to make it available to other users on my system also.
If you are the only user on your system then I would suggest that you just place the SDK in your home directory, for example
There is another reason to make the SDK multi-user capable if we’re putting it outside of our home directory. The Android SDK is not a static one and over time various new features and updates will be downloaded into it. After an update session there will be directories and files created belonging to one user and when another user tries to update these they will fail because of permissions issues.
Installing the SDK
Creating a home directory
We will start by picking a place where the SDK will live on the system. The /opt/ and /usr/local/ directories would be the most common but it doesn’t really matter where you put it as long as it is in a place where all users on the system can access it. In this example /opt/ will be used.
Open the terminal app and create a directory for the SDK. We will be using sudo because we want the files to be owned by root. We are going to rely on group membership to allow users to access and update the SDK. N.B. The account that you are logged onto will also need to have the ‘Allow user to administer this computer’ checkbox checked under ‘System Preferences -> Users & Groups’.
sudo mkdir -p /opt/android-sdk
When this command executes you should have a new directory under /opt like this. Note that it is owned by ‘root’ and the group is ‘admin’. Having the group owned by admin is desirable because it means standard users won’t be able to use or change the SDK.
(If you wanted standard users to be able to use and update the SDK you could use the ‘staff’ group instead.)
➜ ~ ls -l /opt drwxr-xr-x 8 root admin 272 10 Apr 11:23 android-sdk
Setting up group permissions
Feel free to skip this paragraph if you just want the solution! I considered making the SDK directory group writable so that users in the admin group could make child directories but that only works to the first level, i.e. the direct children of the ‘android-sdk’ directory. We don’t know what sort of structures the SDK will want to create so I thought this solution wasn’t a solution. In a similar way setguid on the directory would cause the group ownership of new files to be inherited by direct children only.
The solution that worked for me was to define an access control list (ACL) entry on the ‘android-sdk’ directory. An ACL entry allows you to define very finely grained permissions and inheritance behaviours. We want members of the ‘admin’ group to have full access and for any files or directories to be created with the same group as the root sdk directory. We won’t be doing it just yet though…
Installing the SDK
Getting the SDK
Go to the SDK download site and expand ‘Use an existing IDE’. Click the button to download the SDK zip file. It should be in a format like this: android-sdk_rxx.x-macosx.zip, where the x characters mark the current version.
Unzipping it and moving to /opt
Unzip the SDK zip file in the terminal. Remember to replace the ‘xx.x’ with the actual version number of what you downloaded.
cd /path/to/downloads/ unzip android-sdk_rxx.x-macosx.zip
Next, go into the newly created directory and change the ownership of the files to root. It isn’t strictly necessary but keeps things tidy.
cd android-sdk-macosx sudo chown -R root:admin .
Still in the same directory, move what is in there to the ‘/opt/android-sdk’ directory.
sudo mv * /opt/android-sdk/
Checking the result
If things have gone well you should see something like this after listing the contents of ‘/opt/android-sdk’.
➜ android-sdk ls -l /opt/android-sdk total 8 -rw-r----- 1 root admin 1158 6 Feb 20:27 SDK Readme.txt drwxr-x--- 2 root admin 68 6 Feb 20:27 add-ons drwxr-x--- 2 root admin 68 6 Feb 20:27 platforms drwxr-x--- 37 root admin 1258 6 Feb 20:27 tools
The final thing to do is to set our ACL entry on this directory structure. To do this enter the following in the terminal (intuitive, right?!):
chmod -R +a "group:admin allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit" /opt/android-sdk
I’ve bolded two parts. The first defines the group that this ACL entry applies to and the second is the directory to apply it to. If you do another directory listing now you’ll notice that there is a + character at the end of each permissions block. This signifies that there is an ACL active on the file or directory.
drwxr-x---+ 2 root admin 68 6 Feb 20:27 add-ons
You can see what the ACL is by issuing an ls command with -le
Testing the SDK
We will install two packages from the SDK manager using different user accounts to verify that multiple users can use the SDK.
Admin user one
Start the Android SDK manager as the first admin user from the terminal.
After it has finished downloading, “done loading packages”, click deselect all and then select ‘Samples for SDK API 17’ for example.
Admin user two
Login as another admin user and add another component of SDK 17, ‘SDK Platform’ for example. It should work just fine.
If you examine the SDK’s directory structure you’ll notice that there are some files with root:admin ownership, some with user1:admin ownership and some with user2:admin ownership. This isn’t really a problem per sé because we are relying on membership of the ‘admin’ group as authorisation but if you wished you could write a script to reset ownership back to root and schedule it to run periodically with cron.
chown -R root:admin /opt/android-sdk