Nativescript Android 不断崩溃
Nativescript Android keeps crashing
我正在创建一个 nativescript 应用程序,当我尝试在我的 android 设备(通过 USB 连接)上进行调试时,该应用程序打开启动画面并立即崩溃,控制台中没有显示任何错误。
我打开另一个终端并使用 adb logcat *:W --pid=15820
获取错误输出(警告及以上),我看到的只是连接失败。这些发生在应用程序崩溃后并每秒重复一次。我还能做些什么来找出我的应用崩溃的原因?它在 ios 模拟器上运行良好。
06-29 15:45:30.127 15820 15820 E adbd : failed to connect to socket 'localabstract:com.mycompany.myapp-livesync': Connection refused
06-29 15:45:31.136 15820 15820 E adbd : failed to connect to socket 'localabstract:com.mycompany.myapp-livesync': Connection refused
06-29 15:45:32.141 15820 15820 E adbd : failed to connect to socket 'localabstract:com.mycompany.myapp-livesync': Connection refused
package.json
{
"nativescript": {
"id": "com.mycompany.myapp",
"tns-ios": {
"version": "5.4.2"
},
"tns-android": {
"version": "5.4.0"
}
},
"description": "My Mobile App",
"license": "SEE LICENSE IN <your-license-filename>",
"repository": "https://github.com/...",
"scripts": {
"lint": "tslint \"src/**/*.ts\"",
"clean": "find ./src -name '*.js' -delete",
"debug:android": "adb logcat *:W --pid=15820"
},
"dependencies": {
"@angular/animations": "8.0.0",
"@angular/common": "8.0.0",
"@angular/compiler": "8.0.0",
"@angular/core": "8.0.0",
"@angular/forms": "8.0.0",
"@angular/http": "8.0.0-beta.10",
"@angular/platform-browser": "8.0.0",
"@angular/platform-browser-dynamic": "8.0.0",
"@angular/router": "8.0.0",
"@ngxs/store": "^3.4.3",
"@turf/bearing": "^6.0.1",
"@turf/distance": "^6.0.1",
"nativescript-angular": "^8.0.0",
"nativescript-camera": "^4.5.0",
"nativescript-geolocation": "5.1.0",
"nativescript-google-maps-sdk": "2.7.0",
"nativescript-plugin-firebase": "^9.0.1",
"nativescript-social-share": "^1.5.2",
"nativescript-theme-core": "1.0.4",
"nativescript-urlhandler": "1.2.3",
"reflect-metadata": "0.1.13",
"rxjs": "6.5.2",
"tns-core-modules": "^5.4.3",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/compiler-cli": "8.0.0",
"@ngtools/webpack": "8.0.3",
"nativescript-dev-typescript": "^0.10.0",
"nativescript-dev-webpack": "0.24.1"
},
"readme": "My App"
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="__PACKAGE__"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="com.mycompany.myapp"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="My Mobile App"
android:theme="@style/AppTheme">
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
<meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/nativescript_google_maps_api_key" />
<activity
android:name="com.tns.NativeScriptActivity"
android:label="@string/title_activity_kimera"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/LaunchScreenTheme"
android:launchMode="singleTask">
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="veganbeacon" />
</intent-filter>
</activity>
<activity android:name="com.tns.ErrorReportActivity"/>
</application>
</manifest>
在 Android Studio 中查看 logcat 给了我一些额外的错误输出:
2019-06-30 07:58:56.785 10645-10645/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mycompany.myapp, PID: 10645
java.lang.RuntimeException: Unable to instantiate application com.mycompany.myapp: java.lang.ClassNotFoundException: Didn't find class "com.mycompany.myapp" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-rkxokotTtXOg1zrVZvRGdg==/base.apk"],nativeLibraryDirectories=[/data/app/com.mycompany.myapp-rkxokotTtXOg1zrVZvRGdg==/lib/x86, /data/app/com.mycompany.myapp-rkxokotTtXOg1zrVZvRGdg==/base.apk!/lib/x86, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:1069)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5842)
at android.app.ActivityThread.access00(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mycompany.myapp" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-rkxokotTtXOg1zrVZvRGdg==/base.apk"],nativeLibraryDirectories=[/data/app/com.mycompany.myapp-rkxokotTtXOg1zrVZvRGdg==/lib/x86, /data/app/com.mycompany.myapp-rkxokotTtXOg1zrVZvRGdg==/base.apk!/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:50)
at android.support.v4.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:49)
at android.app.Instrumentation.newApplication(Instrumentation.java:1120)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1061)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5842)
at android.app.ActivityThread.access00(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
我想你已经修改了
<application
android:name="com.tns.NativeScriptApplication"
至
<application
android:name="com.mycompany.myapp"
只有在扩展自己的 custom application class.
时才可以这样做
我正在创建一个 nativescript 应用程序,当我尝试在我的 android 设备(通过 USB 连接)上进行调试时,该应用程序打开启动画面并立即崩溃,控制台中没有显示任何错误。
我打开另一个终端并使用 adb logcat *:W --pid=15820
获取错误输出(警告及以上),我看到的只是连接失败。这些发生在应用程序崩溃后并每秒重复一次。我还能做些什么来找出我的应用崩溃的原因?它在 ios 模拟器上运行良好。
06-29 15:45:30.127 15820 15820 E adbd : failed to connect to socket 'localabstract:com.mycompany.myapp-livesync': Connection refused
06-29 15:45:31.136 15820 15820 E adbd : failed to connect to socket 'localabstract:com.mycompany.myapp-livesync': Connection refused
06-29 15:45:32.141 15820 15820 E adbd : failed to connect to socket 'localabstract:com.mycompany.myapp-livesync': Connection refused
package.json
{
"nativescript": {
"id": "com.mycompany.myapp",
"tns-ios": {
"version": "5.4.2"
},
"tns-android": {
"version": "5.4.0"
}
},
"description": "My Mobile App",
"license": "SEE LICENSE IN <your-license-filename>",
"repository": "https://github.com/...",
"scripts": {
"lint": "tslint \"src/**/*.ts\"",
"clean": "find ./src -name '*.js' -delete",
"debug:android": "adb logcat *:W --pid=15820"
},
"dependencies": {
"@angular/animations": "8.0.0",
"@angular/common": "8.0.0",
"@angular/compiler": "8.0.0",
"@angular/core": "8.0.0",
"@angular/forms": "8.0.0",
"@angular/http": "8.0.0-beta.10",
"@angular/platform-browser": "8.0.0",
"@angular/platform-browser-dynamic": "8.0.0",
"@angular/router": "8.0.0",
"@ngxs/store": "^3.4.3",
"@turf/bearing": "^6.0.1",
"@turf/distance": "^6.0.1",
"nativescript-angular": "^8.0.0",
"nativescript-camera": "^4.5.0",
"nativescript-geolocation": "5.1.0",
"nativescript-google-maps-sdk": "2.7.0",
"nativescript-plugin-firebase": "^9.0.1",
"nativescript-social-share": "^1.5.2",
"nativescript-theme-core": "1.0.4",
"nativescript-urlhandler": "1.2.3",
"reflect-metadata": "0.1.13",
"rxjs": "6.5.2",
"tns-core-modules": "^5.4.3",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/compiler-cli": "8.0.0",
"@ngtools/webpack": "8.0.3",
"nativescript-dev-typescript": "^0.10.0",
"nativescript-dev-webpack": "0.24.1"
},
"readme": "My App"
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="__PACKAGE__"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="com.mycompany.myapp"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="My Mobile App"
android:theme="@style/AppTheme">
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
<meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/nativescript_google_maps_api_key" />
<activity
android:name="com.tns.NativeScriptActivity"
android:label="@string/title_activity_kimera"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/LaunchScreenTheme"
android:launchMode="singleTask">
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="veganbeacon" />
</intent-filter>
</activity>
<activity android:name="com.tns.ErrorReportActivity"/>
</application>
</manifest>
在 Android Studio 中查看 logcat 给了我一些额外的错误输出:
2019-06-30 07:58:56.785 10645-10645/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mycompany.myapp, PID: 10645
java.lang.RuntimeException: Unable to instantiate application com.mycompany.myapp: java.lang.ClassNotFoundException: Didn't find class "com.mycompany.myapp" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-rkxokotTtXOg1zrVZvRGdg==/base.apk"],nativeLibraryDirectories=[/data/app/com.mycompany.myapp-rkxokotTtXOg1zrVZvRGdg==/lib/x86, /data/app/com.mycompany.myapp-rkxokotTtXOg1zrVZvRGdg==/base.apk!/lib/x86, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:1069)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5842)
at android.app.ActivityThread.access00(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mycompany.myapp" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-rkxokotTtXOg1zrVZvRGdg==/base.apk"],nativeLibraryDirectories=[/data/app/com.mycompany.myapp-rkxokotTtXOg1zrVZvRGdg==/lib/x86, /data/app/com.mycompany.myapp-rkxokotTtXOg1zrVZvRGdg==/base.apk!/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:50)
at android.support.v4.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:49)
at android.app.Instrumentation.newApplication(Instrumentation.java:1120)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1061)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5842)
at android.app.ActivityThread.access00(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
我想你已经修改了
<application
android:name="com.tns.NativeScriptApplication"
至
<application
android:name="com.mycompany.myapp"
只有在扩展自己的 custom application class.
时才可以这样做