Currently I am having an issue, where users had JIT version of the app. Now I have released an AOT version, but when people update their app, it immediately crashes:
java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException:
Error calling module function
Error: com.tns.NativeScriptException: Failed to find module: "ui/frame/activity", relative to: app/tns_modules/
It is because AOT does not have tns_modules folder there by idea. If one clears its app data, the app works fine. I guess the app is storing some sort of startup code in app data. Is there a way to programmatically or in some preferences specify, for an app to clear app data?
There is something like this: PreferenceManager.getDefaultSharedPreferences(context).edit().clear().apply();
But where do I put it in my code? The app crashes at startup screen, without getting to the first component.
Perhaps I can build a new AOT version of the app with tns_modules folder in it, which would make users, who update their app, app not to crash. And by that point, I could get into app.component.ts code and execute the upper mentioned function? And immediately after that I would set a flag, so it only clears app data once in that version. After that I could release a normal AOT version without tns_modules folder.
Well, the above mentioned plan fails, even with tns_modules in there, the app crashes, which is not surprising. However, it does work if I make an update a JIT version. At least then I get to code execution.
So, the upper mentioned function didn't do anything, however this did applicationSettings.clear();
But, it only deletes my custom set variables, which were set with applicationSettings.setString("my_var", "test_value"), it does not delete the startup data, which causes aot to crash.
@dxshindeo as you noticed the application-settings module is used to store and persist custom data for user interaction. Behind application-settings lies _SharedPreferences_ for Android and _NSUserDefaults_ for iOS.
The reason for your application to throw during start up is elsewhere- can you share your package.json and NativeScript-CLI, tns-android and tns-core-modules versions. Are you building your application debug or in release mode? As a possible solution try to update your NativeScript to 2.5.0 and follow these instructions
It seems, that the procedure, which kickstarts the whole app, comes from app data. When AOT is put over JIT app, and AOT tries to start, he sees `Ou, I have my kickstart procedure already unpacked here in app data, so I'll use it." But that is JITs startup procedure, not AOTs. Thats why the error is thrown, AOT doesn't have such folder there.
And yes, the app is in production and release mode, with lazy loading and AOT enabled.
package.json:
{
"description": "Mobile Application",
"license": "",
"readme": "",
"repository": "",
"nativescript": {
"id": "com.test.test",
"tns-android": {
"version": "2.5.0"
}
},
"dependencies": {
"@angular/common": "2.4.6",
"@angular/compiler": "2.4.6",
"@angular/core": "2.4.6",
"@angular/forms": "2.4.6",
"@angular/http": "2.4.6",
"@angular/platform-browser": "2.4.6",
"@angular/platform-browser-dynamic": "2.4.6",
"@angular/router": "3.4.6",
"nativescript-angular": "1.4.0",
"nativescript-angular-snapshot": "1.4.0-5.5.372.32",
"nativescript-geolocation": "0.0.18",
"nativescript-gif": "^1.0.8",
"nativescript-google-maps-sdk": "^1.4.3",
"nativescript-phone": "^1.2.4",
"nativescript-platform-css": "^1.4.0",
"nativescript-vibrate": "^1.1.2",
"reflect-metadata": "^0.1.9",
"rxjs": "5.1.0",
"tns-core-modules": "2.5.0",
"tns-platform-declarations": "^2.5.0"
},
"devDependencies": {
"@angular/compiler-cli": "~2.4.6",
"@ngtools/webpack": "1.2.8",
"babel-traverse": "6.22.1",
"babel-types": "6.22.0",
"babylon": "6.15.0",
"copy-webpack-plugin": "~4.0.1",
"extract-text-webpack-plugin": "~2.0.0-beta.4",
"htmlparser2": "~3.9.2",
"lazy": "1.0.11",
"nativescript-css-loader": "~0.26.1",
"nativescript-dev-android-snapshot": "^0.*.*",
"nativescript-dev-typescript": "^0.3.7",
"nativescript-dev-webpack": "^0.3.3",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~1.6.1",
"typescript": "^2.1.5",
"webpack": "2.2.1",
"webpack-sources": "~0.1.4",
"zone.js": "^0.7.6"
},
"scripts": {
"clean-android": "tns clean-app android",
"clean-ios": "tns clean-app ios",
"prewebpack-android": "npm run clean-android",
"prewebpack-ios": "npm run clean-ios",
"webpack-android": "webpack --config=webpack.android.js --progress",
"webpack-ios": "webpack --config=webpack.ios.js --progress",
"prestart-android-bundle": "npm run webpack-android",
"prestart-ios-bundle": "npm run webpack-ios",
"start-android-bundle": "tns run android --bundle --disable-npm-install",
"start-ios-bundle": "tns run ios --bundle --disable-npm-install",
"prebuild-android-bundle": "npm run webpack-android",
"prebuild-ios-bundle": "npm run webpack-ios",
"build-android-bundle": "tns build android --bundle --disable-npm-install",
"build-ios-bundle": "tns build ios --bundle --disable-npm-install"
}
}
@dxshindeo thanks for sending us your package.json content.
There are several things that might be a stopper for your successful release build using webpack.
npm install --save-dev nativescript-dev-webpack. For your convenience here is the package.json set with the supported version of webpack, typescript , @ngtools/webpack, {
"description": "Mobile Application",
"license": "",
"readme": "",
"repository": "",
"nativescript": {
"id": "com.nativescript.test",
"tns-android": {
"version": "2.5.0"
}
},
"dependencies": {
"@angular/common": "2.4.6",
"@angular/compiler": "2.4.6",
"@angular/core": "2.4.6",
"@angular/forms": "2.4.6",
"@angular/http": "2.4.6",
"@angular/platform-browser": "2.4.6",
"@angular/platform-browser-dynamic": "2.4.6",
"@angular/router": "3.4.6",
"nativescript-angular": "1.4.0",
"nativescript-angular-snapshot": "1.4.0-5.5.372.32",
"nativescript-geolocation": "0.0.18",
"nativescript-gif": "^1.0.8",
"nativescript-google-maps-sdk": "^1.4.3",
"nativescript-phone": "^1.2.4",
"nativescript-platform-css": "^1.4.0",
"nativescript-theme-core": "1.0.2",
"nativescript-vibrate": "^1.1.2",
"reflect-metadata": "^0.1.9",
"rxjs": "5.1.0",
"tns-core-modules": "2.5.0",
"tns-platform-declarations": "^2.5.0"
},
"devDependencies": {
"@angular/compiler-cli": "2.4.6",
"@ngtools/webpack": "1.2.4",
"babel-traverse": "6.22.1",
"babel-types": "6.22.0",
"babylon": "6.15.0",
"copy-webpack-plugin": "~4.0.1",
"extract-text-webpack-plugin": "~2.0.0-beta.4",
"htmlparser2": "~3.9.2",
"lazy": "1.0.11",
"nativescript-css-loader": "~0.26.1",
"nativescript-dev-android-snapshot": "^0.*.*",
"nativescript-dev-typescript": "^0.3.7",
"nativescript-dev-webpack": "^0.3.3",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~1.6.1",
"typescript": "~2.1.5",
"webpack": "2.2.0",
"webpack-sources": "~0.1.4",
"zone.js": "^0.7.6"
},
"scripts": {
"clean-android": "tns clean-app android",
"clean-ios": "tns clean-app ios",
"prewebpack-android": "npm run clean-android",
"prewebpack-ios": "npm run clean-ios",
"webpack-android": "webpack --config=webpack.android.js --progress",
"webpack-ios": "webpack --config=webpack.ios.js --progress",
"prestart-android-bundle": "npm run webpack-android",
"prestart-ios-bundle": "npm run webpack-ios",
"start-android-bundle": "tns run android --bundle --disable-npm-install",
"start-ios-bundle": "tns run ios --bundle --disable-npm-install",
"prebuild-android-bundle": "npm run webpack-android",
"prebuild-ios-bundle": "npm run webpack-ios",
"build-android-bundle": "tns build android --bundle --disable-npm-install",
"build-ios-bundle": "tns build ios --bundle --disable-npm-install"
}
}
npm install open node_modules folder and locate the root package.json of each native scripts plugin. Look for the main key and remove the file extension from its value. For example:"main": "vibrate.js",
and change it to
"main": "vibrate",
Now the plugin is webpack enabled.
"paths": {
"ui/*": ["node_modules/tns-core-modules/ui/*"],
"platform": ["node_modules/tns-core-modules/platform"],
"image-source": ["node_modules/tns-core-modules/image-source"],
"xml": ["node_modules/tns-core-modules/xml"],
"xhr": ["node_modules/tns-core-modules/xhr"],
"text": ["node_modules/tns-core-modules/text"],
"data": ["node_modules/tns-core-modules/data"],
"fetch": ["node_modules/tns-core-modules/fetch"],
"trace": ["node_modules/tns-core-modules/trace"],
"fps-meter": ["node_modules/tns-core-modules/fps-meter"],
"color": ["node_modules/tns-core-modules/color"],
"application-settings": ["node_modules/tns-core-modules/application-settings"],
"http": ["node_modules/tns-core-modules/http"],
"camera": ["node_modules/tns-core-modules/camera"],
"console": ["node_modules/tns-core-modules/console"],
"timer": ["node_modules/tns-core-modules/timer"],
"utils": ["node_modules/tns-core-modules/utils"],
"location": ["node_modules/tns-core-modules/location"],
"file-system": ["node_modules/tns-core-modules/file-system"],
"application": ["node_modules/tns-core-modules/application"],
"image-asset": ["node_modules/tns-core-modules/image-asset"],
"connectivity": ["node_modules/tns-core-modules/connectivity"],
"globals": ["node_modules/tns-core-modules/globals"]
}
npm run build-android-bundle -- --release --for-device --key-store-path D:\my-release-key.jks --key-store-password MyPass --key-store-alias MyAlias --key-store-alias-password MyPass
Full documentation article that explains all about bundling and build in release with webpack can be found here
Hey @dxshindeo closing this due to inactivity but please let me know if you need further assistance
I seem to be having what I believe to be the same issue. Recently tried to publish my application with AOT, but it is throwing the error at startup.
For whatever reason it works as a fresh install on my simulators, but won't succeed on my device. Even if I uninstall the application completely it will still fail to start as a fresh install on my device.
Ok to add to my previous comment, uninstalling the application from my device didn't work, but clearing the data on my application did work for the device.
Does something linger on the device after an uninstallation? How do I do a proper upgrade from plain to Webpack in the app store so it doesn't crash for all my users?
Does something linger on the device after an uninstallation?
I have seen the same thing - even though I uninstall my app, sometimes it does not remove previous appData, but clearing it specifically and then uninstalling does the trick.
@NickIliev
I think more seriousness should be included into this issue. I upgraded my application from non-webpack to webpack and now I'm getting a flood of these errors in my Google Play.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nraboy.solarflare/com.tns.NativeScriptActivity}: com.tns.NativeScriptException:
Calling js method onCreate failed
Error: A Frame must be used to navigate to a Page.
File: "file:///data/data/com.nraboy.solarflare/files/app/tns_modules/tns-core-modules/ui/frame/frame.js, line: 680, column: 16
StackTrace:
Frame: function:'ZoneAwareError', file:'file:///data/data/com.nraboy.solarflare/files/app/vendor.js', line: 58401, column: 33
Frame: function:'ActivityCallbacksImplementation.onCreate', file:'file:///data/data/com.nraboy.solarflare/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 680, column: 23
Frame: function:'NativeScriptActivity.onCreate', file:'file:///data/data/com.nraboy.solarflare/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 13, column: 25
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2666)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: com.tns.NativeScriptException:
Calling js method onCreate failed
Error: A Frame must be used to navigate to a Page.
File: "file:///data/data/com.nraboy.solarflare/files/app/tns_modules/tns-core-modules/ui/frame/frame.js, line: 680, column: 16
StackTrace:
Frame: function:'ZoneAwareError', file:'file:///data/data/com.nraboy.solarflare/files/app/vendor.js', line: 58401, column: 33
Frame: function:'ActivityCallbacksImplementation.onCreate', file:'file:///data/data/com.nraboy.solarflare/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 680, column: 23
Frame: function:'NativeScriptActivity.onCreate', file:'file:///data/data/com.nraboy.solarflare/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 13, column: 25
at com.tns.Runtime.callJSMethodNative(Native Method)
at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1197)
at com.tns.Runtime.callJSMethodImpl(Runtime.java:1061)
at com.tns.Runtime.callJSMethod(Runtime.java:1047)
at com.tns.Runtime.callJSMethod(Runtime.java:1028)
at com.tns.Runtime.callJSMethod(Runtime.java:1018)
at com.tns.NativeScriptActivity.onCreate(android.app.Activity.java)
at android.app.Activity.performCreate(Activity.java:6682)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
... 9 more
Clearing the application data manually fixes the problem while uninstalling the application does not. Like @dxshindeo mentioned, something is lingering on the device and breaking upgrades.
cc @tjvantoll
Reopening this as we have a confirmed case of this occurring.
Hi @dxshindeo , @nraboy , @tjvantoll.
Thank you for reporting this issue.
After some tests, I was able to reproduce similar issue like the above described one, with upgrade an application from non-webpack to webpack.
We will investigate further this case and will check what is causing this crash.
Please keep track on the issue for further info and for a possible fix.
Best Regards,
@tsonevn
Hey guys(@dxshindeo , @nraboy , @tjvantoll)
I think we found the source of all evil. Here is what happens:
tns-java-classes.js that get inserted in the app folder that goes in the apk. On application startup this files is automatically required if it exists by the android-runtime.app folder.When you have no-webpack version installed and you update/reinstall a webpack version on top of it - the tns-java-classes.js still remains in the app folder and is still loaded on app startup. This causes the the crash as the app now uses webpacked bundles and the tns-java-classes files does some invalid requires.
_Note:_ This does not happen locally when using tns run, as it uninstalls the app first and then installs the newer version. If you just build the app and install the .apk with adb install -r <app>.apk you can reproduce the crash. It is like updating the app from play store.
There is an easy workaround. Just create an empty tns-java-classes.js file when building with web-pack. It will override the existing file already deployed in the app folder from previous installs. However as it is empty - it won't cause problems. To create the file - just specify it along as the vendor chunk in the webpack.common.js:
// Vendor libs go to the vendor.js chunk
new webpack.optimize.CommonsChunkPlugin({
name: ["vendor", "tns-java-classes"]
}),
...
@sis0k0 is currently doing a fix to put this fix in the default webpack config file you get when you install nativescript-dev-webpack plugin.
What is the timeline and are you sure this resolves everything?
@nraboy We managed to reproduce the problem locally and the fix resolved the issue. You can already apply the fix iff you add the changes the above changes in you webpack config.
@sis0k0 Already has a PR in NativeScript/nativescript-dev-webpack#128, which will add these changes by default when you install web pack plugin in projects.
Closing this one as resolved via https://github.com/NativeScript/nativescript-dev-webpack/pull/128
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
Hey guys(@dxshindeo , @nraboy , @tjvantoll)
I think we found the source of all evil. Here is what happens:
tns-java-classes.jsthat get inserted in theappfolder that goes in the apk. On application startup this files is automatically required if it exists by the android-runtime.appfolder.Problem
When you have no-webpack version installed and you update/reinstall a webpack version on top of it - the
tns-java-classes.jsstill remains in theappfolder and is still loaded on app startup. This causes the the crash as the app now uses webpacked bundles and thetns-java-classesfiles does some invalid requires._Note:_ This does not happen locally when using
tns run, as it uninstalls the app first and then installs the newer version. If you just build the app and install the.apkwithadb install -r <app>.apkyou can reproduce the crash. It is like updating the app from play store.Solution
There is an easy workaround. Just create an empty
tns-java-classes.jsfile when building with web-pack. It will override the existing file already deployed in theappfolder from previous installs. However as it is empty - it won't cause problems. To create the file - just specify it along as thevendorchunk in thewebpack.common.js:@sis0k0 is currently doing a fix to put this fix in the default webpack config file you get when you install
nativescript-dev-webpackplugin.