【问题标题】:Gradle plugin 'com.apollographql.apollo' not syncing in Android StudioGradle 插件“com.apollographql.apollo”未在 Android Studio 中同步
【发布时间】:2021-05-31 16:50:07
【问题描述】:

我正在尝试在我的 Android 项目中为 Kotlin 安装 apollo graphql 插件。

根据Apollographql installation for Kotlin 的说明,我正在尝试使用旧语法进行安装。

我的 build.gradle(app) 文件:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.apollographql.apollo'

android {
    compileSdkVersion 29

    defaultConfig {
        applicationId "com.example.goonlinepackagescanner"
        minSdkVersion 26
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.1'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    implementation "com.apollographql.apollo:apollo-gradle-plugin:2.3.1"
    implementation "com.apollographql.apollo:apollo-runtime:2.3.1"
    implementation "com.apollographql.apollo:apollo-coroutines-support:2.3.1"
}

我的 build.gradle(project) 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = '1.4.10'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.0"
        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
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

当我尝试同步 gradle 文件时出现以下错误:

Plugin with id 'com.apollographql.apollo' not found.

我一直试图找出问题所在,但无法做到。对此的任何帮助将不胜感激。

【问题讨论】:

    标签: android android-studio kotlin graphql


    【解决方案1】:

    所以我只是想出了为什么 gradle 没有同步。首先,build.gradle(app) 文件是完全正确的。它没有任何变化。其次,您必须做的主要更改或添加是在 build.gradle(project) 文件中添加以下行:

    classpath "com.apollographql.apollo:apollo-gradle-plugin:2.3.1"
    

    就在依赖项 {} 块中的注释上方。

    因此,build.gradle(project) 文件现在如下所示:

    // 顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项。

    buildscript {
        ext.kotlin_version = '1.4.10'
        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath "com.android.tools.build:gradle:4.0.0"
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath "com.apollographql.apollo:apollo-gradle-plugin:2.3.1"
            // 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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-06
      • 2016-09-24
      • 2022-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多