Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Android Gradle Plugin: Cannot Access Publisher

Tags:

android

gradle

I am using Android studio 3.4.2

My build.gradle file as follows

I am getting this error and not able to run the app since I upgraded the android studio.

I converted the code to androidx.

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    ext.realmVersion = '5.9.1'
    ext.googleServiceVersion = '4.2.0'
    repositories {

        mavenCentral()
        google()
        jcenter()
        maven {
            url "http://storage.googleapis.com/r8-releases/raw/master"
        }
        maven { url "https://jitpack.io" }

    }
    dependencies {
        classpath 'com.android.tools:r8:522bd9fc1d398753fed5134b6c4fe32cdae482be'  // Must be before the Gradle Plugin for Android.
        classpath 'com.android.tools.build:gradle:3.4.2'
        //  classpath 'com.android.tools.build:gradle:3.5.0-alpha13'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
        classpath "io.realm:realm-gradle-plugin:$realmVersion"
        classpath "com.google.gms:google-services:$googleServiceVersion"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {

    repositories {

        mavenCentral()
        maven { url "https://jitpack.io" }
        google()
        jcenter()
    }
}

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

My App level build gradle

apply plugin: 'com.android.application'

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://jitpack.io" }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'


android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.xxx.xxx"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        multiDexEnabled true
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        disable 'RestrictedApi'
        disable 'MissingTranslation'
    }//this until  Google release a fix .bottomsheet super

    dexOptions {
        preDexLibraries true
        javaMaxHeapSize "4g"
        dexInProcess = true
    }

    packagingOptions {
        exclude '.readme'
        exclude 'LICENSE.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/README.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        exclude 'META-INF/MANIFEST.MF'
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    //noinspection GradleCompatible

    def supportLibsVer = '1.0.0-beta01'

    implementation "androidx.appcompat:appcompat:1.1.0-rc01"
    implementation "androidx.cardview:cardview:$supportLibsVer"
    implementation "androidx.recyclerview:recyclerview:1.1.0-beta01"

    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation('com.android.support:multidex:1.0.1') {
        exclude module: 'support-v4'
    }
    implementation files('libs/DataVaultLib-2.3.3.13.jar')
    implementation 'org.apache.commons:commons-lang3:3.6'

    //CardView

    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
    implementation 'com.squareup.okhttp3:okhttp:3.12.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'


    //Image Picker

    implementation 'com.github.jrvansuita:PickImage:2.2.4'
    implementation 'com.squareup.picasso:picasso:2.71828'

    implementation('com.mikepenz:materialdrawer:6.0.7@aar') {
        transitive = true
    }

    //For Firebase
    implementation 'com.google.firebase:firebase-auth:18.1.0'
    implementation 'com.google.android.gms:play-services-auth:17.0.0'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation 'com.google.firebase:firebase-messaging:19.0.1'

    //For Google Places

    implementation('com.google.android.gms:play-services-places:16.1.0') {
        exclude module: 'support-v4'
    }
    implementation('com.google.android.gms:play-services-location:16.0.0') {
        exclude module: 'support-v4'
    }
    implementation('com.google.android.gms:play-services-maps:16.1.0') {
        exclude module: 'support-v4'
    }

    //for event bus
    implementation 'org.greenrobot:eventbus:3.1.1'


    //Room Database
    // Room
    implementation 'android.arch.persistence.room:runtime:1.1.1'
    annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'


    implementation('com.paytm:pgplussdk:1.3.3') {
        transitive = true;
    }
//
//    implementation 'com.google.android.libraries.places:places:1.1.0'


}
apply plugin: 'com.google.gms.google-services'

I go through this question of stackoverflow solve error: cannot access Publisher in Android Studio?

But it is not helpful.

like image 626
Sandeep Londhe Avatar asked Jun 12 '26 09:06

Sandeep Londhe


1 Answers

I had this same problem as soon as I upgraded to gradle 5.x (plugin 3.4+). In my case it was caused by two seemingly unrelated conditions:

1) Having a dependency on retrofit's adapter-rxjava2 plugin (without the accompanying io.reactivex.rxjava2 dependencies):

implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'

2) Having a Room DAO with a query function that returns a List directly:

@Dao
interface UserDao {
    @Query("SELECT * FROM user")
    fun getUsers(): List<User>
}

The easiest solution was removing the adapter-rxjava2 dependency since I wasn't using it anymore anyway (and you likely aren't either since you don't include io.reactivex.rxjava2 dependencies, hence the error).

I also found that changing the return type of the DAO function from List to Array also solved the problem for whatever reason. The actual underlying cause as to why these two things combine to cause this error is still a mystery to me, though.

like image 187
alexc Avatar answered Jun 14 '26 22:06

alexc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!