TFS on-premise Xamarin cannot find AndroidSDK - android

I have a build definition set up in our on-prem TFS 2018 instance and it's just not working for us.
We have Visual Studio 2017 Enterprise installed on the TFS server instance, including Xamarin Studio, pointing to the default /program files (86)/android/android-sdk location, and we've created two (2) environment variables on the Server, called AndroidSDK and Xamarin.Android, yet we're still getting a build failure:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets (617, 2)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(617,2): Error XA5205: The Android SDK Directory could not be found. Please set via /p:AndroidSdkDirectory.
Process 'msbuild.exe' exited with code '1'.
We've tried setting /p:{} as an Additional parameter in the Android build step, but this also fails unexpectedly.
Are we missing something here? Any help would really be appreciated.
Note we're trying out on-premise for our team

This issue is most likely due to one or both of the following reasons:
Android SDK Tools are removed accidentally (or Antivirus has removed
these tools)
Android SDK Platform-tools are removed accidentally (or Antivirus
has removed these tools)
In case of this issue, SDK manager will not work. And the options to
run SDK Manager within Visual Studio will also be disabled. On the
Android SDK installation path one or both of the following folders
will be missing:
tools
platform-tools
So, you just need to reinstall the Tools. Please refer to Wasim's blog for details.
Besides, in TFS the build agent on the server runs in its own account (build service account), so the Android SDK must be accessible to it. which meant that a local build on the server may worked fine, but the TFS build agent couldn't access it and thus failed. In this case, you can move the SDK to an accessible place for the build agent service account, thus everything will be worked.
Refer to this link for details :
Resolving “The Android SDK Directory could not be found” building a Xamarin app via TFS build server

Related

Gradle won't pick up Android build tools unless opened in Android Studio

I'm preparing an Android build pipeline in Jenkins, on a Windows build server. Jenkins uses a number of workspaces and will often re-use them. I've noticed that when Jenkins re-uses a workspace, there are no problems and a build goes perfectly. But when it first checks out a new workspace, the gradle wrapper complains that it cannot install Android build-tools. The build tools (the exact version) are already installed.
I can open another older workspace and run the gradle build in there and it works perfectly and then, with the same login and in the exact same cmd session, go to the new workspace and run the same command and it complains that it cannot install Android build-tools.
A note about the Android configuration: I'm storing the Android SDK in C:\android-sdk\ and have given every user access to that directory. ANDROID_HOME and ANDROID_SDK are set as system-wide variables. This is the most convenient solution- this way every user that logs in, domain account or otherwise, is (in theory) able to immediately build the solution without having to set up their own SDK, and we don't end up with a lot of duplicated SDK data.
I can fix the issue manually by opening the workspace folder in Android Studio. Just doing this alone seems to fix the issue. My hypothesis is that somewhere there's a cached value in the project metadata telling gradle where to find the Android build-tools, and when I open Android Studio it updates this value.
Obviously the work-around isn't adequate because the build needs to work consistently every time without human intervention. Is there some command I can use to refresh this cache? Or perhaps some configuration files that are checked into git that shouldn't be?
Figured it out. Gradle looks in two places, in order of priority, for your SDK: Firstly, it checks whether a local.properties file specifies the SDK. Then, it tries the ANDROID_HOME (not ANDROID_SDK) system variable. Opening a folder in Android Studio generates the local.properties file, which is why that work-around worked.
I had no local.properties file, but my ANDROID_HOME was set to the Android Studio install folder rather than the Android SDK. When I moved it to the SDK and re-started the Jenkins agent service it worked.

Cordova gradle wrapper missing in android sdk

