【问题标题】:React native app crashes on start when add " apply plugin: 'com.google.gms.google-services' " into " /android/app/build.gradle " file将 \" apply plugin: \'com.google.gms.google-services\' \" 添加到 \" /android/app/build.gradle \" 文件时反应原生应用程序在启动时崩溃
【发布时间】:2022-09-23 14:10:23
【问题描述】:

我正在将 firebase 集成到我的反应原生安卓应用.问题是当我添加这一行时:\"应用插件:\'com.google.gms.google-services\'\"在顶部或底部,在 gradle 文件中\"/android/app/build.gradle\",我的应用程序在启动时崩溃。

但是当我评论这一行时,我的应用程序正常启动。

严格地根据官方文档在我的应用程序中配置 firebase。 https://rnfirebase.io/#installation

我一直在互联网上寻找解决方案 2 周没有成功。

请帮助我。

--

包.json

\"dependencies\": {
    \"@gorhom/bottom-sheet\": \"^4\",
    \"@react-native-async-storage/async-storage\": \"^1.16.1\",
    \"@react-native-community/cameraroll\": \"^4.1.2\",
    \"@react-native-community/datetimepicker\": \"^5.1.0\",
    \"@react-native-community/masked-view\": \"^0.1.11\",
    \"@react-native-community/netinfo\": \"^8.0.0\",
    \"@react-native-community/slider\": \"^4.2.0\",
        \"@react-native-firebase/app\": \"^14.5.0\",
        \"@react-native-firebase/auth\": \"^14.5.0\",
        \"@react-native-firebase/crashlytics\": \"^14.5.0\",
        \"@react-native-firebase/database\": \"^14.5.0\",
        \"@react-native-firebase/firestore\": \"^14.5.0\",
        \"@react-native-firebase/functions\": \"^14.5.0\",
        \"@react-native-firebase/in-app-messaging\": \"^14.5.0\",
        \"@react-native-firebase/installations\": \"^14.5.0\",
        \"@react-native-firebase/messaging\": \"^14.5.0\",
        \"@react-native-firebase/remote-config\": \"^14.5.0\",
    \"@react-navigation/bottom-tabs\": \"^6.2.0\",
    \"@react-navigation/drawer\": \"^6.3.1\",
    \"@react-navigation/elements\": \"^1.3.1\",
    \"@react-navigation/material-top-tabs\": \"^6.1.1\",
    \"@react-navigation/native\": \"^6.0.8\",
    \"@react-navigation/native-stack\": \"^6.5.0\",
    \"@react-navigation/stack\": \"^6.1.1\",
    \"@sindresorhus/to-milliseconds\": \"^2.0.0\",
    \"axios\": \"^0.26.0\",
    \"expo\": \"~44.0.2\",
    \"expo-splash-screen\": \"~0.14.1\",
    \"expo-status-bar\": \"~1.2.0\",
    \"i18n\": \"^0.14.1\",
    \"libphonenumber-js\": \"^1.9.49\",
    \"pretty-bytes\": \"^6.0.0\",
    \"pretty-ms\": \"^7.0.1\",
    \"react\": \"17.0.2\",
    \"react-dom\": \"17.0.1\",
    \"react-native\": \"0.67.2\",
    \"react-native-create-thumbnail\": \"^1.5.1\",
    \"react-native-date-time-scroll-picker\": \"^0.0.8\",
    \"react-native-device-info\": \"^8.5.0\",
    \"react-native-fast-image\": \"^8.5.11\",
    \"react-native-ffmpeg\": \"^0.5.2\",
    \"react-native-file-access\": \"^2.2.2\",
    \"react-native-fs\": \"^2.18.0\",
    \"react-native-gesture-handler\": \"^2.2.0\",
    \"react-native-pager-view\": \"^5.4.11\",
    \"react-native-progress\": \"^5.0.0\",
    \"react-native-reanimated\": \"^2.5.0\",
    \"react-native-safe-area-context\": \"^3.4.0\",
    \"react-native-screens\": \"^3.12.0\",
    \"react-native-snackbar\": \"^2.4.0\",
    \"react-native-svg\": \"^12.1.1\",
    \"react-native-tab-view\": \"^3.1.1\",
    \"react-native-video\": \"^5.2.0\",
    \"react-native-view-shot\": \"^3.1.2\",
    \"react-native-web\": \"0.17.1\",
    \"react-native-webview\": \"^11.17.2\",
    \"react-redux\": \"^7.2.6\",
    \"redux\": \"^4.1.2\"
  },

--

安卓/build.gradle

buildscript {
    ext {
        buildToolsVersion = \'30.0.3\'
        minSdkVersion = 24
        compileSdkVersion = 31
        targetSdkVersion = 31

        ndkVersion = \"21.4.7075529\"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath \'com.android.tools.build:gradle:4.2.2\'

        // Google Firebase
        classpath \'com.google.gms:google-services:4.3.10\'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url(new File([\'node\', \'--print\', \"require.resolve(\'react-native/package.json\')\"].execute(null, rootDir).text.trim(), \'../android\'))
        }
        maven {
            // Android JSC is installed from npm
            url(new File([\'node\', \'--print\', \"require.resolve(\'jsc-android/package.json\')\"].execute(null, rootDir).text.trim(), \'../dist\'))
        }

        mavenCentral {
            // We don\'t want to fetch react-native from Maven Central as there are
            // older versions over there.
            content {
                excludeGroup \"com.facebook.react\"
            }
        }

        jcenter() {
            content {
                includeModule(\"com.yqritc\", \"android-scalablevideoview\")
            }
        }

        google()
        maven { url \'https://www.jitpack.io\' }
    }
}

--

android/app/build.gradle

    apply plugin: \"com.android.application\"
    apply plugin: \"com.google.gms.google-services\"
    
    // codes
    
    dependencies {
        // codes
    
        // Firebase
        // Import the Firebase BoM
        implementation platform(\'com.google.firebase:firebase-bom:29.2.1\')
    
        // Add the dependency for the Firebase SDK for Google Analytics
        // When using the BoM, don\'t specify versions in Firebase dependencies
        implementation \'com.google.firebase:firebase-analytics\'
        implementation \'com.google.firebase:firebase-auth\' 
        implementation \'com.google.firebase:firebase-firestore\'
        implementation \'com.google.firebase:firebase-database\'
        implementation \'com.google.firebase:firebase-functions\'
        implementation \'com.google.firebase:firebase-installations\'
        implementation \'com.google.firebase:firebase-messaging\'
        implementation \'com.google.firebase:firebase-crashlytics\'
    }

    // codes

    标签: android firebase react-native gradle


    【解决方案1】:

    我也遇到了同样的问题,请问你解决了吗?如果是这样,你能解释一下解决方法吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-01
      相关资源
      最近更新 更多