microsoft / vsts-cordova-tasks

Streamline CI setup for your Apache Cordova, PhoneGap, Ionic, or Cordova CLI compatible app using a set of useful pre-defined build steps for VS Team Services or TFS
http://go.microsoft.com/fwlink/?LinkID=691188
Other
25 stars 27 forks source link

Cordova Build task fails, unable to find Gradle #76

Closed cocowalla closed 7 years ago

cocowalla commented 7 years ago

I'm trying to setup a build definition to build an Android app. The npm install task succeeds, as does the Ionic Command task (which I use to do ordova platform add android.

I have the Cordova Build task configured to use Cordova 7.0.1 (which works fine for our local builds), but the task is failing with:

{ CordovaError: Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle 
in your path, or install Android Studio
     at Object.module.exports.check_gradle (d:\a\1\s\platforms\android\cordova\lib\check_reqs.js:146:18)
     at GradleBuilder.prepEnv (d:\a\1\s\platforms\android\cordova\lib\builders\GradleBuilder.js:176:23)
     at Api.module.exports.run (d:\a\1\s\platforms\android\cordova\lib\build.js:152:20)
     at d:\a\1\s\platforms\android\cordova\Api.js:348:43
     at _fulfilled (d:\a\1\s\platforms\android\cordova\node_modules\q\q.js:854:54)
     at self.promiseDispatch.done (d:\a\1\s\platforms\android\cordova\node_modules\q\q.js:883:30)
     at Promise.promise.promiseDispatch (d:\a\1\s\platforms\android\cordova\node_modules\q\q.js:816:13)
     at d:\a\1\s\platforms\android\cordova\node_modules\q\q.js:624:44
     at runSingle (d:\a\1\s\platforms\android\cordova\node_modules\q\q.js:137:13)
     at flush (d:\a\1\s\platforms\android\cordova\node_modules\q\q.js:125:13)
   name: 'CordovaError',
   message: 'Could not find an installed version of Gradle either in Android Studio,\nor on your system to install the gradle wrapper. Please include gradle \nin your path, or install Android Studio' 

I've tried this with both the Hosted and Hosted VS2017 agents, with the same result.

johnwargo commented 7 years ago

This is a known issue with the Cordova CLI (has nothing to do with VS TACO). I encountered this last week setting up a new Cordova development environment. If you read the error message its telling you it can't find Gradle. Install Gradle and the problem will go away.

For some reason the CLI can't seem to find the one installed with Android Studio. That's what I experienced anyway.

cocowalla commented 7 years ago

@johnwargo I did read the error message, I just figured that gradle must be installed already. Wondered if there was some way to get it to recognise the existing gradle.

Anyway, I just setup a couple of tasks to install gradle, and it does now work.

To help others, I used a Powershell script to download gradle:

Param([Parameter(Mandatory=$True,Position=1)]
    [string]$BaseDir)

$Url = "https://services.gradle.org/distributions/gradle-4.1-bin.zip"
$DownloadDir = [IO.Path]::Combine($BaseDir, "temp")
$DownloadPath = [IO.Path]::Combine($BaseDir, "temp\gradle.zip")
$OutputPath = [IO.Path]::Combine($BaseDir, "gradle")

Write-Host "Paths:"
Write-Host "`tBase path     : ${BaseDir}"
Write-Host "`tDownload path : ${DownloadPath}"
Write-Host "`tOutput path   : ${OutputPath}"
Write-Host

# Create download directory
New-Item -ItemType Directory -Force -Path ${DownloadDir} | Out-Null

# Download gradle ZIP file
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($Url, $DownloadPath)

# Extract gradle from the ZIP file
Expand-Archive $DownloadPath -DestinationPath $OutputPath

Note for this one I set the Arguments in the task to $(Agent.BuildDirectory)

I also used a one-line batch file to prefix the PATH environment variable with the location of our downloaded gradle (I got an access error when trying to change it from Powershell; seems you need to use a Run script task with Modify Environment enabled):

SET PATH=%1;%PATH%

Note for this one I set the Arguments in the task to $(Agent.BuildDirectory)\gradle\gradle-4.1\bin

cocowalla commented 7 years ago

Actually, I take it back - the build task succeeds, but the assets\www folder in the generated apk doesn't appear to contain any of my code, just default Cordova stuff :(

meetgaurang commented 6 years ago

So, shall we reopen this issue please?

ChrisProlls commented 6 years ago

Any news about it ?

drewgillies commented 6 years ago

Apologies if this appears a little boiler-plate, but Visual Studio 2017 (and by extension MSBuild and vsts-cordova-tasks) only support Cordova v6.3.1. Are there any failures using this version?

ChrisProlls commented 6 years ago

I used the Mac Agent for VSTS so it's working now