【问题标题】:Deploying backend server for android in-app purchases for classytaxi?为classytaxi 的android 应用内购买部署后端服务器?
【发布时间】:2020-04-18 04:31:30
【问题描述】:

我几天来一直在努力将 android 用户订阅实现到 android 中。我正在使用 google dev 教程进行 Java 应用内购买:

https://github.com/android/play-billing-samples/tree/master/ClassyTaxiJava

在最后一部分,我需要部署后端服务器,如下所述:

https://github.com/android/play-billing-samples/tree/master/ClassyTaxiServer

我做了什么:

  1. 将服务器文件和文件夹in the tutorial 克隆到我的电脑中
  2. 打开 CMD 并定向到文件夹
  3. 通过firebase login登录firebase --> OK
  4. 通过firebase use -add添加了firebase项目-->好的
  5. 发起了一个函数命令firebase functions:config:set app.package_name="com.mypackage.app" --> OK
  6. deploy firebase --> 错误

错误如下:

=== Deploying to 'api-2341234***'...

i  deploying functions, hosting
Running command: npm --prefix "$RESOURCE_DIR" run lint
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Users\vafa\Firebase\server\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\vafa\Firebase\server\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\vafa\AppData\Roaming\npm-cache\_logs\2020-04-18T22_21_16_430Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code4294963238

我注意到部署后,在项目文件夹中创建了一个“服务器”文件夹,服务器文件夹中没有任何内容。我尝试将 package.json 文件放入其中并再次部署,但它不起作用。

*** 它在 git 中也被提及为 issue here 并且有人回复:

注意事项:在 firebase.json 中, https://github.com/android/play-billing-samples/blob/master/ClassyTaxiServer/firebase.json 没有“服务器”或“网络”目录,firebase 无法部署 这些文件夹的功能和托管。

我的 firebase 项目文件夹:

我的服务器文件夹:

我的 src 文件夹:

更改文件夹结构后出错:

Error: spawn npm --prefix "%RESOURCE_DIR%" run lint ENOENT
    at notFoundError (C:\Users\vafaeene\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (C:\Users\vafaeene\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:40:16)
    at ChildProcess.cp.emit (C:\Users\vafaeene\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:27:25)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess.cp.emit (C:\Users\vafaeene\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:30:37)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12) {
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn npm --prefix "%RESOURCE_DIR%" run lint',
  path: 'npm --prefix "%RESOURCE_DIR%" run lint',
  spawnargs: []
}

错误:函数预部署错误:命令以非零退出代码终止

【问题讨论】:

  • 通读文档。不要打和审判。它会为你节省很多时间。我很欣赏你想要做的事情,但首先要获得知识。 => firebase.google.com/docs/admin/setup
  • 我无意冒犯你兄弟,但你应该学会初始化 Firebase Admin SDK。这就是该链接所包含的内容。
  • @example 这里没有尝试和错误。你甚至读过你的建议吗?是的,我读过它。感谢您的建议。
  • 让我向您展示一些我目前已部署到 firebase 函数的 firebase admin sdk 代码
  • @example 它没有被视为冒犯。这是对我的建议,我很感激。您发送的链接没有提示我应该如何处理这些文件或如何将这些文件连接到我的 Firebase。我尝试了firebase init 并添加了功能,但我想不通。这些是我电脑文件夹中已经存在的服务器文件。我必须将它们链接到火力基地。

标签: android node.js firebase npm in-app-subscription


【解决方案1】:

看看这个代码兄弟 我在我的 firebase 函数中使用它 代码位于 index.ts

import * as admin from 'firebase-admin';

const serviceAccount = require('../common/serviceAccountKey.json');

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://<project-id>.firebaseio.com",
    storageBucket: "<project-id>.appspot.com"
});

以下是我的目录结构

functions
      ├── common
      |     └── serviceAccountKey.json
      └── src
           └── index.ts

希望对您有所帮助。询问您是否遇到问题;)

[更新]

您的firebase.json 没有问题。实际上它正在寻找正确的文件夹。将 package.json 放在正确的位置,保存位置是错误的。它应该保存在服务器文件夹之外。 src 文件夹所在的位置,所以这应该是更新后的目录结构:

   myProjectFolder
      ├──server
      |    ├── common
      |    |     └── serviceAccountKey.json
      |    ├── src
      |    |    └── index.ts
      |    └──package.json, tsconfig.json and other files
      └── firebase.json

将您的文件夹结构更新为此并从myProjectFolder git 命令firebase deploy --only functions

windows 的 package.json [编辑]

{
  "functions": {
    "predeploy": [
      "npm --prefix \"%RESOURCE_DIR%\" run lint", // observe here $RESOURCE_DIR has been replaced with %RESOURCE_DIR%
      "npm --prefix \"%RESOURCE_DIR%\" run build" // same change as above
    ],
    "source": "server"
  },
  "hosting": {
    "public": "web",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [ ]
  }
}

试试这个并回复评论

【讨论】:

  • 我用我得到的错误更新了答案。服务器似乎存在问题(未定义服务器......)。我不懂这种语言,因为我是 npm 的新手。有趣的是,这是 google 的官方教程,似乎没有人关心在 git 中更正它。
  • 我没有特权,但我会帮你别担心。这不是一个大问题。查看更新的答案
  • 谢谢。但我也没有“lib”文件夹。有两个文件夹:src 和 test。我现在就试试。
  • 我确实测试过。同样的问题。这次它创建了另一个名为“lib”的文件夹,它是空的。它正在源文件夹中寻找 package.json 文件。天哪,我是多么愚蠢。我必须将其更改为“src”。我已经在项目中有这个文件夹了。
  • 发出命令 => firebase logout &amp;&amp; firebase login &amp;&amp; firebase deploy。这可能是一些缓存问题。一旦你注销并登录,firebase cli 就会清理缓存
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-16
  • 2019-03-21
  • 2019-09-23
  • 1970-01-01
  • 1970-01-01
  • 2011-11-27
  • 1970-01-01
相关资源
最近更新 更多