How do I fix gradle in Flutter? - gradle

I get this error running my project:
Error running Gradle:
ProcessException: Process
"/Users/jacobgjrva/AndroidStudioProjects/stage_me/android/gradlew"
exited abnormally:
Command:
/Users/jacobgjrva/AndroidStudioProjects/stage_me/android/gradlew
app:properties
Finished with error: Please review your Gradle project setup in
the android/ folder.
Do anyone know how to solve this? Thanks in advance!
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
}

Run the gradlew command with --stacktrace for details of the error.
Also check the build.gradle file.
In the block reported in the answer there are { } in the wrong place.
allprojects {
repositories {
google()
jcenter()
}
} //it is missing in your code
And:
task clean(type: Delete) {
delete rootProject.buildDir
}
}// You have to remove this.

Related

Unable to apply plugin in gradle init script

Here is my gradle init script.
initscript {
repositories {
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.5.1")
}
}
allprojects {
apply(plugin="java")
apply(plugin="application")
apply(plugin="org.springframework.boot.gradle.plugin.SpringBootPlugin")
repositories {
gradlePluginPortal()
mavenCentral()
}
}
However, I am getting Plugin with id 'org.springframework.boot.gradle.plugin.SpringBootPlugin' not found. error.
I have tried the solutions from the following questions but none of them solves the problem.
Add Android plugin to gradle init script
I have found my solution after googling around.
In order to apply plugins in gradle init script that is written in kotlin DSL,
one has to use the following
initscript {
repositories {
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.5.1")
}
}
allprojects {
apply(plugin="java")
apply(plugin="application")
apply<org.springframework.boot.gradle.plugin.SpringBootPlugin>()
repositories {
gradlePluginPortal()
mavenCentral()
}
}
In order to apply third party plugins in the init script, one has to use the form apply<path.to.classname>()

Could not find lint-gradle-api.jar (com.android.tools.lint:lint-gradle-api:26.1.2) flutter project

I have an error with lint-gradle-api.jar, I looked at other similar questions on the forums but I still have the problem.
Does anyone have an idea ?
Error running Gradle:
Exit code 1 from: C:\Users\bgbra\Documents\Flutter_apps\flutter_app\android\gradlew.bat app:properties:
Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.
FAILURE: Build failed with an exception.
Where:
Build file 'C:\Users\bgbra\Documents\Flutter_apps\flutter_app\android\app\build.gradle' line: 25
What went wrong:
A problem occurred evaluating project ':app'.
Could not resolve all artifacts for configuration 'classpath'.
Could not find lint-gradle-api.jar (com.android.tools.lint:lint-gradle-api:26.1.2).
Searched in the following locations:
https://jcenter.bintray.com/com/android/tools/lint/lint-gradle-api/26.1.2/lint-gradle-api-26.1.2.jar
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
build.gradle
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://dl.google.com/dl/android/maven2'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This is my build.gradle file. I don't know, will it help you.
buildscript {
ext.kotlin_version = '1.3.10'
repositories {
google()
jcenter()
maven {
url 'https://dl.google.com/dl/android/maven2'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:3.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
// global properties used in sub modules
ext {
versionCodeProp = 81100
versionNameProp = "0.8.11-dev"
versionBuild = System.getenv("BUILD_NUMBER") as Integer ?: 0
buildNumberProp = "${versionBuild}"
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
google()
}
}
Probably you shoul add maven to allprojects branch.

Import buildscripts in gradle

I am pretty new with gradle, I want to include a plugin globally, and I don't know how.
In my project(wish I DO NOT OWN), there are multiple build.gradle, and there is a commons.gradle folder. In there is created a script like this
myscript.gradle
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.nl.javadude.gradle.plugins:license-gradle-plugin:0.13.1"
}
}
Then in of the build.gradle I have this:
buildscript {
repositories {
mavenCentral()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
apply from: "$path-to/myscript.gradle", to: buildscript
}
apply plugin: "com.github.hierynomus.license"
but I keep getting a Plugin with id com.github.hierynomus.license" not found. I am using Gradle 3.1. any help or hint would greatly help.
Thanks
I was able to make this work by doing the following:
myScript.gradle
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.nl.javadude.gradle.plugins:license-gradle-plugin:0.13.1"
}
}
then in the build.gradle
buildscript {
repositories {
mavenCentral()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
apply from: "$path-to/myScript.gradle", to: buildscript
}
plugins{id "com.github.hierynomus.license" version "0.13.1"}
apply plugin: "com.github.hierynomus.license"
I was not able to find anything online, so I hope this will help someone one day.
ps: Sorry for my bad English

Plugin with id 'com.wonbin.myplugin' not found

I wrote a demo for learning gradle for android . i used the JAR
1) project root dir build.gradle
buildscript {
repositories {
jcenter()
flatDir {dirs 'build_libs'}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.wonbin.myplugin:MyPlugin:1.0'
}
}
apply plugin: 'com.wonbin.myplugin'
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have leanrd that the plugin id is the properties filename in the plugin project. But still when I run ./gradlew assemble , it happens:
Build file '/home/wonbin/MyApp/build.gradle' line: 13
What went wrong: A problem occurred evaluating root project 'MyApp'.
Plugin with id 'com.wonbin.myplugin' not found.
what should i do ?
Probably your build_dir doesn't correspond to the correct file structure. You can reference your jar in the classpath directly instead, like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath file('/path/to/your/plugin.jar')
}
}
apply plugin: 'com.wonbin.myplugin'

How to apply Cobertura plugin to all projects or all subprojects

I'm trying to apply the Cobertura plugin to all projects and subprojects in my Gradle build scripts. However, the scripts are unable to find the plugin when applied to all. Here is what I've got:
buildscript {
repositories {
jcenter()
}
}
allprojects {
beforeEvaluate {
project.buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'net.saliman:gradle-cobertura-plugin:2.2.7'
}
}
}
}
subprojects {
apply plugin: 'net.saliman.cobertura'
}
This is how build.gradle should look like:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'net.saliman:gradle-cobertura-plugin:2.2.7'
}
}
allprojects {
apply plugin: 'net.saliman.cobertura'
}
You may also find that you want to merge all your subprojects cobertura reports into one beautiful top level report for the entire project.
To do this you will need cobertura gradle plugin 2.2+ I believe and the configuration for that is something like:
// note - all non-cobertura config is stripped out of this example
allprojects {
apply plugin: 'cobertura'
}
subprojects {
cobertura {
coverageIgnoreTrivial = true
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "net.saliman:gradle-cobertura-plugin:2.2.2"
}
}
def files = subprojects.collect { new File(it.projectDir, '/build/cobertura/cobertura.ser') }
cobertura {
coverageFormats = [ 'xml', 'html' ]
coverageSourceDirs = subprojects.sourceSets.main.allSource.srcDirs.flatten()
coverageMergeDatafiles = files
}
test.dependsOn(subprojects.test)
which is from syncsynchalt's great comment on the issue here:
https://github.com/stevesaliman/gradle-cobertura-plugin/issues/10

Resources