Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle Error Using Android Studio 4.1 #320

Closed
oras opened this issue Oct 20, 2020 · 12 comments
Closed

Gradle Error Using Android Studio 4.1 #320

oras opened this issue Oct 20, 2020 · 12 comments

Comments

@oras
Copy link

oras commented Oct 20, 2020

When I try to build my project, I am getting an error. Here is the Gradle error
trace:

A problem occurred configuring root project 'DOV'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not find com.github.node-gradle:gradle-node-plugin:2.2.4.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/github/node-gradle/gradle-node-plugin/2.2.4/gradle-node-plugin-2.2.4.pom
       - https://jcenter.bintray.com/com/github/node-gradle/gradle-node-plugin/2.2.4/gradle-node-plugin-2.2.4.pom
     Required by:
         project : > com.amazonaws:aws-android-sdk-appsync-gradle-plugin:3.1.0

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

AppSync SDK version: 3.1.1

My Android Studio version info:

Android Studio 4.1
Build #AI-201.8743.12.41.6858069, built on September 23, 2020
Runtime version: 1.8.0_242-release-1644-b01 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 2014M
Cores: 4
Registry: ide.new.welcome.screen.force=true, debugger.watches.in.variables=false, cidr.max.intellisense.file.length=1400000
Non-Bundled Plugins: com.thoughtworks.gauge, com.intellij.lang.jsgraphql, org.intellij.plugins.markdown, name.kropp.intellij.makefile, BashSupport, org.siprop.android.opencl.OpenCLCLGenerator, PythonCore, aws.toolkit

Gradle version: 6.7
Android Gradle Plugin version: 4.2.0-alpha13

@jamesonwilliams
Copy link
Contributor

jamesonwilliams commented Oct 20, 2020

Hi @oras. Have you included the Maven plugin repositories into your Gradle dependencies, as discussed in the project's README.md?

TLDR, ensure you have these additions to your top-level build.gradle:

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
        // ...
    }
    // ...
}

allprojects {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
        // ...
    }
    // ...
}

@msimic-dev
Copy link

msimic-dev commented Sep 3, 2021

According to this we should add our dependencies to the settings.gradle file.

Here is my settings.gradle

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon

        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
}
rootProject.name = "AWS Test"
include ':app'

And this is my top-level build.gralde

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()

        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30"
        classpath 'com.amazonaws:aws-android-sdk-appsync-gradle-plugin:3.1.2'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I'm getting this error message and can't really figure out why

Execution failed for task ':app:nodeSetup'.
> Build was configured to prefer settings repositories over project repositories but repository 'ivy' was added by unknown code

* 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.


@giorgospat
Copy link

Hi, any update on this? I have exactly the same problem as @msimic-dev. Running on a MacBook with M1 pro chip.

@lindan4
Copy link

lindan4 commented Apr 25, 2024

I am also facing the same problem as @msimic-dev.

@tylerjroach
Copy link
Contributor

Please upgrade to 3.4.1 which contains support for Apple Silicon chips

@hackfreeee
Copy link

Hi, @tylerjroach.
I upgraded to 3.4.1.
But I am also facing the same problem as @msimic-dev. Running on a MacBook with M3 pro chip.

@tylerjroach
Copy link
Contributor

@hackfreeee can you show your build.gradle?

@hackfreeee
Copy link

@tylerjroach
build.gradle.kts (project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    alias(libs.plugins.androidApplication) apply false
    alias(libs.plugins.jetbrainsKotlinAndroid) apply false
}

buildscript {
    repositories {
        // Add this maven block.
        maven(url="https://plugins.gradle.org/m2/")
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.amazonaws:aws-android-sdk-appsync-gradle-plugin:3.4.1")
    }
}

build.gradle.kts (app)

plugins {
    alias(libs.plugins.androidApplication)
    alias(libs.plugins.jetbrainsKotlinAndroid)
    id("com.amazonaws.appsync")
}

android {
    namespace = "com.example.myapplication"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.example.myapplication"
        minSdk = 24
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary = true
        }
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildFeatures {
        compose = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.5.1"
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
}

dependencies {

    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.lifecycle.runtime.ktx)
    implementation(libs.androidx.activity.compose)
    implementation(platform(libs.androidx.compose.bom))
    implementation(libs.androidx.ui)
    implementation(libs.androidx.ui.graphics)
    implementation(libs.androidx.ui.tooling.preview)
    implementation(libs.androidx.material3)
    testImplementation(libs.junit)
    androidTestImplementation(libs.androidx.junit)
    androidTestImplementation(libs.androidx.espresso.core)
    androidTestImplementation(platform(libs.androidx.compose.bom))
    androidTestImplementation(libs.androidx.ui.test.junit4)
    debugImplementation(libs.androidx.ui.tooling)
    debugImplementation(libs.androidx.ui.test.manifest)
}

settings.gradle.kts

pluginManagement {
    repositories {
        maven(url="https://plugins.gradle.org/m2/")
        google {
            content {
                includeGroupByRegex("com\\.android.*")
                includeGroupByRegex("com\\.google.*")
                includeGroupByRegex("androidx.*")
            }
        }
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        maven(url="https://plugins.gradle.org/m2/")
        google()
        mavenCentral()
    }
}

rootProject.name = "My Application"
include(":app")
 

error message

Execution failed for task ':app:nodeSetup'.
> Build was configured to prefer settings repositories over project repositories but repository 'ivy' was added by unknown code

@tylerjroach
Copy link
Contributor

The failure is coming from your settings.gradle.kts setup of repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS).

Can you try and replace that with repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) and report back?

@hackfreeee
Copy link

@tylerjroach
The following was output

Execution failed for task ':app:nodeSetup'.
> Could not resolve all dependencies for configuration ':app:detachedConfiguration10'.
   > Could not find org.nodejs:node:20.10.0.
     Searched in the following locations:
       - https://plugins.gradle.org/m2/org/nodejs/node/20.10.0/node-20.10.0.pom
       - https://dl.google.com/dl/android/maven2/org/nodejs/node/20.10.0/node-20.10.0.pom
       - https://repo.maven.apache.org/maven2/org/nodejs/node/20.10.0/node-20.10.0.pom
     Required by:
         project :app

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

@mattcreaser
Copy link
Contributor

Hi @hackfreeee @lindan4. This issue is caused by the Node Gradle Plugin being used adding a repository pointing to the nodejs.org distribution location. This plugin is used to install Node in order to run the Apollo codegen. Newer Gradle versions have centralized repository declarations in settings.gradle.kts and fail by default if anything else tries to add them.

The easiest workaround is to use repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) as suggested and to manually specify the repository in your settings.gradle.kts file. This is how I did it:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
    repositories {
        google()
        mavenCentral()
        ivy {
            name = "Node.js"
            setUrl("https://nodejs.org/dist/")
            patternLayout {
                artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]")
            }
            metadataSources {
                artifact()
            }
            content {
                includeModule("org.nodejs", "node")
            }
        }
    }
}

Please let us know if that resolves the issue.

@hackfreeee
Copy link

Solved. Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants