gpt4 book ai didi

android - 无法将 firebase 与具有 flavor 和尺寸的即时应用程序连接

转载 作者:行者123 更新时间:2023-11-29 00:57:40 26 4
gpt4 key购买 nike

<分区>

我刚刚将我的应用程序转换为即时应用程序,问题是它的设置有点复杂,因为我有 3 个维度:

  1. 经验

      - instant
    - installed
  2. 类型

      - demo
    - controlled
    - user
  3. 调整

      - normal
    - perf

所以到即时应用程序的转换过程不是直截了当的,必须添加一些 gradle 代码来忽略一些风格的排列,为构建变体设置源和 list 位置,处理不同 list 中 Activity 的深层链接等等我设法解决的问题。似乎一切正常,除了 firebase。

我正在尝试了解 firebase 如何路由 google-services.json 文件、如何设置不同的位置或如何使其重复文件或其他内容。

当我添加 firebase 并将 google-services.json 文件添加到安装目录时,出现以下错误:

文件 google-services.json 丢失。 Google 服务插件不能

function without it. 
Searched Location:
myapp_project/base/src/feature/instant/user/normal/release/google-services.json
... and so on with other flavors and combinations

这对我来说意义不大,因为目录树结构的格式不正确。我的目录树如下:

- myapp_project
- base
- src
- controlled
- demo
- main
- user
- userNormal
- userPerf
- installed
- instant

我已尝试创建要求的目录,并在所有目录中添加文件。然后它可以完美编译,但不会连接到 firebase。 更新 在这件事上,我意识到 gradle 在许多目录中搜索文件,但其中有我的“基本”目录,所以只需在那里添加 google-services.json 文件,现在无需编译每个目录创建一个文件。我还将文件中的包字符串更改为 .base,这样它就不会抛出找不到包的错误。但是,它仍然可以很好地编译但无法连接到 firebase 服务器。

基础gradle文件

apply plugin: 'com.android.feature'
apply plugin: 'kotlin-android'

import org.apache.tools.ant.taskdefs.condition.Os

android {

baseFeature true

compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}

def keystoreProperties = Os.isFamily(Os.FAMILY_WINDOWS) ?
"KeyStoreWin.properties" : "KeyStore.properties"
Properties props = new Properties()
props.load(new FileInputStream(file(project.property(keystoreProperties))))

signingConfigs {
storeSignature {
storeFile file(props['KEYSTORE'])
storePassword props['KEYSTORE_PASSWD']
keyAlias props['KEYSTORE1']
keyPassword props['KEYSTORE_PASSWD1']
}
}

buildTypes {
debug {
debuggable true
}
release {
signingConfig signingConfigs.storeSignature
debuggable false
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
renderscriptDebuggable false
}
}

flavorDimensions "experience", "type", "adjustment"
productFlavors {
instant {
dimension "experience"
versionCode 1
}
installed {
dimension "experience"
versionCode 2
}
user {
dimension "type"
}
demo {
dimension "type"
}
controlled {
dimension "type"
}
normal {
dimension "adjustment"
}
perf {
dimension "adjustment"
}
}

variantFilter { variant -> def names = variant.flavors*.name
if (names.contains("controlled") && names.contains("perf")) {
setIgnore(true)
}
if (names.contains("demo") && names.contains("perf")) {
setIgnore(true)
}
if (names.contains("user") && names.contains("perf") &&
variant.buildType.name == 'debug') {
setIgnore(true)
}
if (names.contains("instant") && names.contains("perf")) {
setIgnore(true)
}
if (names.contains("instant") && names.contains("demo")) {
setIgnore(true)
}
if (names.contains("instant") && names.contains("controlled")) {
setIgnore(true)
}
}

sourceSets {
instantUserNormal {
java.srcDirs = ['src/userNormal/java', 'src/userNormal/java/']
res.srcDirs = ['src/userNormal/res', 'src/userNormal/res/']
manifest.srcFile 'src/userNormal/AndroidManifest.xml'
}
installedUserNormal {
java.srcDirs = ['src/userNormal/java', 'src/userNormal/java/']
res.srcDirs = ['src/userNormal/res', 'src/userNormal/res/']
manifest.srcFile 'src/userNormal/AndroidManifest.xml'
}
installedUserPerf {
java.srcDirs = ['src/userPerf/java', 'src/userPerf/java/']
res.srcDirs = ['src/userPerf/res', 'src/userPerf/res/']
manifest.srcFile 'src/userPerf/AndroidManifest.xml'
}
}
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

packagingOptions {
exclude 'META-INF/proguard/androidx-annotations.pro'
}
}

repositories {
google()
maven { url "https://jitpack.io" }
mavenCentral()
}


dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
... all dependencies here
}

apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'

已安装的 gradle:

import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
applicationId "com.domain.myapp"
minSdkVersion 21
targetSdkVersion 28
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

def keystoreProperties = Os.isFamily(Os.FAMILY_WINDOWS) ?
"KeyStoreWin.properties" : "KeyStore.properties"
Properties props = new Properties()
props.load(new
FileInputStream(file(project.property(keystoreProperties))))

signingConfigs {
storeSignature {
storeFile file(props['KEYSTORE'])
storePassword props['KEYSTORE_PASSWD']
keyAlias props['KEYSTORE_UPS']
keyPassword props['KEYSTORE_UPS_PASSWD']
}
}

buildTypes {
debug {
debuggable true
versionNameSuffix "v1d"
}
release {
signingConfig signingConfigs.storeSignature
debuggable false
versionNameSuffix "v1r"
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
renderscriptDebuggable false
}
}

flavorDimensions "experience", "type", "adjustment"
productFlavors {
instant {
dimension "experience"
}
installed {
dimension "experience"
}
user {
dimension "type"
}
demo {
dimension "type"
applicationIdSuffix ".demo"
}
controlled {
dimension "type"
applicationIdSuffix ".controlled"
}
normal {
dimension "adjustment"
}
perf {
dimension "adjustment"
}
}

variantFilter { variant -> def names = variant.flavors*.name
if (names.contains("controlled") && names.contains("perf") {
setIgnore(true)
}
if (names.contains("demo") && names.contains("perf")) {
setIgnore(true)
}
if (names.contains("user") && names.contains("perf") && variant.buildType.name == 'debug') {
setIgnore(true)
}
if (names.contains("instant") && names.contains("perf")) {
setIgnore(true)
}
if (names.contains("instant") && names.contains("demo")) {
setIgnore(true)
}
if (names.contains("instant") && names.contains("controlled")) {
setIgnore(true)
}
}

packagingOptions {
exclude 'META-INF/proguard/androidx-annotations.pro'
}
}

repositories {
google()
maven { url "https://jitpack.io" }
mavenCentral()
}

dependencies {
implementation project(':base')
}

Update2 我的日志显示以下错误:

E/FA: GoogleService failed to initialize, status: 10, Missing google app id value from from string resources with name google_app_id.
E/FA: Missing google_app_id. Firebase Analytics disabled. See https....

然而,google_app_id 存在于构建目录中,为每个构建变体自动生成 values.xml 文件

我该如何解决这个问题?

UPDATE3 已解决 我不得不在基础文件和已安装的 gradle 文件中应用 firebase 插件两次。如其中一条评论中分享的帖子所示。

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com