Android - require("tns-core-modules/platform").device.uuid | Cannot read property 'getContentResolver' of undefined
See original GitHub issueFrom @cpreston321 on March 18, 2019 16:3
Environment
Provide version numbers for the following components (information can be retrieved by running tns info
in your project folder or by inspecting the package.json
of the project):
- CLI: 5.2.4
- Cross-platform modules:5.2.2
- Android Runtime:5.2.1
- iOS Runtime:5.2.0
- Plugin(s): NONE
Describe the bug When you try to recieve the device uuid on Android the app crashes saying that Cannot read property ‘getContentResolver’ of undefined. But IOS works perfectly fine.
To Reproduce Just add this to startup of the project
const platformModule = require("tns-core-modules/platform");
var test = { uuid: platformModule.device.uuid, }; console.log("asdasdasd", JSON.stringify(test));
Expected behavior Supposed to return the uuid of the device.
Sample project https://play.nativescript.org/?template=play-vue&id=v2zJSb&v=1
Additional context
I tried logging the platform.android.js file under “tns-core-modules/platform” and logged var nativeApp = appModule.android.nativeApp;
came back as undefined
so if that could help you debug it faster thanks.
Copied from original issue: NativeScript/NativeScript#7041
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
It will also work if you wrap that code in a
setTimeout
:We are locking this issue because it has been closed for more than 14 days.
If the issue comes up again please open a new issue with additional details.