Configuring the TFS Server to Build Android Apps
- PDF for offline use:
Let us know how you feel about this.
As stated in the requirements, an appropriate edition of Visual Studio must be installed on the Team Foundation Server along with licensed copies of Xamarin for each target platform.
If you are using Visual Studio 2015 on your TFS machine and installed Xamarin as part of Visual Studio setup, and Android SDK and NDK will already have been installed in a shared location. The first step below will verify this. If that's the case, no other configuration is necessary.
If, conversely, you installed the Android SDK and NDK separately, they'll likely be in folders that are accessible to only the currently logged in user. The TFS build service, however, uses a different account. As a result, TFS builds will fail with the error The Android SDK Directory could not be found. Please set via /p:AndroidSdkDirectory.. You may also see this error, both when building locally and on a build server, when your app project requires an API level for which the appropriate SDK has not been installed.
If you encounter this error, it's necessary to move the Android SDK and NDK to a shared location, as described in this topic.
Checking the Location of the Android SDK and NDK
To determine whether you need to move the Android kits, open Visual Studio, select the Tools > Options menu command, and navigate to the Xamarin > Android Settings options. (If you don't see Xamarin listed on the left side of the Options dialog, check Show all settings at the bottom.)
If the Android SDK and NDK are placed in a shared folder such as c:\Program Files (x86) (the default with Visual Studio 2015 as shown above), then no further action is needed.
If, however, they're in a user-specific folder such as c:\Users[USER]\AppData\Local\Android then proceed with the instructions in this topic.
Moving the Android SDK
Here you need to locate the Android folder in the current user's AppData, and move or copy all its contents into a central folder such as c:\android-sdk:
- Log in to the TFS machine as Administrator.
- Open Windows Explorer and navigate to c:\Users[USER] where [USER] is the current user account.
- In the Search box enter android-sdk and press Enter.
- In the search results look for the folder C:\Users[USER]\AppData\Local\Android. Right click that folder, select Open in new window, and then select all the files in that folder and copy them. (If no results come up, repeat the search starting at the C drive root.)
- Go to the C drive root, create a new folder called android-sdk, navigate into that folder, and paste in the copied files.
Once the copy is complete, go into Visual Studio, select the Tools > Options menu command, and navigate to the Xamarin > Android Settings options. (If you don't see Xamarin listed on the left side of the Options dialog, check Show all settings at the bottom.) Click Change by the Android SDK Location and point to c:\android-sdk.
Note: The c:\android-sdk path will need to be added to the Build Process for any solution that will want to automatically build Android apps during a TFS check-in. See Adding a Build Definition in Using TFS with Xamarin for details.
Moving the Android NDK
To move the NDK, follow the same steps above as for the SDK, but search for android-ndk and move files into a folder such as c:\android-ndk. Be sure to update the Visual Studio options for Xamarin as shown in the previous image.
Adjusting Environment Variables
During the automated build process Xamarin.Android will require access to the Android SDK and NDK at the paths that were adjusted above. This is best done by setting ot adjusting several server wide environment variables:
- If not already, log in to the TFS machine as Administrator.
Open Control Panel, type Environment in the search box, select Edit the system environment variables, and then click the Environment Variables... button to bring up the following dialog:
Under System variables select ANDROID_HOME and click Edit…, or if ANDROID_HOME doesn’t exist, click New… to create it:
Set the value to
c:\android-sdk(or wherever you moved the SDK) and click OK.
Under System variables select ANDROID_NDK_PATH and click Edit… (or New… if necessary):
Set the value to
c:\android-ndk\android-ndk-r8d(or wherever you moved the NDK) and click OK. Note that you do need the second folder name in this value.
Select the Path variable, click Edit… button, and append
;c:\android-sdk(or whatever folder you used) to the end of the path and click OK. Don’t forget to include the semi-colon (;) separator between this and previous entries.
Verify the changes by opening a command prompt, entering Set, and examining the variables.
The Team Foundation Server should now be able to build Android apps in a team project.