I am struggling for days to implement android user subscription into android. I am using the google dev tutorial for Java in-app purchases:
https://github.com/android/play-billing-samples/tree/master/ClassyTaxiJava
At the last section, I need to deploy backend Server as described here:
https://github.com/android/play-billing-samples/tree/master/ClassyTaxiServer
What I did:
firebase login
--> OKfirebase use -add
--> OKfirebase functions:config:set app.package_name="com.mypackage.app"
--> OKdeploy firebase
--> ERRORError is as below:
=== 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
I noticed after deploying, a "server" folder is made inside the project folder that nothing is inside the server folder. I tried putting the package.json file inside it and deploy again, but it did not work.
*** It was also mentioned in git as issue here and someone responded:
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.
Error after changing the folder structure:
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: []
}
Error: functions predeploy error: Command terminated with non-zero exit code1
look at this code brother i m using it in my firebase functions the code lies in 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"
});
following is my directory structure
functions
├── common
| └── serviceAccountKey.json
└── src
└── index.ts
hope this help. ask if you face problem ;)
[UPDATE]
there is no problem with your firebase.json
. actually it is looking for the right folder. put the package.json in right place, where it is kept is wrong. it should be kept outside the server folder. where the src folder lies so this should be the updated directory structure :
myProjectFolder
├──server
| ├── common
| | └── serviceAccountKey.json
| ├── src
| | └── index.ts
| └──package.json, tsconfig.json and other files
└── firebase.json
update your folder structure to this and git the command firebase deploy --only functions
from myProjectFolder
package.json for windows [EDIT]
{
"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": [ ]
}
}
try this and comment back