nativescriptnativescript-angularnativescript-firebase

Nativescript Android keeps crashing


I am creating a nativescript application and when I try to debug on my android device (connected via usb) the app opens the splash screen and immediately crashes without any errors shown in the console. I open another terminal and use adb logcat *:W --pid=15820 to get error output (warnings and above) and all I see is failures to connect. These occur after the app crashes and keep repeating every second. What else can I do to find out why my app is crashing? It runs fine on an ios emulator.

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>

Looking through logcat in Android Studio gave me some addition error output:

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.access$1100(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.access$1100(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) 

Solution

  • I think you had modified

    <application
            android:name="com.tns.NativeScriptApplication"
    

    to

    <application
            android:name="com.mycompany.myapp"
    

    You may do it only if you are extending your own custom application class.