Background service example error on build


#1

I’m getting errors building or using tns run android on
https://github.com/NativeScript/sample-android-background-services

I used this command:

git clone https://github.com/NativeScript/sample-android-background-services
cd sample-android-background-services
tns run android

This throws errors same with
tns build android

Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not fi
nd WindowsSDKDir variable from the registry.  TargetFrameworkVersion or PlatformToolset may be set to an invalid versio
n number. [C:\nativescript\sample-android-background-services\node_modules\utf-8-validate\build\validation.vcxproj]
TRACKER : error TRK0005: Failed to locate: "CL.exe". The system cannot find the file specified. [C:\nativescript\sample
-android-background-services\node_modules\utf-8-validate\build\validation.vcxproj]


gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:125:13)
gyp ERR! stack     at ChildProcess.emit (events.js:213:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:197:12)
gyp ERR! System Windows_NT 10.0.14393
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\nativescript\sample-android-background-services\node_modules\utf-8-validate
gyp ERR! node -v v8.1.4
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
Build failed
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! utf-8-validate@1.0.1 install: `node ./build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the utf-8-validate@1.0.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Stephen Jason Wang\AppData\Roaming\npm-cache\_logs\2017-07-15T08_39_42_768Z-debug.log
Unable to install dependencies. Make sure your package.json is valid and all dependencies are correct. Error is: Command npm.cmd install failed with exit code 1

I’m trying to test the background functionality and apply it to nativescript-geolocation

Please don’t tell me to use nativescript-background-geolocation-lt (PREMIUM)

npm install also throws an error

Thank you.


Use sample-android-background-service for nativescript 3.0.1
#2

I don’t really appreciate the snarky comment. The technology is provided to you as-is, and you are able to augment it, read its code, send PRs, fix things. Did I mention, free of charge? Plugin authors are also free to decide whether they plugin will be open source, or paid for.

Back on-topic - the problem seems to be caused by either a corrupted npm package, or npm itself during npm install. At this point I can only suggest purging the npm cache (npm cache clean), the node_modules dir, and trying again.


#3

I’m sorry the comment was not meant to be snarky, all i’m saying is that the nativescript-background-geolocation-lt is expensive. I can’t afford to pay to pay $299 for a license https://www.transistorsoft.com/shop/products/nativescript-background-geolocation

I would rather take my time learning the technology and perhaps writing a code to implement a background service geolocation. At the moment, there are no plugins available which will accomplish what i need. I need the geolocation to be tracked even if the app is closed, not minimized.

running npm cache clean results in this error

C:\nativescript\sample-android-background-services>npm cache clean
npm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead.
npm ERR!
npm ERR! If you're sure you want to delete the entire cache, rerun this command with --force.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Stephen Jason Wang\AppData\Roaming\npm-cache\_logs\2017-07-15T15_30_56_008Z-debug.log

so i used the --force flag and it purged the cache but after clearing , i run npm install and this error still showed up

C:\nativescript\sample-android-background-services>npm install

> utf-8-validate@1.0.1 install C:\nativescript\sample-android-background-services\node_modules\utf-8-validate
> node ./build.js

(node:5660) [DEP0006] DeprecationWarning: child_process: options.customFds option is deprecated. Use options.stdio instead.

C:\nativescript\sample-android-background-services\node_modules\utf-8-validate>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not fi
nd WindowsSDKDir variable from the registry.  TargetFrameworkVersion or PlatformToolset may be set to an invalid versio
n number. [C:\nativescript\sample-android-background-services\node_modules\utf-8-validate\build\validation.vcxproj]
TRACKER : error TRK0005: Failed to locate: "CL.exe". The system cannot find the file specified. [C:\nativescript\sample
-android-background-services\node_modules\utf-8-validate\build\validation.vcxproj]


gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:125:13)
gyp ERR! stack     at ChildProcess.emit (events.js:213:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:197:12)
gyp ERR! System Windows_NT 10.0.14393
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\nativescript\sample-android-background-services\node_modules\utf-8-validate
gyp ERR! node -v v8.1.4
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
Build failed
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! utf-8-validate@1.0.1 install: `node ./build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the utf-8-validate@1.0.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Stephen Jason Wang\AppData\Roaming\npm-cache\_logs\2017-07-15T15_31_55_585Z-debug.log

Thank you for the reply, have a nice evening to you my friend.


#4

To be completely honest, I don’t know what you could do at this point. Seems like a problem with the utf-8-validate npm package, which, if I understand correctly is a dependency to one of the dev dependencies. Could you report what the results of tns create newApp && cd newApp && tns run android is? I would expect that to fail in a similar manner.

Thanks!


#5

Hi Pete, tns create newApp && cd newApp && tns run android
runs perfectly.

Tried to copy all the js file and xml file from

to this newApp then npm install. tns run android
Error gone.
Problem is, I don’t think the background service is running.
Changed the seconds on which the notification should show to 5seconds and still nothing happens.
Even if the app is still open.


#6

Did you copy the AndroidManifest? https://github.com/NativeScript/sample-android-background-services/blob/master/app/App_Resources/Android/AndroidManifest.xml into your own App_Resources/Android?

Also, there’s a blog post explaining what each file’s purpose is. Bear in mind, everything is android-specific - https://www.nativescript.org/blog/using-android-background-services-in-nativescript


#7

I only copied all js xml and css
I’ll try to copy the androidmanifest file and read all the resources you’ve sent.

I’ll get back to you as soon as I’ve done it.

Thank you for helping


#8

Hi Pete,


Uploaded the files i copied from sample android background services

If you’d check the app.
I changed service-helper.js setupAlarm function to notify every 2 seconds
it then calls getStartPendingIntent function on the same file.
disregard my comment on line 4

Then it calls createIntentStartNotificationService(context);
on line 8 of broadcastreceivers/NotificationEventReceiver.js

then line 24 throws the error
when

var intent = new Intent(context, com.tns.notifications.NotificationIntentService.class);

i think it is not being referenced properly

Because if you run the app and press the button
it throws this error

TypeError: Cannot read property 'NotificationIntentService' of undefined ...

#9

Getting the same error:
System.err: TypeError: Cannot read property 'NotificationIntentService' of undefined