How to resolve gradle sonarqube compatibility error? [duplicate] - android

Android sonarqube worked until I updating android studio. Now it gives an error
FAILURE: Build failed with an exception.
* What went wrong:
com.android.build.gradle.api.ApkVariant.getCompileLibraries()Ljava/util/Collection;
I think this happens because gradle dependency syntax changed from 'compile' to 'implementation' like below in newest android version.
from
dependencies {
compile ........
compile ........
}
to
dependencies {
implementation ........
implementation ........
}
Can anyone please help me to configure sonarqube for new android version

Read the last part of the answer to get the latest updates
Original answer
I've performed some researches:
here you can
find the issue tracked internally by SonarQube
here you
can find the issue opened by a SonarQube developer asking Google
about the API change. As stated by Google engineers this change is intended and an alternative API already exists. SonarQube stated they won't support android plugin 3.0.0 until the final release or at least RC version
Result:
To continue to work you are forced to build your project with the current stable Android Studio and Android plugin v2.X.X
UPDATE - 6th November 2017
SonarQube released the new version 2.6 which is fully compatible with the AGP (Android Gradle Plugin) 3.0.0.
buildscript {
repositories {
google()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.1"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
apply plugin: "org.sonarqube"
More info in the release page HERE

You can use my solution https://github.com/SonarSource/sonar-scanner-gradle/pull/33
buildscript {
repositories {
jcenter()
google()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.android.tools.build:gradle:3.0.0"
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6-rc1"
}
}
apply plugin: 'org.sonarqube'

After sonarqube 2.6 was released just updating the plugin was enough for me
plugins {
id "org.sonarqube" version "2.6"
}

Updating Benoit answer, the official sonar scanner gradle plugin (v2.6-rc1) already supports the new gradle syntax. So, update your root gradle script to:
buildscript {
repositories {
jcenter()
google()
maven {
url "https://jitpack.io"
}
}
dependencies {
classpath "com.android.tools.build:gradle:3.0.0"
classpath "com.github.SonarSource:sonar-scanner-gradle:2.6-rc1"
}
}
apply plugin: 'org.sonarqube'

Try to use lower version of gradle

Related

Error when upgrading Android Studio to gradle version 5.6.4

A problem occurred configuring project ':feature-ABC'.
> 'kotlin-android' expects one of the Android Gradle plugins to be applied to the project:
* android
* com.android.application
* android-library
* com.android.library
* com.android.test
* com.android.feature
* com.android.dynamic-feature
* com.android.instantapp
Gradle build is failing for an existing project after updating Android Studio gradle to 5.6.4. My plugin version is 3.6.1. It was previously working for Android Studio gradle 5.2.1 and plugin version 3.3.0.
I am relatively new to Android Studio so please ignore my ignorance about something basic that I might be missing. But this error really has me stumped.
EDIT: Posting build.gradle file
apply from: rootProject.file('jacoco-full-report.gradle')
buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://maven.google.com" }
maven { url "https://microsoft-maps.bintray.com/Maven" }
}
dependencies {
apply from: 'dependencies.gradle'
classpath pluginDep.androidGradle
classpath pluginDep.jacoco
classpath pluginDep.kotlin
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://www.jitpack.io" }
mavenCentral()
}
jacoco {
toolVersion = '0.8.2'
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I realise the source of the error now.
com.android.feature and various other plugins have been deprecated in the newer gradle version. So either I had to migrate to new plugins (instant apps) or revert to old gradle (which I am doing because this a collaborative project and I don't have the authority to make structural changes)

Unable to load class 'com.android.builder.Version' after upgrade to Android Studio 3.1

I've upgraded to Android Studio 3.1 in Canary channel and I cannot build my project anymore, this error is printed:
Unable to load class 'com.android.builder.Version'. Possible causes
for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync
project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build
processes (requires restart)
Your project may be using a third-party plugin which is not compatible
with the other plugins in the project or the version of Gradle
requested by the project. In the case of corrupt Gradle processes, you
can also try closing the IDE and then killing all Java processes.
I already tried both of those solutions and also tried deleting all the ~/.gradle/caches directory but the error persists.
Looking for similar error I've found the old version of Android Studio having this issues with the suggested solution to upgrade the android tools version.
I think I already have the last one:
classpath 'com.android.tools.build:gradle:3.1.0-alpha01'
EDIT (30 Oct 2017):
Answers show that someone is having the issue while someone isn't.
As pointed out in the comments to this question this can be caused by a non compatible plugin, so I list the plugins used in my project here:
buildscript {
ext.kotlin_version = '1.1.51'
repositories {
jcenter()
google()
// maven {
// url 'https://maven.google.com'
// }
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.gradle:build-scan-plugin:1.10"
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.1'
classpath 'com.android.tools.build:gradle:3.1.0-alpha01'
classpath 'com.google.gms:google-services:3.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
The dexcount one is currently not used tough because of some incompatibilities with newer versions of Android plugin.
I had the same issue and what we have in common is the dexcount plugin. Disabling this issue until the two plugins are compatible. See dexcount bug report.
"updating to dexcount 0.8.2 fixes the issue"
Apparently going back to a previous version of the Android Tools plugin works:
classpath 'com.android.tools.build:gradle:3.0.0'
But the IDE ask me if I want to update to 3.1.0-alpha1 so I wander if this is a bug or if the issue lay somewhere else.
I just leave this solution here until someone else come up with another explanation.
No idea why your build is not working, but after a clean install of Android Studio 3.1 and using this setting everything works fine compiling a large project which contains several libraries (and mixed with java, kotlin).
buildscript {
ext {
gradle_version = "3.1.0-alpha01"
kotlin_version = "1.1.51"
}
repositories {
maven {
url 'https://maven.google.com'
}
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
jcenter()
google()
}
dependencies {
classpath "com.android.tools.build:gradle:$gradle_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
maven {
url 'https://maven.google.com'
}
jcenter()
google()
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xmaxerrs" << "500"
}
}
}
and my app-based gradle.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
...
}
i changed my class path line in gradle (project : project name) and issue is gone.
classpath 'com.android.tools.build:gradle:3.1.2'

Downgrade Android Plugin in Android Studio

I've got two workstations with Android Studio installed. The first one is having version 2.3.3, but the other one is having version 3.0. Both of them are using Gradle 3.3. The problem that I am facing is that when I create an application on the 3.0 system and then transfer it to the 2.3.3 it doesn't want to build. I am receiving
Could not resolve all dependencies for configuration ':classpath'.
> Could not find com.android.tools.build:gradle:3.0.0.
Searched in the following locations:
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.jar
I compared a build.gradle file created from the older version of Android Studio and from the newer version
3.0 version:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2.3.3:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
allprojects {
repositories {
jcenter()
}
}
From the 3.0 version, I removed "google()", because it was also failing.
I am new to Android Development and I would really appreciate it if you can help me to solve my problem of using one project on both of the environments.
Could not resolve all dependencies for configuration ':classpath'. > Could not find com.android.tools.build:gradle:3.0.0. Searched in the following locations: https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom
It happens because you are using the wrong repository.
If you want to use android plugin for gradle 3.x you have to use:
buildscript {
repositories {
...
// You need to add the following repository to download the
// new plugin.
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
}
It requires also gradle v4.+ using in gradle/wrapper/gradle-wrapper.properties :
distributionUrl=\
https\://services.gradle.org/distributions/gradle-4.1-all.zip
If you are using Android Studio 2.x you have to change the repository google() with maven { url "https://maven.google.com" }
If you want to use the android plugin for gradle 2.3.x you can use:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
and you can use gradle v.3.3 with:
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Of course in this case you can't use the new DSL introduced with gradle v.4.x and the plugin 3.x for example the implementation() and api() DSL.
Android plugin 3.0 located in Google Maven Repository (google() line) and it requires new Gradle. You should update Gradle to version 4.1.
Open file gradle/wrapper/gradle-wrapper.properties and set
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
If you are using android studio <3.0 then go to gradle-wrapper.properties and change the gradle from 4.1 to 3.3.
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Go to top level gradle and change the gradle version from 3.0.0 to 2.3.3 and then it should work fine.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
If you are using android studio >3.0 then Go to gradle-wrapper.properties and change the gradle to 4.1.
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Go to top level gradle and change the gradle version from 3.0.0 and then it should work fine.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}

SonarQube - Android not working for gradle 3.0.0

Android sonarqube worked until I updating android studio. Now it gives an error
FAILURE: Build failed with an exception.
* What went wrong:
com.android.build.gradle.api.ApkVariant.getCompileLibraries()Ljava/util/Collection;
I think this happens because gradle dependency syntax changed from 'compile' to 'implementation' like below in newest android version.
from
dependencies {
compile ........
compile ........
}
to
dependencies {
implementation ........
implementation ........
}
Can anyone please help me to configure sonarqube for new android version
Read the last part of the answer to get the latest updates
Original answer
I've performed some researches:
here you can
find the issue tracked internally by SonarQube
here you
can find the issue opened by a SonarQube developer asking Google
about the API change. As stated by Google engineers this change is intended and an alternative API already exists. SonarQube stated they won't support android plugin 3.0.0 until the final release or at least RC version
Result:
To continue to work you are forced to build your project with the current stable Android Studio and Android plugin v2.X.X
UPDATE - 6th November 2017
SonarQube released the new version 2.6 which is fully compatible with the AGP (Android Gradle Plugin) 3.0.0.
buildscript {
repositories {
google()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.1"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
apply plugin: "org.sonarqube"
More info in the release page HERE
You can use my solution https://github.com/SonarSource/sonar-scanner-gradle/pull/33
buildscript {
repositories {
jcenter()
google()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.android.tools.build:gradle:3.0.0"
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6-rc1"
}
}
apply plugin: 'org.sonarqube'
After sonarqube 2.6 was released just updating the plugin was enough for me
plugins {
id "org.sonarqube" version "2.6"
}
Updating Benoit answer, the official sonar scanner gradle plugin (v2.6-rc1) already supports the new gradle syntax. So, update your root gradle script to:
buildscript {
repositories {
jcenter()
google()
maven {
url "https://jitpack.io"
}
}
dependencies {
classpath "com.android.tools.build:gradle:3.0.0"
classpath "com.github.SonarSource:sonar-scanner-gradle:2.6-rc1"
}
}
apply plugin: 'org.sonarqube'
Try to use lower version of gradle

Could not find com.android.tools.build.gradle:3.0.0-alpha7

I update the gradle plugin to the latest, and i'm getting this error:
Error:Could not find com.android.tools.build.gradle:3.0.0-alpha7:.
Searched in the following locations:
file:/C:/Users/dmin/Documents/android-studio/gradle/m2repository/com/android/tools/build/gradle/3.0.0-alpha7//3.0.0-alpha7-.pom
file:/C:/Users/dmin/Documents/android-studio/gradle/m2repository/com/android/tools/build/gradle/3.0.0-alpha7//3.0.0-alpha7-.jar
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-alpha7//3.0.0-alpha7-.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-alpha7//3.0.0-alpha7-.jar
https://maven.google.com/com/android/tools/build/gradle/3.0.0-alpha7//3.0.0-alpha7-.pom
https://maven.google.com/com/android/tools/build/gradle/3.0.0-alpha7//3.0.0-alpha7-.jar
Here's my build.gradle
buildscript {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build.gradle:3.0.0-alpha7'
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Where i'm getting wrong? since i modified my gradle.build according to the question Could not find com.android.tools.build:gradle:3.0.0-alpha1 in circle ci
thank you!!
-- Updated the build.gradle according to Mr Tim, but i'm still having the same error
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build.gradle:3.0.0-alpha7'
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Follow the steps in the 3.0.0 plugin migration guide
Update gradle version
The new Android plugin requires Gradle version 4.1-milestone-1 or
higher. If you're opening an existing project using Android Studio 3.0
Preview 5 or later, follow the prompts to automatically update an
existing project to the compatible version of Gradle.
To update Gradle manually, update the URL in gradle-wrapper.properties
as follows:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-milestone-1-all.zip
and
Apply the plugin
If you're opening an existing project using Android
Studio 3.0 Preview 5 or later, follow the prompts to automatically
update your project to the latest version of the Android plugin. To
manually update your project, include the maven repo and change the
plugin version in your project-level build.gradle file as follows:
buildscript {
repositories {
...
// You need to add the following repository to download the
// new plugin.
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1' //Minimum supported Gradle version is 4.6
}
}
You try :
buildscript {
repositories {
...
// You need to add the following repository to download the
// new plugin.
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
Credits: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html
If you're in Android Studio 3.1 or higher, you're likely encounter such type of issue prompting by a Build window.
Simply click on the Add Google Maven repository and sync project option at right side and initiate another gradle sync.
It'll make the necessary changes in both gradle-wrapper.properties as well as build.gradle files.
Update gradle plugin : in gradle.properties file
add this line
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
then apply ther plugin in build.gradle file :
buildscript {
repositories {
...
// You need to add the following repository to download the
// new plugin.
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
the distributionUrl property inside gradle-wrapper.properties should be:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
that works for me
open the file path(just as the log said):
file:/C:/Users/dmin/Documents/android-studio/gradle/m2repository/com/android/tools/build/gradle/
found this file
just change classpath 'com.android.tools.build.gradle:3.0.0-alpha7'
to classpath 'com.android.tools.build.gradle:* * * ' ; * * * is the exist gradle file;
this problem is because of gradle file do not found

Categories

Resources