invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.71k stars 2.22k forks source link

🔥 Enabling firebase performance monitoring on Android removes certain classes from external library during build. #1681

Closed jjang16 closed 5 years ago

jjang16 commented 6 years ago

Issue

I'm trying to build an AR app with react native. I'm using "the 8th wall" https://8thwall.com/ as the AR solution. since it only supports Unity3d libary currently, I'm also exporting the Unity3d into React Native using this module https://github.com/f111fei/react-native-unity-view There is an obfuscated library XRPlugin.aar from the8thwall, which I include it via gradle dependencies in one of my modules. It contains classes such as com.the8thwall.reality.a.a.p, com.the8thwall.reality.a.a.q, etc. So here is the problem. When I enable firebase performance monitoring, some classes of the obfuscated library are removed. the removed classes are ones that are called by reflection inside the external library. I can see the classes missing inside the dex files, but present in the original library aar file. I'm using multidex, but no proguard. If I remove firebase performance monitoring, but with all other firebase modules included, the classes do get included normally in the final dex files. I think firebase performance monitoring plugin runs some kind of shrinking, or optimization during the build. Maybe, since the removed classes don't have direct reference, firebase performance monitoring thinks those classes are unused, removing them from the final dex file.


Project Files

iOS

ios/Podfile:

# N/A

AppDelegate.m:

// N/A

Android

android/build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 19
        compileSdkVersion = 27
        targetSdkVersion = 27
        supportLibVersion = "27.1.1"
    }
    repositories {
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.1.0'
        classpath 'io.fabric.tools:gradle:1.25.4'
        classpath 'com.google.firebase:firebase-plugins:1.1.5'
    }
}

allprojects {
    repositories {
        google()
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '4.6'
    distributionUrl = distributionUrl.replace("bin", "all")
}

android/app/build.gradle:

apply plugin: "com.android.application"

apply plugin: "io.fabric"
apply plugin: "com.google.firebase.firebase-perf"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = true

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = true

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.company.product"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        /*
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        */
        multiDexEnabled true
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            manifestPlaceholders = [excludeSystemAlertWindowPermission: "true"]
        }
        debug {
            manifestPlaceholders = [excludeSystemAlertWindowPermission: "false"]
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    implementation project(':react-native-unity-view')
    implementation project(':react-native-splash-screen')

    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:0.57.4"  // From node_modules
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'

    implementation project(':react-native-firebase')

    implementation "com.google.android.gms:play-services-base:16.0.1"
    implementation 'com.google.firebase:firebase-core:16.0.4'
    implementation "com.google.firebase:firebase-firestore:17.1.2"
    implementation "com.google.firebase:firebase-functions:16.1.2"
    implementation "com.google.firebase:firebase-messaging:17.3.4"
    implementation "com.google.firebase:firebase-storage:16.0.4"

    implementation "com.google.firebase:firebase-perf:16.2.0"
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') {
        transitive = true
    }

}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->

Environment


Think react-native-firebase is great? Please consider supporting the project with any of the below:

Salakar commented 5 years ago

Hey @jjang16 - apologies on the delay in responding to this issue.

This would be an issue to raise with firebase support, we're not adding any custom build compilation/minification steps, this is all coming from the Firebase Perf gradle tools.

Thanks