When I add Firebase Auth and Database to my project, the following problem arises:
FATAL EXCEPTION: main Process: com.myapp, PID: 4024 java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.myapp-NTr4rdWkzRUXkEy5dItLzQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp-NTr4rdWkzRUXkEy5dItLzQ==/lib/arm64, /system/lib64, /system/vendor/lib64]]
And so the app closes, I searched the internet and saw that it might be Multidex, but I tried to add Multidex and the following error occurred:
FATAL EXCEPTION: main Process: com.myapp, PID: java.lang.ClassNotFoundException: Didn't find class ".MyApplication" on path: DexPathList[[zip file "/data/app/com.myapp-NTr4rdWkzRUXkEy5dItLzQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp-NTr4rdWkzRUXkEy5dItLzQ==/lib/arm64, /system/lib64, /system/vendor/lib64]]
This is my gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.company.myapp"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.google.firebase:firebase-auth:+'
compile 'com.google.firebase:firebase-database:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'androidx.multidex:multidex:2.0.0+'
compile 'androidx.appcompat:appcompat:1.0.0'
compile 'androidx.legacy:legacy-support-v4:1.0.0'
compile 'com.google.android.material:material:1.0.0-rc01'
compile 'androidx.cardview:cardview:1.0.0'
}
As stated in some forums, it is necessary for the app to contain the MyApplication class
public class MyApplication extends Application {
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this); } }
And in the Application tag
android:name="MyApplication"
I tried to maintain the FirebaseInitProvider class with proguard and it didn’t work. The app stops working too!
I also checked the dex files and FirebaseInitProvider is inside the APK.
Any solution?
Add this to your proguard file
-keep class com.google.firebase.** { *; }
1