You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android集成AWS AppSync遇:app:nodeSetup失败及依赖解析问题

AWS AppSync集成Android时的Node依赖与仓库配置问题

在Android应用中集成AWS AppSync,按官方文档步骤添加com.amazonaws.appsync Gradle插件后,出现两个核心错误:

Could not resolve org.nodejs:node:6.7.0

同时伴随:

Execution failed for task ':app:nodeSetup'.

Build was configured to prefer settings repositories over project repositories but repository 'ivy' was added by unknown code

尝试指定Node版本为16.14.2后问题依旧,以下是当前的Gradle配置文件及解决办法:


现有配置文件

App build.gradle

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.amazonaws.appsync'
}

android {
    namespace 'com.example.awsappsyncdemo'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.awsappsyncdemo"
        minSdk 24
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled 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'
    }
//    node {
//        version = "16.14.2"
//    } //solution not working so commented
}

dependencies {
    implementation 'androidx.core:core-ktx:1.9.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.8.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

    // AWS dependencies
    implementation 'com.amazonaws:aws-android-sdk-appsync:3.3.1'
}

Project build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }

    dependencies {
        classpath 'com.amazonaws:aws-android-sdk-appsync-gradle-plugin:3.2.1'
    }
}
plugins {
    id 'com.android.application' version '7.4.2' apply false
    id 'com.android.library' version '7.4.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}
allprojects {
    repositories {
        google()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

settings.gradle

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.name = "AwsAppSyncDemo"
include ':app'

解决步骤

1. 统一AppSync SDK与插件版本

SDK和插件版本不一致会引发兼容性问题,将Project build.gradle中的插件版本改为与SDK一致的3.3.1:

buildscript {
    dependencies {
        classpath 'com.amazonaws:aws-android-sdk-appsync-gradle-plugin:3.3.1' // 修改为3.3.1
    }
}

2. 在settings.gradle中添加Node依赖仓库

由于settings中设置了RepositoriesMode.PREFER_SETTINGS,插件无法自行添加ivy仓库,需手动在dependencyResolutionManagement中添加Node的ivy源:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
    repositories {
        google()
        mavenCentral()
        // 添加以下仓库
        maven { url "https://plugins.gradle.org/m2/" }
        ivy {
            url "https://nodejs.org/dist/"
            patternLayout {
                artifact "[revision]/[artifact](-v[revision]-[classifier]).[ext]"
            }
            metadataSources {
                artifact()
            }
        }
    }
}

3. 正确配置Node版本

在App build.gradle中取消注释并保留Node版本配置,推荐使用LTS版本(如16.14.2或18.17.1):

android {
    // ... 其他配置
    node {
        version = "16.14.2"
        download = true // 确保自动下载指定版本
    }
}

4. 清理并重新构建

执行以下Gradle命令清理缓存并重新构建:

./gradlew clean build --refresh-dependencies

内容的提问来源于stack exchange,提问作者Sudhansu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 10:57:11