I'm on windows7 x64, installed today's latest stable release of android sdk studio (through android studio bundle, since it's shipped together now apparently). I have properly configured the environment variables as you'll see above.
This is what I get when issuing the following command
$ cordova build android
ANDROID_HOME=G:\installs\Android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_121
Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.
Looked here: G:\installs\Android\sdk\tools\templates\gradle\wrapper
And indeed, the "templates" directory doesn't even exist in my sdk install.
I've already tried the suggestions (setting the right path, uninstall/reinstall) of this question here but nothing applies to my case, and I find that manually copying and pasting packages is not really a solution, since there's a package manager in place.
If anybody has an answer as of today's android install, would be very much appreciated.
If still not working then copy all file from gradle\wrapper from Android Studio installation folder
C:\Program Files\Android\Android
Studio\plugins\android\lib\templates\gradle\wrapper
and paste it in your Android SDK gradle\wrapper then run same command.
E:\android-sdk\tools\templates\gradle\wrapper
This is a known issue; see CB-12544. For now you'll need to downgrade.
I downloaded Android SDK r25 manually and placed templates folder inside Android/sdk/tools. This solved the issue for me.
You can get it from https://dl.google.com/android/repository/tools_r25.2.3-macosx.zip
For Windows:
https://developer.android.com/studio/index.html
Go to the section :"Get just the command line tools"
There is a link 'sdk-tools-darwin-3859397.zip' for Mac, Unfortunately that didn't have the templates folder with Gradle Wrapper. So for Mac users, i will suggest not to go for this zip.

signing and aligning apk step: No matching files were found with search pattern

Recently I created a pool agent to automate a build definition for Xamarin Forms (Android) in TFS. Although almost all steps run succeded, signing and aligning apk step throws an error:
According error, no apk is found in C:\agent_work\1\b\release*.apk, however during building process I went to folder to check it out and I found the file:
I'm not being able to understand why error. Please need your help! Here build definition for step:
I solved it:
Signing process of the APK files depends on the Java tool called jarsigner. The java compilations that my Xamarin projects do in Visual Studio are done using JDK 8 (Jdk 1.8.0_111), however when reviewing the JDK version with which the Team Services Build Agent compiles, it depends on the variables of Environment that it recognized from the system and registered them in the capabilities when installing the agent in Team Services. %JAVA_HOME% was using the JDK 7 build path, different from the one used by Visual Studio for the same solution:
Visual Studio solution:
I actually have two Java versions installed on my PC, and because the SYSTEM CAPABILITIES have been built into Visual Team Services since the agent was first installed, it recognized the path configured in the environment variables of the operating system for %JAVA_HOME%, So it was necessary to adjust the path of this variable, uninstall the agent and reinstall it again. Subsequently the compilation already generated other errors: JAVA_HOME is not set, ANDROID_HOME is not set. This was solved by adding them as predefined variables in Team Services:
And That's it! Successful building:

how to build android apk in non-gui linux server

Want to set up a linux server only to build and test, and I found Android does not offer sdk only package anymore.
Previous sdk download page was redirect to studio download page.
I need android sdk package. but now Android only supply the sdk-tool, in my mind sdk-tool/ is under sdk/, like path-to-sdk/tools. When android project builds, I need to set env $ANDROID_HOME, and $ANDROID_HOME is the directory of the sdk/ not the sdk/tool/
I try the android-studio-linux, but the pack I unzipped can not found android sdk, it seems android download sdk on first run.
I try the to find the android-sdk, but only get the older releas.
Please give me some suggestion, how to build android apk in non-gui linux server, the server is Ubuntu 64bit.
Well they still offer, they just have moved it to bottom to promote Android Studio more over other other IDEs.
Check the bottom of the page or just use this link to download it for linux. You can very well use gradle to build and package your app so if there is actually no compulsion of using Android Studio.
Update Also this document explains how to develop Android apps/libs from commandline.

Android:How to avoid XML verification failed error and Upgrading to 2.x SDK successfully?

I have setup for Android development with 1.5 SDK on Mac O.S X - Eclipse 3.5. I want to upgrade the SDK, so as i followed to choose Window->Android SDK and AVD Manager from Eclipse. But it throws error as follows:
XML verification failed for
https://dl-ssl.google.com/android/repository/repository.xml.
Error: cvc-elt.1: Cannot find the declaration of element 'sdk:sdk- repository'. Failed to fetch URL
I tried "http" instead of https, but still getting the same error. I don't know why such crap error comes. If i see Android website,
https://developer.android.com/sdk/index.html
its confusing.
Could someone guide me easily to update Android SDK to 2.x or later without uninstalling my current setup environment.
If you are using a very old version of the tools, you will need to download a newer starter package from http://developer.android.com/sdk/index.html
The reason is that the schema of the repository XML file changed when we released rev 5, but only tools in revision 4 or higher can adapt to schema changes.
By the way once you download the new starter package you can replace the tools folder from your previous installation with the new one. That way you don't have to change PATH env var or any other setup you have.
Error:
XML verification failed for https://dlssl.google.com/android/repository/repository.xml.
Error: java.lang.NullPointerException
Solution:
This error occurs on Mac because, Java 6 is not installed by default on osX 10.5.6 or before and you need Java 6 to run Android AVD and SDK Manager.
The easiest way to overcome this error is by installing the latest version of Java.
You can find this blog useful.
If you are getting the error XML verification failed for https://dl-ssl.google.com/android/repository/repository.xml. Error: cvc-elt.1: Cannot find the declaration of element 'sdk:sdk- repository'. Failed to fetch URL
in mac os, then download android sdk (Mac OS X (intel) android-sdk_r15-macosx.zip) from http://developer.android.com/sdk/index.html. Unzip this package and copy this unzip package on your mac root directory (Macintosh HD) and rename this unzip package as android-sdk. Now open android-sdk->tools->android. The sdk update will start automatically. You dont need to install java 6. It is automatically installed in your mac os.

Categories

Resources