APP出海--Android 接入Firebase笔记

Publish: April 15, 2021 Category: 编程 No Comments

0x00 创建Firebase应用

进入Firebase控制台(https://console.firebase.google.com/) 创建应用,这里选择创建一个Android应用,注意自己的包名是否匹配。创建成功之后会给一个google-service.json的配置文件,将文件复制到app项目目录下。

0x01 添加Firebase配置文件

项目级的build.gradle中添加

buildscript {

  repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
  }

  dependencies {
    // ...

    // Add the following line:
    classpath 'com.google.gms:google-services:4.3.5'  // Google Services plugin
  }
}

allprojects {
  // ...

  repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
    // ...
  }
}

在应用build.gradle中添加

apply plugin: 'com.android.application'
// Add the following line:
apply plugin: 'com.google.gms.google-services'  // Google Services plugin

android {
  // ...
}

添加依赖
dependencies {
  // ...

  // Import the Firebase BoM
  implementation platform('com.google.firebase:firebase-bom:26.7.0')

  // When using the BoM, you don't specify versions in Firebase library dependencies

  // Declare the dependency for the Firebase SDK for Google Analytics
  implementation 'com.google.firebase:firebase-analytics'

  // Declare the dependencies for any other desired Firebase products
  // For example, declare the dependencies for Firebase Authentication and Cloud Firestore
  implementation 'com.google.firebase:firebase-auth'
  implementation 'com.google.firebase:firebase-firestore'
}

0x02 同步Gradle

同步之后提示构建成功

Tags: android, firebase

Related Posts:

Leave a Comment