运行发行版时React-native + Firebase崩溃

时间:2019-02-11 11:51:58

标签: javascript firebase react-native react-native-android

我为我的应用程序使用react-native和firebase / firestore。当开发一切正常时,但是当我收集android的发行版时,在应用程序启动时崩溃。出现错误。该应用程序在启动后立即关闭...

当我添加以下行时会发生这种情况:

import * as Firebase from 'firebase';

我没有为Android开发应用程序的经验,我很难理解自己错过或做错了什么。

我的build.gradle:

buildscript {
ext {
    buildToolsVersion = "28.0.3"
    minSdkVersion = 16
    compileSdkVersion = 28
    targetSdkVersion = 27
    supportLibVersion = "28.0.0"
}
repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'

    classpath 'com.google.gms:google-services:4.2.0' 
}
}

allprojects {
repositories {
    mavenLocal()
    google()
    jcenter()
    maven {
        url "$rootDir/../node_modules/react-native/android"
    }
}
}

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

我的app / build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile

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

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

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

apply plugin: 'com.android.application'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
    applicationId "com.alcoexpert"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
signingConfigs {
    release {
        if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
            storeFile file(MYAPP_RELEASE_STORE_FILE)
            storePassword MYAPP_RELEASE_STORE_PASSWORD
            keyAlias MYAPP_RELEASE_KEY_ALIAS
            keyPassword MYAPP_RELEASE_KEY_PASSWORD
        }
    }
}
splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  // If true, also generate a universal APK
        include "armeabi-v7a", "x86", "arm64-v8a"
    }
}
buildTypes {
    release {
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), 
"proguard-rules.pro"
        signingConfig signingConfigs.release
    }
}
// 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, "arm64-v8a": 3]
        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-gesture-handler')
implementation project(':react-native-i18n')
implementation project(':react-native-vector-icons')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat- 
v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+"  // From 
node_modules

implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-firestore:17.1.5'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.firebaseui:firebase-ui-auth:4.3.1'

}

task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}

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

1 个答案:

答案 0 :(得分:0)

我一直为此苦苦挣扎。 让我省钱的是添加了import '@firebase/database'名称空间。您将必须npm install才能保持联系。这是我的完整代码段:

import firebase from '@firebase/app'
import '@firebase/database'
import '@firebase/auth'