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:
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'
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'sattachBaseContextmethod:@Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); }
- If you use a custom Application class, make it extend
Old build cache from the pre-upgrade version can cause weird inconsistencies. Do a full clean and rebuild:
- Click
Build > Clean Projectin the Android Studio menu - Then click
Build > Rebuild Project - For a deeper clean, manually delete the
app/buildand root project.gradlefolders before rebuilding.
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 } }
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

