Cannot add task 'clean' as a task with that name already exists - java

I have a project that I started in Java on Android Studio and I want to continue it in Kotlin. So I configured my project to integrating Kotlin by this way "Configure Kotlin in Project"
After that Android Studio changed my twice build.gradle files. But from that moment my sync started to fail.
there is my build.gradle file where the error occurs :
before :
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
after :
buildscript {
ext.kotlin_version = '1.3.21'
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.2.0'
}
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.21'
}
repositories {
mavenCentral()
}
allprojects {
repositories {
google()
jcenter()
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I get the following error :
Cannot add task 'clean' as a task with that name already exists.
When I remove the task clean I get the error :
1

After created a new Kotlin project and took a look about the build.gradle file
I adapted mine and it worked as well !
There is my current build.gradle file
buildscript {
ext.kotlin_version = '1.3.21'
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
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
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Related

Is Jitpack needed as repository if I am using mavenCentral()?

So I am working on an old project in which I have the following code in the project build.gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath 'com.google.gms:google-services:4.3.13'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Android Studio is warning me to use mavenCentral() instead of jcenter() as jcenter is not being updated. So I have change it to the following code:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath 'com.google.gms:google-services:4.3.13'
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
So my question is, if now I am using mavenCentral() instead of jcenter(), do I have to use the " maven { url "https://jitpack.io" }" line of code or I should´t use it? I mean, the correct code
would be the following instead of the previous code? ->
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath 'com.google.gms:google-services:4.3.13'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Or actually I should use the code line of maven jitpack (maven { url "https://jitpack.io" }") although now I am using mavenCentral() instead of jcenter()?
Or actually I should use the code line of maven jitpack (maven { url "https://jitpack.io" }") although now I am using mavenCentral() instead of jcenter()?
The choice of mavenCentral() versus jcenter() has nothing to do with jitpack.io and whether you should be using it as a repository.
You need a repository to obtain artifacts hosted by that repository. So, for example, you need the google() repository for most of Google's artifacts, such as the com.google.gms:google-services that you are using.
Whether you need jitpack.io will depend on whether you have any dependencies that come from that repository. We have no way of telling whether you do or you do not.
A comment on your question suggests removing it and seeing if your build breaks. That will not work immediately, as Gradle caches downloaded artifacts and usually works off of your cached copy. Your build would break in the future if you try updating the version of some dependency and none of the other repositories host that artifact (at least for that version).
The safest thing to do is to go through all your dependencies (everything listed in a dependencies closure in your project-level and module-level build.gradle files) and identify where they come from. Perhaps add comments to your Gradle files to help you keep track. If you find that none of your dependencies seem to come from jitpack.io, you can remove that repository.

Material Search Bar from github not working

I get an error saying "Failed to resolve: com.github.mancj:MaterialSearchBar:0.8.5"
any ideas on how to fix this?
my build gradle proj
buildscript {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.3"
classpath 'com.google.gms:google-services:4.3.10'
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build gradle app:
dependencies {
.....
implementation 'com.github.mancj:MaterialSearchBar:0.8.5'
} ```
Try adding this to your project's build.gradle(the one you showed in the first):
allprojects​ { repositories { google() mavenCentral() jcenter() } ​}
Edit: Just checked the library you were asking about. It asks you to add that maven { url ....} in the repositories section of allprojects as well:
Try adding maven { url "https://jitpack.io" } in your settings.gradle file:
settings.gradle (Project Settings)
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url "https://jitpack.io" } <-- here
}
}
rootProject.name = "StackOverflow"
include ':app'
I think this happens because Build is configured to prefer settings repositories over project repositories

Gradle project refresh failed Error: Cannot find JAR 'kotlin-compiler-embeddable-1.1.3-2.jar'

I created a new project and getting following Gradle Sync error.
Gradle 'ProjectX' project refresh failed Error: Cannot find JAR 'kotlin-compiler-embeddable-1.1.3-2.jar' required by module 'gradle-kotlin-dsl' using classpath or distribution.
I am not using 'Kotlin' and using Android 4.0(IceCreamSandwich). Below is my build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Android : build.gradle problem after add sdk

I've add the SDK to the builder.gradle like this
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
dependencies {
compile 'com.kontaktio:sdk:3.0.2'
}
packagingOptions {
exclude 'main/AndroidManifest.xml'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
But it return an error
ERROR: Could not find method compile() for arguments [com.kontaktio:sdk:3.0.2] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Please help me to fix it.
You need to move the following block from your project build.gradle:
dependencies {
compile 'com.kontaktio:sdk:3.0.2'
}
packagingOptions {
exclude 'main/AndroidManifest.xml'
}
to your module build.gradle (usually app module).
your project build.gradle dependencies block must use classpath instead of compile. Your project build.gradle should be something like this:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Please take a look Configure your build for more details.
They change the 'compile' into 'implementation' on latest gradle, so you need to change
dependencies {
compile 'com.kontaktio:sdk:3.0.2'
}
to
dependencies {
implementation 'com.kontaktio:sdk:3.0.2'
}

Cannot resolve symbol 'services' import com.google.api.services;

I am trying to follow this sample for google-api-java-client for android app but in my andoid project it is not resolving the symbol services and drive. I downloaded the lib files of google-api-java-client and copied it to the apps lib folder.
Included following to app build.gradle
implementation 'com.google.android.gms:play-services-drive:15.0.1'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation "com.google.android.gms:play-services-gcm:15.0.1"
implementation 'com.google.android.gms:play-services-identity:15.0.1'
implementation 'com.google.apis:google-api-services-storage:v1-rev134-1.23.0'
and added the following to project build.gradle
buildscript {
repositories {
google()
maven {url "https://maven.google.com"}
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.google.gms:google-services:3.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
maven {url "https://maven.google.com"}
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
but still I am getting the error that can not resolve the symbol.

Categories