You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio 3.1编译运行报错:无法获取FirebaseInitProvider类

Hey there, sorry to hear you're hitting this crash right after upgrading to Android Studio 3.1—let's work through this together. The ClassNotFoundException for FirebaseInitProvider usually ties to issues with how Firebase dependencies are handled or built post-upgrade, especially since everything ran smoothly before. Here are the most effective fixes to try:

1. Align all Firebase dependency versions

Android Studio 3.1 enforces stricter dependency version consistency than older versions. Make sure every Firebase-related dependency in your app/build.gradle uses the exact same version number—avoid using + to auto-pick the latest version, as this often causes mismatches.

Example of correct alignment:

// All Firebase dependencies share the same version
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-auth:16.0.8'
implementation 'com.google.firebase:firebase-database:16.0.8'
2. Enable Multidex if your app exceeds the 64k method limit

Upgrading might have added more methods to your app, pushing it over the 64k threshold. This can cause certain classes (like FirebaseInitProvider) to get excluded from the final APK.

  • First, enable Multidex in your app/build.gradle:
    android {
        defaultConfig {
            multiDexEnabled true
        }
    }
    dependencies {
        implementation 'com.android.support:multidex:1.0.3'
    }
    
  • Then, update your Application class:
    • If you use a custom Application class, make it extend MultiDexApplication:
      public class MyApp extends MultiDexApplication {
          // ... your existing code
      }
      
    • If you can't extend MultiDexApplication, add this to your custom Application's attachBaseContext method:
      @Override
      protected void attachBaseContext(Context base) {
          super.attachBaseContext(base);
          MultiDex.install(this);
      }
      
3. Clean and rebuild your project

Old build cache from the pre-upgrade version can cause weird inconsistencies. Do a full clean and rebuild:

  • Click Build > Clean Project in the Android Studio menu
  • Then click Build > Rebuild Project
  • For a deeper clean, manually delete the app/build and root project .gradle folders before rebuilding.
4. Update the Google Services plugin

Make sure the Google Services plugin in your root build.gradle is compatible with your Firebase dependency versions. Outdated plugins can fail to properly link Firebase libraries.

Example compatible setup:

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.2.0' // Works with Firebase 16.x versions
    }
}
5. Fix ProGuard/R8 configuration (if obfuscation is enabled)

If you're using obfuscation, R8 (the default minifier in Android Studio 3.1) might be stripping Firebase classes by accident. Add these rules to your proguard-rules.pro:

-keep class com.google.firebase.** { *; }
-keep class com.google.android.gms.** { *; }

If you want to test if R8 is the issue, temporarily disable it by adding this to your gradle.properties:

android.enableR8=false

Start with the clean/rebuild first—it's often the quick fix. If that doesn't work, move through the dependency checks and Multidex setup. These steps should resolve the FirebaseInitProvider class not found crash you're facing.

内容的提问来源于stack exchange,提问作者Murtaza

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:18:27