System.err:调用 js 方法 onCreate 失败 - System.err:错误:缺少主条目。应用程序无法启动。验证应用引导程序
Posted
技术标签:
【中文标题】System.err:调用 js 方法 onCreate 失败 - System.err:错误:缺少主条目。应用程序无法启动。验证应用引导程序【英文标题】:System.err: Calling js method onCreate failed - System.err: Error: Main entry is missing. App cannot be started. Verify app bootstrap 【发布时间】:2019-11-14 03:37:37 【问题描述】:我有一个使用 Angular 7 的 Web 应用程序,并且想从 NativeScript 进行代码共享。 成功安装 nativescript 和架构后,我尝试运行 tns run android --bundle。
最奇怪的是,当我第一次运行应用程序时,它会显示错误。当我更改 smt 然后使用热重载功能保存它时,它会完美显示。
但我收到此错误:
System.err: java.lang.RuntimeException: 无法启动活动 组件信息org.nativescript.ngsample/com.tns.NativeScriptActivity: com.tns.NativeScriptException: System.err: 调用 js 方法 onCreate 失败 System.err:System.err:错误:缺少主条目。应用程序 无法启动。验证应用引导程序。 System.err:文件: “file:///data/data/org.nativescript.ngsample/files/app/vendor.js, 行:21913,列:20 System.err:System.err:StackTrace: System.err:帧: 功能:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.setActivityContent', 文件:'file:///data/data/org.nativescript.ngsample/files/app/vendor.js', 行:21913,列:27 System.err:框架: 功能:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.onCreate', 文件:'file:///data/data/org.nativescript.ngsample/files/app/vendor.js', 行:21758,列:14 System.err:框架: 功能:'push.../node_modules/tns-core-modules/ui/frame/activity.js.NativeScriptActivity.onCreate', 文件:'file:///data/data/org.nativescript.ngsample/files/app/vendor.js', 行:19571,列:25 System.err:System.err:at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913) System.err:在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) System.err:在 android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) System.err:在 android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) System.err:在 android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) System.err:在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) System.err:在 android.os.Handler.dispatchMessage(Handler.java:106) System.err: 在 android.os.Looper.loop(Looper.java:193) System.err: 在 android.app.ActivityThread.main(ActivityThread.java:6669) System.err: 在 java.lang.reflect.Method.invoke(Native Method) System.err: 在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) System.err:在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) System.err:引起:com.tns.NativeScriptException:System.err: 调用 js 方法 onCreate 失败 System.err: System.err: Error: Main 条目丢失。应用程序无法启动。验证应用引导程序。 System.err:文件: “file:///data/data/org.nativescript.ngsample/files/app/vendor.js, 行:21913,列:20 System.err:System.err:StackTrace: System.err:帧: 功能:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.setActivityContent', 文件:'file:///data/data/org.nativescript.ngsample/files/app/vendor.js', 行:21913,列:27 System.err:框架: 功能:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.onCreate', 文件:'file:///data/data/org.nativescript.ngsample/files/app/vendor.js', 行:21758,列:14 System.err:框架: 功能:'push.../node_modules/tns-core-modules/ui/frame/activity.js.NativeScriptActivity.onCreate', 文件:'file:///data/data/org.nativescript.ngsample/files/app/vendor.js', 行:19571,列:25 System.err:System.err:at com.tns.Runtime.callJSMethodNative(Native Method) System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1203) System.err:在 com.tns.Runtime.callJSMethodImpl(Runtime.java:1083) System.err:在 com.tns.Runtime.callJSMethod(Runtime.java:1070) System.err:在 com.tns.Runtime.callJSMethod(Runtime.java:1050) System.err:在 com.tns.Runtime.callJSMethod(Runtime.java:1042) System.err:在 com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:19) System.err:在 android.app.Activity.performCreate(Activity.java:7136) System.err: 在 android.app.Activity.performCreate(Activity.java:7127) System.err: 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) System.err:在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) System.err: ... 11 更多成功同步的应用程序 设备 emulator-5554 上的 org.nativescript.ngsample。
我删除了钩子、平台、node_modules 和 webpack.config.js 文件,然后再次安装,但没有任何改变。我还将 tns-core-modules、typescript 和 nativescript-dev-webpack 升级到最新版本。我错过了什么?
我的 package.json 文件:
"name": "farm-management-ui",
"description": "The UI for farm management",
"version": "0.0.0",
"license": "MIT",
"scripts":
"android": "tns run android --bundle",
"ios": "tns run ios --bundle",
"mobile": "tns run --bundle",
"preview": "tns preview --bundle",
"ng": "ng",
"start": "ng serve --base-href=/ui/",
"start-local-prod": "ng serve --base-href=/ui/",
"start-traci": "ng serve --configuration=traci-dev --base-href=/ui/",
"build": "ng build --prod --base-href=/ui/",
"build-traci": "ng build --prod --configuration=traci --base-href=/ui/",
"test": "ng test --code-coverage=true",
"lint": "ng lint",
"e2e": "ng e2e",
"loco": "node tools/update-localized-strings.js",
"bundle-report": "webpack-bundle-analyzer dist/stats.json",
"licenses": "node tools/extract-licenses.js"
,
"private": true,
"dependencies":
"@angular-devkit/architect": "^0.13.9",
"@angular-devkit/build-optimizer": "^0.13.9",
"@angular-devkit/build-webpack": "^0.13.9",
"@angular-devkit/core": "^7.3.9",
"@angular/animations": "^7.2.0",
"@angular/cdk": "^7.2.1",
"@angular/common": "7.2.0",
"@angular/compiler": "7.2.0",
"@angular/core": "7.2.0",
"@angular/forms": "7.2.0",
"@angular/http": "7.2.0",
"@angular/material": "^7.2.1",
"@angular/platform-browser": "7.2.0",
"@angular/platform-browser-dynamic": "7.2.0",
"@angular/router": "7.2.0",
"@asymmetrik/ngx-leaflet": "^3.0.2",
"@asymmetrik/ngx-leaflet-draw": "^2.7.1",
"@asymmetrik/ngx-leaflet-markercluster": "^1.0.0",
"@bwc/bwc-button": "^2.0.5",
"@bwc/bwc-footer": "^2.0.2",
"@bwc/bwc-header": "^4.1.2",
"@bwc/bwc-input": "^2.2.2",
"@bwc/bwc-overlay": "^3.0.6",
"@bwc/bwc-style": "^2.1.0",
"@inst-iot/bosch-angular-ui-components": "^0.3.20",
"@nativescript/schematics": "^0.6.0",
"@ng-bootstrap/ng-bootstrap": "^4.0.1",
"@ngx-translate/core": "^11.0.1",
"@ngx-translate/http-loader": "^4.0.0",
"@schematics/angular": "^7.3.9",
"@swimlane/ngx-datatable": "^14.0.0",
"@types/geojson": "^1.0.6",
"@types/leaflet": "^1.2.6",
"@types/leaflet.markercluster": "^1.0.3",
"@types/leaflet.pm": "^0.13.3",
"@webcomponents/webcomponentsjs": "^2.2.4",
"angular-2-local-storage": "^1.0.1",
"bootstrap-daterangepicker": "^3.0.3",
"bosch-bootstrap": "git+https://products.bosch-si.com/stash/scm/instiot/bosch-bootstrap.git#v4",
"brace": "^0.10.0",
"chart.js": "^2.7.2",
"chartjs-plugin-annotation": "^0.5.7",
"chartjs-plugin-zoom": "^0.6.6",
"classlist.js": "^1.1.20150312",
"core-js": "^2.5.1",
"file-saver": "^1.3.8",
"flatpickr": "^4.5.7",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
"json-formatter-js": "^2.2.0",
"leaflet": "^1.3.1",
"leaflet-draw": "^1.0.2",
"leaflet-easybutton": "^2.3.0",
"leaflet.markercluster": "^1.3.0",
"leaflet.pm": "^0.22.0",
"magic-string": "^0.22.4",
"moment": "^2.19.4",
"nan": "^2.14.0",
"nativescript-angular": "~7.2.0",
"nativescript-theme-core": "~1.0.4",
"ng2-ace-editor": "^0.3.3",
"ng5-slider": "^1.1.3",
"ngx-clipboard": "^12.1.2",
"ngx-gallery": "^4.3.0",
"ngx-toastr": "^10.0.2",
"ngx-ui-switch": "^6.0.3",
"popper.js": "^1.13.0",
"puppeteer": "^1.17.0",
"reflect-metadata": "~0.1.12",
"rxjs": "^6.3.3",
"sass-loader": "^6.0.5",
"tmp": "0.0.30",
"tns-core-modules": "^5.4.3",
"tslib": "^1.9.0",
"uuid": "^3.3.2",
"web-animations-js": "^2.3.1",
"zone.js": "^0.8.27"
,
"devDependencies":
"@angular-devkit/build-angular": "^0.12.4",
"@angular/cli": "^7.3.9",
"@angular/compiler-cli": "8.0.0",
"@angular/language-service": "7.2.0",
"@nativescript/schematics": "0.6.0",
"@types/chart.js": "^2.7.18",
"@types/jasmine": "2.8.6",
"@types/leaflet-draw": "^0.4.11",
"@types/node": "^6.0.92",
"codelyzer": "^4.2.1",
"https-proxy-agent": "^2.1.1",
"jasmine-core": "^2.99.1",
"jasmine-spec-reporter": "~4.1.0",
"karma": "^1.7.1",
"karma-chrome-launcher": "^2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.4.3",
"karma-firefox-launcher": "^1.0.1",
"karma-jasmine": "^1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-spec-reporter": "0.0.32",
"license-checker": "^21.0.0",
"nativescript-dev-webpack": "^0.24.1",
"node-sass": "^4.12.0",
"protractor": "~5.1.2",
"rxjs-tslint": "^0.1.6",
"style-loader": "^0.23.1",
"ts-node": "~3.0.4",
"tslint": "^5.10.0",
"typescript": "^3.4.5"
,
"nativescript":
"id": "org.nativescript.ngsample",
"tns-android":
"version": "5.4.0"
我的 main.tns.ts 文件:
import platformNativeScriptDynamic from 'nativescript-angular/platform';
import AppModule from './app/app.module';
platformNativeScriptDynamic().bootstrapModule(AppModule);
我的 main.ts 文件:
import enableProdMode from '@angular/core';
import platformBrowserDynamic from '@angular/platform-browser-dynamic';
import AppModule from './app/app.module';
import environment from './environments/environment';
if (environment.production)
enableProdMode();
document.addEventListener('WebComponentsReady', () =>
platformBrowserDynamic()
.bootstrapModule(AppModule, preserveWhitespaces: false)
.catch(err => console.log(err));
);
【问题讨论】:
你能更新你在main.ts
中的内容吗?
@Manoj 是的!已经完成了!谢谢!
@Manoj 最奇怪的是,当您第一次运行应用程序时,它会显示错误。当您使用热重载功能进行更改保存时,它会完美显示。
【参考方案1】:
这对我有用...
从 package.json 文件中的依赖项和 devDependencies 中删除所有包(仅保存在某些 .txt 文件中,这是必需的)
运行 npm i,它将从 node_modules 文件夹中删除所有包
之后,返回所有在dependecies和devDependecies中的包,并保存
然后再次运行 npm i 即可启动项目。
【讨论】:
【参考方案2】:尝试像下面这样实现引导程序。 main.ts 文件
import enableProdMode from '@angular/core';
import platformBrowserDynamic from '@angular/platform-browser-dynamic';
import AppModule from './app/app.module';
import environment from './environments/environment';
if (environment.production)
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule, preserveWhitespaces: false)
.catch(err => console.log(err));
【讨论】:
嗨!感谢您的回复!我再次遇到同样的错误......奇怪的是,正如我所说,当我在第一次执行后进行更改时,我可以看到应用程序。 @KathrineHanson 嗨,当任何组件中缺少导入时,我都会遇到同样的错误。请验证您的应用中是否存在任何代码错误。 嗨西玛!谢谢你的回复。您的意思是 .tns 文件对吗?这只会在开始时发生在你身上,因为对我来说只有这样才会发生,然后当我进行更改时,我可以看到我的应用程序。以上是关于System.err:调用 js 方法 onCreate 失败 - System.err:错误:缺少主条目。应用程序无法启动。验证应用引导程序的主要内容,如果未能解决你的问题,请参考以下文章
System.out.println 和 System.err.println 乱序