Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to sync Gradle with Firebase Crashlytic 2.6.0 using Android Studio 4.2

Project-level build.gradle

buildscript {
    addRepos(repositories)
    dependencies {

        classpath 'com.google.gms:google-services:4.3.5'

        // Crashlytic
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.6.0'

    }
}

App-level build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

dependencies {

    // Crashlytic
    implementation 'com.google.firebase:firebase-crashlytics:18.0.0'

}

With gradle 4.3.5 and Firebase crashlytic 2.6.0 My app stop compiling with the error below

class org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar$2 cannot be cast to class org.gradle.api.file.Directory (org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar$2 and org.gradle.api.file.Directory are in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @68be2bc2)
class org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar$2 cannot be cast to class org.gradle.api.file.Directory (org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar$2 and org.gradle.api.file.Directory are in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @68be2bc2)

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.

Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

But everything works if I change Firebase crashlytic version to 2.3.0

Do you guys have any idea why is this happen?

like image 506
Harvey Avatar asked May 12 '21 07:05

Harvey


People also ask

Why is gradle not syncing?

It could be that you are using gradle in offline mode. To uncheck it go to File > Settings > Gradle , uncheck the Offline Work checkbox, and click Apply Make sure you have internet connection and sync the project again.

How do I resolve gradle sync issues?

For this, you have to connect your PC to the internet and you have to open your Android studio. After opening your project click on the Sync Project with Gradle files option. This will automatically download the new Gradle files and will fix the issue which is caused by the Gradle files.

How do I sync gradle with Android studio?

Open your gradle. properties file in Android Studio. Restart Android Studio for your changes to take effect. Click Sync Project with Gradle Files to sync your project.


2 Answers

UPDATED ANSWER:

The reason for the compiling issue is that version of Gradle and Crashlytics Gradle plug-in is incompatible.

As described here, starting from Crashlytics Gradle plugin version 2.5.0:

The Crashlytics Gradle plugin is compatible with Gradle v5.6.4+ and the Android Gradle plugin v3.4.2+. Support for previous Gradle and Android Gradle plugin versions have been removed.

So, the Solution is to use the latest Gradle and firebase-crashlytics-gradle versions. Thanks to @Mher for describing the compatible up-to-date versions here. Follow his answer for updating versions. Don't forget to change compileOptions in app level build.gradle as:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

Warning: My old answer below is a workaround to fix the Gradle and Crashlytics compatibility for those who are not ready to update the Gradle version. The proper solution is to update the Gradle version. In the old answer below, the mentioned firebase-crashlytics-gradle:2.4.1 was buggy for me and it was not able to upload mapping files to the Firebase console which deobfuscates the crash reports. So, try to follow the above-updated answer instead of downgrading the Crashlytics Gradle version.

OLD ANSER FOR WHO CANNOT UPDATE THE GRADLE VERSION:

I hit the exact same issue. Seems the latest crashlytics-gradle plugin is incompatible with something. Using the lower version of crashlytics-gradle plugin helped. Instead of firebase-crashlytics-gradle:2.6.0 Try to use this version:

classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'

That worked for me... If that doesn't work for you, you can maybe try even lower versions. A list of versions can be found here:

https://firebase.google.com/support/release-notes/android#crashlytics_gradle_plugin_v2-0-0

When you search for "Crashlytics Gradle plugin version", you can see all released versions for Crashlytics Gradle plugin.

I also had to change compileOptions in app level build.gradle as:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

When target and source compatibility was not set to 1_8, project compiled but was crashing when trying to run the app:

    --------- beginning of crash
2021-06-09 17:22:28.765 29519-29519/com.resmed.myair.cpl E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.resmed.myair.cpl, PID: 29519
    java.lang.BootstrapMethodError: Exception from call site #45 bootstrap method
        at com.google.firebase.components.ComponentDiscovery.discoverLazy(ComponentDiscovery.java:112)
        at com.google.firebase.FirebaseApp.<init>(FirebaseApp.java:418)
        at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:299)
        at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:267)
        at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:252)
        at com.google.firebase.provider.FirebaseInitProvider.onCreate(FirebaseInitProvider.java:51)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1917)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1892)
        at com.google.firebase.provider.FirebaseInitProvider.attachInfo(FirebaseInitProvider.java:45)
        at android.app.ActivityThread.installProvider(ActivityThread.java:6239)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:5805)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5722)
        at android.app.ActivityThread.-wrap1(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.NoClassDefFoundError: Invalid descriptor: minimize.
        at com.google.firebase.components.ComponentDiscovery.discoverLazy(ComponentDiscovery.java:112) 
        at com.google.firebase.FirebaseApp.<init>(FirebaseApp.java:418) 
        at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:299) 
        at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:267) 
        at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:252) 
        at com.google.firebase.provider.FirebaseInitProvider.onCreate(FirebaseInitProvider.java:51) 
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1917) 
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1892) 
        at com.google.firebase.provider.FirebaseInitProvider.attachInfo(FirebaseInitProvider.java:45) 
        at android.app.ActivityThread.installProvider(ActivityThread.java:6239) 
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:5805) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5722) 
        at android.app.ActivityThread.-wrap1(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494)
like image 108
Eren Avatar answered Sep 18 '22 07:09

Eren


In my case

classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'

solved the error but crashlytics didn't send errors to server.

I changed versions in \android\build.gradle to

classpath 'com.android.tools.build:gradle:4.2.0'
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'

and in \android\gradle\wrapper\gradle-wrapper.properties to

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip

and now everything works just fine.

like image 37
Mher Aghabalyan Avatar answered Sep 19 '22 07:09

Mher Aghabalyan