Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build Scan not working for Gradle in Android

I am following the Gradle tutorial on https://guides.gradle.org/building-android-apps/ . So the last step of this part is Run a Build Scan. I am doing the exact same thing as it asked me to do, but Android Studio keeps saying "Error:(14, 0) Could not get unknown property 'com' for root project 'HelloWorldGradle' of type org.gradle.api.Project."

Here is my Top-level build file(build.gradle(Project: HelloWorldGradle)):

// Top-level build file where you can add configuration options common to all        sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven { url 'https://plugins.gradle.org/m2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.4.0-alpha7'
        classpath 'com.gradle:build-scan-plugin:1.7.1'
    }
}  

apply plugin: com.gradle.build-scan

buildScan {
    licenseAgreementUrl = 'https://gradle.com/terms-of-service'
    licenseAgree = 'yes'
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
like image 873
Luke Avatar asked Jun 27 '17 19:06

Luke


People also ask

How do I run a Gradle scan?

In your existing gradle project simply run ./gradlew build --scan or gradle build --scan if you're not using the gradle wrapper. You'll be prompted to accept the Gradle Cloud Services license agreement.


2 Answers

My issue was solved after writing the following in build.gradle the top-level file for the project

plugins {
    id 'com.gradle.build-scan' version '1.16'
}

buildScan {
    licenseAgreementUrl = 'https://gradle.com/terms-of-service'
    licenseAgree = 'yes'
    publishAlways()
}
like image 169
Hasan El-Hefnawy Avatar answered Oct 14 '22 18:10

Hasan El-Hefnawy


The issue is with the following line in your build.gradle:

apply plugin: com.gradle.build-scan

You need to update as

apply plugin: 'com.gradle.build-scan'

Another thing you need to pay attention is ALWAYS put the com.gradle.build-scan plugin as the very first one, like this:

apply plugin: 'com.gradle.build-scan'
apply plugin: 'java'

Otherwise, you would see this:

WARNING: The build scan plugin was applied after other plugins. The captured data is more comprehensive when the build scan plugin is applied first.

Please see https://gradle.com/scans/help/plugin-late-apply for how to resolve this problem.

Let me know if this works.

like image 44
chenrui Avatar answered Oct 14 '22 18:10

chenrui