android - 如果我设置了 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 设置流程:
我更改了文件“App_Resources/Android/src/main/AndroidManifest.xml”中的包值。
firebase :AndroidManifest.xml
之前的“com.xx.xx”:AndroidManifest.xml"\\PACKAGE\\"
之后:“com.xx.xx”我下载了“Google-services.json”并将其复制到“platforms/android/app”文件夹中。
我在“App_Resources/Android/app.gradle”的第一行添加了应用插件:'com.Google.gms.Google-services',并注入了两个依赖项。
实施平台('com.google.firebase:firebase-bom:28.2.0')
实施'com.google.firebase:firebase-analytics'我从“platforms/android/build.gradle”添加了类路径 'com.Google.gms:Google-services:4.3.8'。
当我运行“ns run android”或“ns run debug”命令时,没有出现错误,并且显示“Successfully installed on device”日志,但应用程序没有运行。
即使我启动应用程序也不会发生任何事件。
我创建了@loaded 事件调用警报函数并用try-catch 短语包装了它,但我看不到任何错误日志或警报。
我试过的:
- ns 运行 android --clean
- ns 运行调试 --debug-brk
- ns build --release --aab --copy-to=[path] → aab to apks → install pak → no alert
- ns 清洁
- 尝试连接到实际设备,关闭 wifi。
- 把它转到模拟器上。(API 30)
- 我创建了一个新项目并尝试了同样的事情,但结果并没有改变。
- 之后,我将 app.gradle、build.gradle 恢复到原来的状态并删除了 Google-services.json 文件,但应用程序并没有自动运行。
我错过了什么?
附言。我知道有一个 nativescript-firebase 插件。+我用 ns create my-blank-vue --template @nativescript/template-blank-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__"
。不要在那里修改包属性。
解决了:
我恢复了
App_Resources/Android/src/main/AndroidManifest.xml
这样的文件:package="__PACKAGE__"
从以下位置更新包值
platforms/android/src/main/AndroidManifest.xml
:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.company.app" ...>
将
applicationId
与包名称相同的属性添加到App_Resources/Android/src/main/app.gradle
:android { defaultConfig { applicationId "com.company.app" minSdkVersion 17 generatedDensities = [] }
nativescript.config.ts
从文件更新 id :
id: 'com.company.app' // match application id
命令:
ns platform remove android; ns prepare android
参考: https : //docs.nativescript.org/releasing#overview
https://developer.android.com/studio/build/application-id?hl=ko
推荐阅读
- graphql - Amplify + AppSync 不改变对象
- javascript - 将参数从 HOC 功能组件传递到组件不起作用
- git - git-review 补丁集在推送之前拉取/重新定位最新版本
- c++11 - 通过 switch-case 梯形图调用 write 时无法以二进制模式写入文件
- javascript - 用静态和动态值创建数组组合的最佳方法是什么
- pyspark - pyspark 2.0中按箭头键时的字符“^[[A”“^[[B”“^[[C”“^[[D”
- flutter - 颤振选项卡没有正确下划线
- c# - VB.NET Azure Functions — Microsoft.CSharp 程序集有什么作用?
- ios - 如何使用 if 逻辑或三元运算符在 Swift 中设置枚举案例的 rawValue?
- java - 如何在java中自动填充对象?