为 classytaxi android in-app 购买部署后端服务器?

Deploying backend server for android in-app purchases for classytaxi?

为了实现 android 用户订阅 android,我苦苦挣扎了好几天。我正在使用 google 开发教程进行 Java in-app 购买:

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 项目 --> OK
  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\_logs20-04-18T22_21_16_430Z-debug.log

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

我注意到部署后,在项目文件夹中创建了一个 "server" 文件夹,服务器文件夹中没有任何内容。我尝试将 package.json 文件放入其中并再次部署,但没有成功。

*** 它也在 git 中作为问题 here 提到,有人回复:

Notes: In firebase.json, https://github.com/android/play-billing-samples/blob/master/ClassyTaxiServer/firebase.json There are no 'server' or 'web' directory, firebase cann't deploy functions and hosting with these folder.

我的 firebase 项目文件夹:

我的服务器文件夹:

我的源文件夹:

更改文件夹结构后出错:

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

错误:函数预部署错误:命令以 non-zero 退出代码 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

将您的文件夹结构更新为此,并git来自myProjectFolder

的命令firebase deploy --only functions

package.json 对于 windows [编辑]

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

试试这个并回复评论