Can anyone suggest a solution for this problem that seems quite odd.
Error is reported when running app on Android platform:
ReferenceError: NSString is not defined
for tns_modules/tns-core-modules/utils/utils.js', line: 79, column: 24
CLI: 3.4.0
Cross-platform modules: 3.2.0
Runtime(s): IOS: 3.4.0, Android: 3.4.1
I get the problem after a few test runs (tns run android), however I can remove it by installing a new Android platform. Then it starts over again...
The error causes the emulator to crash the application and seems to be same problem for all the devices I have tested.
The problem is also detected by the automated test on Google Play for specific versions of my app. However I have been able to deploy alpha test versions without the error.

Hi @mmeilby,
Does this problem happen, on clear NativeScript project or it is something related to your project?
It would help if you could provide a sample project, where this behavior could be reproduced.
Thank you in advance for your cooperation.
This is related to my project and I have no sample project available to reproduce the issue. However the problem is so odd that it might be known to someone. It looks like a mix of IOS and Android classes in the utils module.
I have updated to latest version of tns.
Seems to be reproducable by killing active "tns run android" and then issue a new "tns run android".
This lead to the error below. The only way to clear the error is to remove the platform/android folder and add the android platform again. With a fresh platform folder the application does not fail.
ActivityManager: Start proc 5338:dk.icup.matchview/u0a85 for activity dk.icup.matchview/com.tns.NativeScriptActivity
System.err: java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException:
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: ReferenceError: NSString is not defined
System.err: File: "file:///data/data/dk.icup.matchview/files/app/tns_modules/tns-core-modules/utils/utils.js, line: 79, column: 23
Hi @mmeilby,
In case you kill tns run android, while the lifesync is running and rebuilding, some files might not be copied properly in the device, which will lead to an issue on the second start of tns run android.
Regarding that, you could also run tns platform remove android command, before rebuilding the app, if this issue appears again.
Hi @tsonevn
Actually the problem appear as I have to kill the proces when the rebuild runs off the track. Doing small changes, native script will rebuild the code. However sometimes the rebuild never ends and continues to rebuild the same code.
So you might be right, though I am a little supprised that I can hit the same spot every time. The error is the same each time - some NSString class not available in Android environment.
Hi @mmeilby,
Thank you for the further description of the case.
However, to confirm that this is a real issue in NativeScript, we will need stable steps to reproduce this problem.
Regarding that, I think that we could close this issue and I will reopen it if we have some further info about the case or description how to reproduce it.
I'm having the exact same issue.
CLI: 3.2.1
CPM: 3.3.0
iOS/Android: 3.2.0/3.2.0
It occurs every single time that I run tns run android --emulator --watch. It does not occur when I save changes to a file and it refreshes automatically. However, if I hit Ctrl+C to stop the execution in the terminal, and run tns run android --emulator --watch again, this issue occurs. Also, if I restart my emulator and run tns run android --emulator --watch, the issue occurs as well.
One way I can consistently reproduce it is to build the Android platform while iOS platform is running on livesync, which will require me to rebuild the iOS platform to resume LiveSync. Then, after iOS has been built (while Android platform is running), if I stop the Android task and re-run it, this issue occurs.
Same problem as well and it's very annoying. Every time I stop the process with Ctrl+C and restart with tns run android the error comes again, and the only thing I can do is remove the entire Android in Platforms and rebuild the entire project again.
This is a very big waste of time.
This is happening to me since I use NativeScript from 10 months ago and I have updated tns periodically, so it's a cross version issue. Same in different computers.
I don't understand how there are no more users talking about this problem here, I think this is a major issue.
@Macarthurval I totally agree with you. I am still having this problem - and some others. But I have been used to remove the platform folders, restart the emulators and even reset the devices. If someone would take this serious it would be much appreciated. Either there is a flaw in the program or we are doing something completely wrong...
Now when running on real devices, I'm getting the same problem, no matter how many times I remove the platform and run again.
HI @AdamDenoon,
Can you provide sample project, which could be used for debugging?
I can't, unfortunately, since starting fresh with a project does not produce the problem. I'm entirely unsure of how to reproduce it... all I know is that it happens all too often.
Prime example... today, after installing fresh on a new machine, my project was running fine. I stopped the process (Ctrl-C in the terminal), made a superficial text change deep in the project (a literally meaningless one), and ran tns run android, and this happened.
Note: at the very bottom of the stack trace, it seems this is occurring first through line 1 in my app.js, which is where I require the "application" module.
I can reproduce this as well. It doesn't happen on a fresh project using the blank template. However, on the previous one as @AdamDenoon mentioned I could reproduce it after terminating the tns command, making a change (any change) and running tns run android again.
Note: Live Syncing does not cause the error to occur. You must terminate the tns command and re-run it. I've tried it with debug as well. Same issue. Consistently reproducing now. Only way it works is removing the platforms folder.
@tjvantoll
Hi @AdamDenoon @smaira,
If you terminate the process, while the tns command is still executed, some of the files might not be copied or executed correctly in the platforms folder. Also, this might be reproducible more often while building big projects, where a lot of external plugins are used as well.
In my opinion, the best solution in this case as @smaira already mentioned is to remove the platform with tns platform remove <platform name> and to start the build process again. I am not sure that we can do something in that case, where this problem happens after the build is terminated.
@tsonevn, I just want to clarify that I don't terminate the tns command during the build process but rather while the app is running, so the files should have already been copied over in platforms folder, right? Moreover, the error I'm getting is regarding NSString and there is a reference to ios but I am only building for android. Attaching the error.
+1 to @smaira’s comments. I’ve for sure hit this after the initial build completed, and the CLI process was only watching for changes. Using tns platform remove is a workaround, but it’s a huge hassle as you’d need to remove your platform before every run of your app.
@tsonevn tracked down the problem in @smaira’s app—it was a tns_modules folder that was still in the app folder from an older version of {N}. Once we deleted app/tns_modules the problem went away.
@AdamDenoon @mmeilby, @Macarthurval—do you have this folder in the apps you’re hitting this problem on?
I did have an app/tns_modules folder in my project. I deleted it, and then had to delete also platforms and node_modules. I have not since been able to replicate this issue. I'll come back and comment if it happens again, but we're looking good!
NOTE: I had a plugin I was using in tns_modules that didn't exist in node_modules, so I also had to run tns plugin add my-rogue-plugin.
And just to confirm things are now working on @smaira’s side as well. I think we’re all set here. If anyone else runs into this problem make sure look for an app/tns_modules folder and delete it. It’s a relic from earlier versions of {N} that’s now handled through the tns-core-modules npm dependency.
Yes, and be sure to run rm -rf platforms && rm -rf node_modules after you
do that
On Wed, May 2, 2018, 7:43 AM TJ VanToll notifications@github.com wrote:
And just to confirm things are now working on @smaira
https://github.com/smaira’s side as well. I think we’re all set here.
If anyone else runs into this problem make sure look for an
app/tns_modules folder and delete it. It’s a relic from earlier versions
of {N} that’s now handled through the tns-core-modules npm dependency.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/NativeScript/NativeScript/issues/5263#issuecomment-385964577,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACZccr2u4eRDWu1qKhEoKUhdsv6qhUyDks5tuaoCgaJpZM4RcZeY
.
@tjvantoll - Actually it isn't so much a relic as an unfortunate unsolved CLI issue. One of the ways it gets created has been found and fixed (https://github.com/NativeScript/nativescript-cli/issues/3016) but I've seen this occur on the Android side randomly throughout version 3's history and I haven't been able to come up with any steps to duplicate it.
It is one of the first things I check when seeing weird startup issues...
I'm not sure this is related. I'm also building an app for Android platform, but it has a part pertaining to iOS. This part (service) gets compiled and the application starts. However, when the lazy-loaded module containing this service gets hit via router it shoots this error during run-time:
JS: ERROR Error: Uncaught (in promise): ReferenceError: NSObject is not defined
JS: ReferenceError: NSObject is not defined
JS: at Object.<anonymous> (file:///data/data/org.nativescript.UnisApp/files/app/app/job/document-picker.delegate.js:
26:3)
JS: at require (<anonymous>:1:266)
JS: at Object.<anonymous> (file:///data/data/org.nativescript.UnisApp/files/app/app/job/document-picker.service.js:8
:34)
JS: at require (<anonymous>:1:266)
JS: at Object.<anonymous> (file:///data/data/org.nativescript.UnisApp/files/app/app/job/docs/docs.component.js:23:33
)
JS: at require (<anonymous>:1:266)
JS: at Object.<anonymous> (file:///data/data/org.nativescript.UnisApp/files/app/app/job/job.module.js:12:24)
JS: at require (<anonymous>:1:266)
JS: at file:///data/data/org.nativescript.UnisApp/files/app/tns_modules/tns-core-modules/globals/globals.js:81:32
JS: at new ZoneAwarePromise (file:///data/data/org.nativescript.UnisApp/files/app/tns_modules/nativescript-angular/z
one-js/dist/zone-nativescript.js:902:29)
JS: at Object.import (file:...
After the error, the app remains responsive, however, it just won't open that lazy-loaded route.
I have tried everything, but it wouldn't go. Finally had to remove this service altogether from the module, and then the application ran fine.
Using {N} 5.0 with Angular.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
I did have an
app/tns_modulesfolder in my project. I deleted it, and then had to delete alsoplatformsandnode_modules. I have not since been able to replicate this issue. I'll come back and comment if it happens again, but we're looking good!NOTE: I had a plugin I was using in
tns_modulesthat didn't exist innode_modules, so I also had to runtns plugin add my-rogue-plugin.