部署用于classytaxi的Android应用内购买的后端服务器?

时间:2020-04-18 04:31:30

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

我为将android用户订阅实现为android奋斗了几天。我正在使用Google开发人员教程进行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克隆到我的PC中
  2. 打开CMD并定向到文件夹
  3. 通过firebase login登录到Firebase->确定
  4. 通过firebase use -add添加了Firebase项目->确定
  5. 启动功能命令firebase functions:config:set app.package_name="com.mypackage.app"->确定
  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中也被称为问题here,有人回答:

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

我的firebase项目文件夹: enter image description here

我的服务器文件夹: enter image description here

我的src文件夹: enter image description here

更改文件夹结构后出现错误:

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: []
}

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

1 个答案:

答案 0 :(得分: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

将文件夹结构更新为此,并从firebase deploy --only functions搅动命令myProjectFolder

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": [ ]
  }
}

尝试一下并发表评论