由于出于多种原因,有人可能想通过两个或多个 firebase 项目使用相同的应用程序,因此出现此错误,我在这里确实解决了这种特定情况。在两个或多个不同的 firebase 项目(比如说生产和登台)上运行同一个应用程序的最简单方法是向您的模块级别build.gradle
文件添加一个构建变体(比如说登台),如下所示:
apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-perf'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.mydomain.myapp"
minSdkVersion 19
targetSdkVersion 27
versionCode 18
versionName "2.8"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
staging {
initWith debug
applicationIdSuffix ".staging"
versionNameSuffix = "-staging"
}
}
}
dependencies {
[...]
}
// Firebase
apply plugin: 'com.google.gms.google-services'
在构建变体staging
中,最重要的是以下行:
applicationIdSuffix ".staging"
这将在构建时为您的应用程序 ID 注入“.staging”后缀,以便您自动拥有
applicationId "com.mydomain.myapp.staging"
您不需要将此应用程序 ( "com.mydomain.myapp.staging"
) 添加到您的 firebase 登台项目中,因此您将能够向此应用程序添加相同的"com.mydomain.myapp"
SHA1,因为它具有不同的应用程序 ID。