Error: Could not parse the Android application Module's Gradle Config

Viewed 106085

I've been trying to setup Firebase in my Android project. Problem is, I've been getting this error:

Could not parse the Android application Module's Gradle Config

And I really can't solve it.

I've seen quite a lot of people getting this error, but it seems that they could solve it by upgrading their build tool version, or by updating google-services. I've done all that and haven't been able to make it work so far.

Here are my Gradle scripts:

apply plugin: 'com.android.application'

android {
signingConfigs {
    AndroidAppPro {
    }
}
compileSdkVersion 25
buildToolsVersion '26.0.0'
useLibrary 'org.apache.http.legacy'
defaultConfig {
    applicationId "com.critizr.pro"
    minSdkVersion 14
    targetSdkVersion 25
    versionCode 9
    versionName "1.5.1"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
productFlavors {
    preprod {
        applicationId "com.cr.pro"
        buildConfigField 'boolean', 'IS_PROD', 'false'
        buildConfigField 'String', 'HOST', '"https://myurl.com/"'
    }
    prod {
        applicationId "com.cr.pro"
        buildConfigField 'boolean', 'IS_PROD', 'true'
        buildConfigField 'String', 'HOST', '"https://myurl/"'
    }
}
packagingOptions {
     exclude 'META-INF/DEPENDENCIES.txt'
     exclude 'META-INF/LICENSE.txt'
     exclude 'META-INF/NOTICE.txt'
     exclude 'META-INF/NOTICE'
     exclude 'META-INF/LICENSE'
     exclude 'META-INF/DEPENDENCIES'
     exclude 'META-INF/notice.txt'
     exclude 'META-INF/license.txt'
     exclude 'META-INF/dependencies.txt'
     exclude 'META-INF/LGPL2.1'
   }
}

dependencies {
compile project(':lib-viewflow')

// new libs
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:cardview-v7:25.2.0'
compile 'com.android.support:recyclerview-v7:25.2.0'

compile 'com.google.android.gms:play-services-gcm:11.0.2'
compile 'com.google.android.gms:play-services-maps:11.0.2'
//compile 'com.google.android.gms:play-services-analytics:11.0.1'

compile 'org.apache.httpcomponents:httpclient:4.1'
compile 'org.apache.httpcomponents:httpmime:4.1'

compile 'com.joshdholtz.sentry:sentry-android:1.5.0'
compile 'com.borax12.materialdaterangepicker:library:1.6'
compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.cloudinary:cloudinary-core:1.2.2'
compile 'com.cloudinary:cloudinary-android:1.2.2'
compile 'com.loopj.android:android-async-http:1.4.5'
}
 apply plugin: 'com.google.gms.google-services'

And the second one:

 buildscript {
repositories {
    jcenter()
    maven { url "https://jitpack.io" }
}
 dependencies {
    classpath 'com.android.tools.build:gradle:2.3.1'
    classpath 'com.google.gms:google-services:3.1.0'
}
}

allprojects {
repositories {
    jcenter()
    maven { url "https://jitpack.io" }
}
}

37 Answers

For me by removing the warning of jCenter worked

jCenter()  remove it..

To solve this on Android Studio v3.1 (not sure about previous versions), just edit your app's build.gradle like this:

  • Look for: apply plugin: 'com.google.gms.google-services' and remove it then sync. Now you'll be able to use the Firebase Assistant with no issues.

Verify the build tab, and make sure you've got no warnings in there.

Firebase Assistant seems to be very sensitive to any Gradle info, warning, or error.

For me it was a simple "info" from gradle, that databinding.enabled is not required anymore:

 DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'.

Once removed, Firebase Assistant worked fine.

The Navigation Component's safeargs plugin can also cause this. To fix it, I temporarily removed id 'androidx.navigation.safeargs.kotlin' from app-level build.gradle file and then added it back in afterwards.

Commenting out apply plugin: io.fabric worked for me. So check your dependencies in your gradle file.

I think some of your dependencies are behind it . Just go to your build.gradle (module app) and comment out most of them or all of them (to find out which one) , sync again ignore all error for now and try connecting to firebase again if it's successful then you can go back to your build.gradle and uncomment them to fix errors.

Hope this helps

I had a problem for viewBinding. Did as in the instructions from Google and it all worked.

android {
    ...
    buildFeatures {
        viewBinding true
    }
}

This error occurs due to depreciation of the Compile keyword in built.gradle(app level)

      WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'. It will be removed at the end of 2018.

Its Solution is to

  1. Just replace the compile keyword with implementation or api in built.gradle(app level)

    &

  2. Rebuilt your project

Restart your Android Studio if not Solved after Rebuilt.

Conclusion

The real culprit is the warnings of your build.gradle. Firebase assistant is very sensitive, it checks for any warning (even deprecated one) in your build.gradle & then starts working. If it finds any, then you will get this error.

Solution

Just remove or resolve every warning of the build.gradle file. also, remove plugins that already exist of the same thing you are adding.

Remove all previous Firebase dependencies in your project and try again. Plugins and libraries.

I had this issue before because I had already setup Firebase manually.

Hope it helps.

If you are not use databinding remove from your app level gradle

 dataBinding {
    enabled = true
}

Remove these lines from your app level gradle

In my case this was caused because I used data binding in my project. Here is how I fixed the issue:

In your build.gradle(App level) set the dataBinding as follow:

Put this code in your build.gradle(Project level) under the buildTypes:

//Here is the code...
buildFeatures {
    dataBinding = true
}

Follow the solution step by step.

1. In Gradle Script/build.gradle(Project:your project name):

Add dependencies

dependencies {  
    classpath "com.android.tools.build:gradle:4.2.1"
    classpath 'com.google.gms:google-services:4.3.8'
 
}
    }

