In this post i will show you how we can have gradle projects built on VSTS/TFS.
- Java Environment
- Android SDK
- Sample Android Project (I have considered Android Studio)
- Installed Build agent up and running
Please find the below link to download Android SDK
Note: Since I am using Visual Studio Team Services to build, I would be installing the agent on my Local Machine. Because, the “Hosted agent” would not recognize the machine you are working with.
Once the Java Environment is ready, please make sure you have the Android SDK setup ready too.
Please follow the below steps for setting up Android SDK
- Copy the SDK to any of the drives (C, D, E etc…)
- Add the environment variables as follows
Variable name: ANDROID_HOME
Variable value: Specify the path till sdk. In my case this is how it looks like “D:\adt- bundle-windows-x86_64-20140702\sdk”
3.Update the same in the System Variables-Path too as shown below
Variable name: Path
Variable value: %ANDROID_HOME%\tools; %ANDROID_HOME%\platform-tools;
4. Open the “services.msc” and verify whether your VSO agent (android) is running or not.
Select the agent that you configured and right click, choose properties.
Go to Logon tab and run as either Local account or Service account as shown below-
The reason is because, the permissions of Network service account should be provided.
Configuring the Build definition
- Make sure the configured agent is up and running
Note: You must cross check the capabilities of your agents once configured. See to it that the Android SDK shows up with the API levels that you have installed already in your Android SDK as shown below-
In my case I have 4 API levels installed.
- Select the “Gradle task” from the list of templates as shown below-
In the options you can pass the arguments as per your needs.
As you can see, this task has many options to perform like code analysis, sonar qube, running unit tests etc. You can setup as per the needs. Since i am performing a neat gradle build, i am not considering it!
2. Map the Location of Gradle wrapper. “.gradle.bat” is the file to be mapped
4.If you want to run a Parallel build, change the options or else retain as it is.
5.Choose your Repository type
6. Choose the trigger that you want for this build definition
7. Select the agent queue that you want to run this build against.Since we have configured one, we will be using default agent.
8. Select copy files task from the utility-
9. Since we are copying the .apk files, pass the below arguments as shown-
$(build.sourcesdirectory) = The local path on the agent where your source code files are downloaded. For example:
$(build.artifactstagingdirectory) = The local path on the agent where any artifacts are copied to before being pushed to their destination. For example:
10. Add the ” Publish build artifacts” task from the utility-
11. Copy the output to the server/file shared path.
12. Post the build, checkout the detailed summary
13. Navigate to the artifacts tab from the build summary page to verify whether the apk’s are generated and voila