简体   繁体   中英

Android - Firebase analytics not showing on dashboard after enabling minifyEnabled & shrinkResources

I have enabled minifyEnabled & shrinkResources in my code. After enabling I am not getting any analytics of that app version on Analytics dashboard.

Do I need to make any proguard changes for firebase analytics?

build.gradle

buildTypes {
        debug {
            
        }
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            firebaseCrashlytics {
                mappingFileUploadEnabled true
            }
        }
    }

First of all, try to add this to your proguard

-keep class com.google.analytics.** { *; }

Did you use any custom class for the source of the value you send? If yes then you should be adding that class to proguard as well

When minifyEnabled is set to true and shrinkResources is set to true in your Android project, it enables code and resource optimization during the build process. However, this optimization can sometimes cause issues with certain libraries or frameworks, such as Firebase.

To resolve the issue with Firebase not working when minifyEnabled and shrinkResources are set to true, you can try adding the necessary rules to the ProGuard configuration file (proguard-rules.pro) to keep the required Firebase classes and resources.

Add the following rules to the proguard-rules.pro file:

      # Keep the Firebase classes
-keep class com.google.firebase.** { *; }

# Keep the Play Services classes
-keep class com.google.android.gms.** { *; }

# Keep the Firebase options
-keepattributes Signature
-keepattributes *Annotation*
-keepclassmembers public class com.google.firebase.options.FirebaseOptions {
    public <fields>;
    public <methods>;
}

# Keep the Firebase database data classes
-keepclassmembers class * extends com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper {
    <fields>;
}

# Keep the Firebase Firestore classes
-keepnames class com.google.firebase.firestore.** { *; }

# Keep the Firebase Auth classes
   -keepnames class com.google.firebase.auth.** { *; }

Make sure to include the proguard-rules.pro file in your build.gradle file:

android {
    // ...

    buildTypes {
        release {
            // ...
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

By adding these rules, you instruct ProGuard to keep the necessary Firebase classes and resources during the code and resource optimization process, ensuring that Firebase functions correctly even when minifyEnabled and shrinkResources are enabled.

Note: If you are using other Firebase products such as Firebase Crashlytics or Firebase Analytics, you may need to add additional ProGuard rules specific to those products as well. Refer to the Firebase documentation or the respective Firebase product documentation for the required ProGuard rules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM