Rishab Parmar
Rishab Parmar

Reputation: 419

Gradle plugin 'com.apollographql.apollo' not syncing in Android Studio

I am trying to install apollo graphql plugin in my Android project for Kotlin.

As per the instruction from Apollographql installation for Kotlin, I am trying the installation process using the legacy syntax.

My build.gradle(app) file:

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"
}

My build.gradle(project) file:

// 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
}

It gives the following error when I try to sync the gradle file:

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

I have been trying to figure out what has went wrong but couldn't do so. Any help on this will be appreciated.

Upvotes: 6

Views: 5240

Answers (1)

Rishab Parmar
Rishab Parmar

Reputation: 419

So I just figured as why the gradle was not syncing. Firstly, the build.gradle(app) file is completely correct. No changes in it. Secondly, the main change or addition that you have to do to make it work is to add the following line in build.gradle(project) file:

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

just above the Note in the dependencies {} block.

So, the build.gradle(project) file will now look as follows:

// 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"
        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
}

Upvotes: 9

Related Questions