jcenter remove or do comment out:

   allprojects {
        repositories {
            google()
            mavenCentral()
           // jcenter() // Warning: this repository is going to shut down soon
        }
    }

2. In Gradle Script/gradle.properties:

android.useAndroidX=true

3. In Gradle Script/build.gradle(:app):

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
}

before build types add buildFeatures:

buildFeatures {
        dataBinding = true
    }
 

at the last:

 dependencies {
        implementation platform('com.google.firebase:firebase-bom:28.0.1')
        implementation 'com.google.firebase:firebase-analytics'
        implementation 'androidx.appcompat:appcompat:1.2.0'
        implementation 'com.google.android.material:material:1.3.0'
        implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
        implementation 'com.google.firebase:firebase-database:20.0.0'
        testImplementation 'junit:junit:4.+'
        androidTestImplementation 'androidx.test.ext:junit:1.1.2'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    }

4. Add google servises json file

location:
D:\AndroidStudioProjects\Whatsup_project\app

See the youtube video on how to add a JSON file.

In my case most of the dependencies were included with compile rather than implementation. So converting compile to implementation in my build.gradle(Module : app) worked perfectly

in case of flutter project after commenting this line worked for me

//apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 

To enable google firebase services in your app you need to add google services plugin to your gradle file(build.gradle). so in the gradle file under dependencies add :

classpath 'com.google.gms:google-services:4.3.0'  // Google Services plugin

under repositories check that you have Google's Maven repository as

google() //Google's Maven repository

For detailed breakdown on how to set up firebase check here for the official documentation.

After very long trying many things. this solved me : changing google services version to 4.2.0 in build gradle classpath 'com.google.gms:google-services:4.2.0'

now my build gradle looks like this:

buildscript {
repositories {
    google()
    jcenter()

    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.1'

    }
}
dependencies {
    classpath 'com.google.gms:google-services:4.2.0'
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

}

When I was facing this problem I have simply removed 20.0.1 from,

implementation 'com.google.firebase:firebase-auth:20.0.1'

(NOTE: I have implemented firebase-boM first so it has occurred in my case.)

Then synced and tried reconnecting then it was successful. I think it occurs for many reasons. If you are using firebase boM. then don't specify any other firebase dependencies versions. after successful sync, it should be solved. In your case, I can not declear why it is happening.

Basically, you need to remove all the gradle warning before doing this. In my case, I used buildFeatures { viewBinding true}

instead of buildFeatures { dataBinding true }

What solved my issue was: deleting

databinding{enabled = true}

and inserting

buildFeatures{dataBinding = true}

I also face this problem and I found the best way to solve this problem is: connect your Application manually to the firebase database.

Remove following from Gradle

testImplementation 'junit:junit:'

This worked for me and also connected to Firebase without any issue, you just need to rebuild project and then click on connect to firebase. It's done.

I just had a similar issue. I had to delete useProguard from the buildTypes in your app gradle.

After that I did not get the warning any more

In my case, I had to change minSdkVersion in build.gradle(Module: app) file to 25 and it worked.

in my case i update the minSdkVersion in build.gradle to the last one 28.0.3 and after i sync it work fine

This worked for me!

Go to Gradle.properties in your android

Disable android.enableR8=true by adding a # in front:

#android.enableR8=true

Alternatively, you can swap out the R8 for D8, The build system changed to using D8 instead of R8.

android.enableD8=true

Change the versions to below.

dependencies {
    classpath "com.android.tools.build:gradle:3.6.1"
    classpath 'com.google.gms:google-services:4.3.3'
}

Try changing the Android Gradle Plugin Version to 4.1.3 and the Gradle Version to 6.5 in Project Structure. It helped me and it might help you too. Android Firebase: Could not parse

Check if you have no same build tools version for your project level. If no download and restart IDE. again build both two gradles and after that run the project. Remember to run the project 1 time at least before using Firebase assist.

Mine solved with removing jcenter() in Project level gradle . It may be happens when some weird dependency or some other plugins are added in project . Here jcenter() is showing - jcenter will die soon . So after deleting it and resync project , Connect to firebase option worked fine.

I just replaced this in my app/build.gradle

dataBinding {
    enabled = true
}

to this:

buildFeatures {
    dataBinding true
}

and now I can connect my App to Firebase

With me!! Android Studio Arctic Fox (2020.3.1)

Im only changer this: In

build.gradle (:app)

To

android {
compileSdk 29 //29 -> 31(new version SDK)

defaultConfig {
...
}

and Sync done.

This helped me:-

  1. Changed Gradle version to 7.3.3
  2. Changed CompiledSdk and TargetSdk to 31

I just changed target sdk version 32 to 31. and it works successfully.

If you fixed everything in the gradle files, then check your Manifest file. Sometimes the manifest file will affect your application config file in terms of causing issues for Firebase integration.

Related