awslabs / aws-mobile-appsync-sdk-android

Android SDK for AWS AppSync.
https://docs.amplify.aws/sdk/api/graphql/q/platform/android/
Apache License 2.0
105 stars 58 forks source link

Gradle Error Using Android Studio 4.1 #320

Closed oras closed 3 years ago

oras commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 1 year ago

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

lindan4 commented 4 months ago

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

tylerjroach commented 4 months ago

Please upgrade to 3.4.1 which contains support for Apple Silicon chips

hackfreeee commented 3 months ago

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 commented 3 months ago

@hackfreeee can you show your build.gradle?

hackfreeee commented 3 months ago

@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 commented 3 months ago

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 commented 3 months ago

@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 commented 3 months ago

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 commented 3 months ago

Solved. Thank you so much.