首页 > 解决方案 > 如果我设置了 Firebase,nativescript 应用程序的安装将成功,但不会运行

问题描述

我对安卓了解不多。我使用的是 nativescript-vue,nativescript 是 8.x 版本。当我第一次创建 ns-vue 模板并运行“ns run android”或“ns debug android”命令时,应用程序安装在连接的设备上并自动运行。但是,如果我在设置 Firebase 后输入“ns run android”,安装会成功,但应用程序不会运行。运行“ns debug android --debug-brk”结果是一样的,控制台上也没有出现错误。我刚刚创建了 Firebase 项目并遵循了规定的流程。

我所做的 Firebase 设置流程:

  1. 我更改了文件“App_Resources/Android/src/main/AndroidManifest.xml”中的包值。
    firebase :AndroidManifest.xml
    之前的“com.xx.xx”:AndroidManifest.xml"\\PACKAGE\\"
    之后:“com.xx.xx”

  2. 我下载了“Google-services.json”并将其复制到“platforms/android/app”文件夹中。

  3. 我在“App_Resources/Android/app.gradle”的第一行添加了应用插件:'com.Google.gms.Google-services',并注入了两个依赖项。
    实施平台('com.google.firebase:firebase-bom:28.2.0')
    实施'com.google.firebase:firebase-analytics'

  4. 我从“platforms/android/build.gradle”添加了类路径 'com.Google.gms:Google-services:4.3.8'。

  5. 当我运行“ns run android”或“ns run debug”命令时,没有出现错误,并且显示“Successfully installed on device”日志,但应用程序没有运行。

即使我启动应用程序也不会发生任何事件。
我创建了@loaded 事件调用警报函数并用try-catch 短语包装了它,但我看不到任何错误日志或警报。

我试过的:

  1. ns 运行 android --clean
  2. ns 运行调试 --debug-brk
  3. ns build --release --aab --copy-to=[path] → aab to apks → install pak → no alert
  4. ns 清洁
  5. 尝试连接到实际设备,关闭 wifi。
  6. 把它转到模拟器上。(API 30)
  7. 我创建了一个新项目并尝试了同样的事情,但结果并没有改变。
  8. 之后,我将 app.gradle、build.gradle 恢复到原来的状态并删除了 Google-services.json 文件,但应用程序并没有自动运行。

我错过了什么?

附言。我知道有一个 nativescript-firebase 插件。+我用 ns create my-blank-vue --template @nativescript/template-blank-vue 创建了一个模板。

标签: androidfirebasenativescriptnativescript-vue

解决方案


最后我发现了问题。

问题:
我更改了文件“App_Resources/Android/src/main/AndroidManifest.xml”中的包值。
firebase :AndroidManifest.xml
之前的“com.xx.xx”:AndroidManifest.xml"__PACKAGE__"
之后:“com.xx.xx”

但是 Nativescript doc:
NativeScript CLI 构建系统会将它们设置为platforms/android/src/main/AndroidManifest.xml. 在 app/App_Resources/Android/AndroidManifest.xml 中,它将使用占位符:package="__PACKAGE__"不要在那里修改包属性。

解决了:

  1. 我恢复了App_Resources/Android/src/main/AndroidManifest.xml这样的文件: package="__PACKAGE__"

  2. 从以下位置更新包值platforms/android/src/main/AndroidManifest.xml
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.company.app" ...>

  3. applicationId与包名称相同的属性添加到App_Resources/Android/src/main/app.gradle

    android { defaultConfig { applicationId "com.company.app" minSdkVersion 17 generatedDensities = [] }

  4. nativescript.config.ts从文件更新 id :
    id: 'com.company.app' // match application id

  5. 命令:ns platform remove android; ns prepare android


参考: https : //docs.nativescript.org/releasing#overview
https://developer.android.com/studio/build/application-id?hl=ko


推荐阅读