Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart/ flutter: application crashes on startup

Tags:

flutter

dart

I have this very interesting issue, where I can run my application on the emulator just fine, flutter build apk is successful, I can either release the new version on Google Play or just install the apk on my phone (Pixel 2 XL, currently on April security patch).

But when I launch it on my phone, it instantly crashes. I haven't tried installing the debug apk yet, first I want to apply the May patch.

I already tried upgrading flutter several times, but doesn't seem to be any issue there either:

C:\Android\osszefogasaszanhuzokert>flutter upgrade
Upgrading Flutter from c:\Android\flutter...
From https://github.com/flutter/flutter
   3d3673a34..23098dde5  master     -> origin/master
Already up to date.

Upgrading engine...
Already up-to-date.

Flutter 0.3.6-pre.81 • channel beta • https://github.com/flutter/flutter.git
Framework • revision 2849bc04ff (10 days ago) • 2018-05-01 20:07:45 -0700
Engine • revision d5c1117170
Tools • Dart 2.0.0-dev.52.0.flutter-011676641a

Running "flutter packages upgrade" in osszefogasaszanhuzokert... 14.4s

Running flutter doctor...
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.3.6-pre.81, on Microsoft Windows [Version 10.0.15063], locale en-GB)
[√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[√] Android Studio (version 3.1)
[√] Connected devices (1 available)

• No issues found!

I recently switched laptops and checked out the git repository of my code on this new one. There were some problems, but I eventually fixed those. The only difference is that that the project name now is simply osszefogasaszanhuzokert, while the package name is osszefogasaszanhuzokert2 - but I don't think this should cause any problem.

My guess is that the problem will lie somewhere in my AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.zgyorkei.osszefogasaszanhuzokert2">

    <!-- The INTERNET permission is required for development. Specifically,
         flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET"/>

    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="Összefogás A Szánhúzókért"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name="com.zgyorkei.osszefogasaszanhuzokert2.MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

Android studio marks several attributes as not allowed, but as you can see I pretty much left everything as default - except I changed the android:label for obvious reasons.

EDIT: I installed the debug apk and it runs perfectly. However, I was able to get adb logcat of the crash of the release apk, and the problem seems to be the following:

05-12 07:38:23.341 29595 29595 I crash_dump32: performing dump of process 29560 (target tid = 29560)
05-12 07:38:23.341 29595 29595 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
05-12 07:38:23.341 29595 29595 F DEBUG   : Build fingerprint: 'google/taimen/taimen:8.1.0/OPM2.171019.029.B1/4720900:user/release-keys'
05-12 07:38:23.341 29595 29595 F DEBUG   : Revision: 'rev_10'
05-12 07:38:23.341 29595 29595 F DEBUG   : ABI: 'arm'
05-12 07:38:23.341 29595 29595 F DEBUG   : pid: 29560, tid: 29560, name: saszanhuzokert2  >>> com.zgyorkei.osszefogasaszanhuzokert2 <<<
05-12 07:38:23.342 29595 29595 F DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
05-12 07:38:23.343 29595 29595 F DEBUG   : Abort message: '[FATAL:flutter/runtime/dart_vm.cc(409)] Error while initializing the Dart VM: Snapshot not compatible with the current VM configuration: the snapshot requires 'product no-type_checks no-asserts no-error_on_bad_type no-error_on_bad_override arm-eabi hardfp' but the VM has 'product no-type_checks no-asserts no-error_on_bad_type no-error_on_bad_override arm-eabi softfp'

How could I change the Dart VM to use hardfp instead of softfp?

like image 852
Zoltán Györkei Avatar asked May 11 '18 17:05

Zoltán Györkei


4 Answers

I had the same issue. For me this happened after I renamed my app and changed the package name. I did not do this properly for android.

After following this guide of how to change the package name, things worked fine for android.

Make sure the package name in AndroidManifest.xml and android/app/build.gradle and android/app/src/.../MainActivity.java is the same. Also check ios/Runner/Info.plist the value of CFBundleName for iOS versions.

like image 80
Lebohang Mbele Avatar answered Nov 17 '22 02:11

Lebohang Mbele


This is not direct answer to this question but I had similar problem and end up here. Others can come too.

MY PROBLEM: app crashes on first launch on emulator

MY SOLUTION: clear cache by running flutter clean

like image 35
temirbek Avatar answered Nov 17 '22 01:11

temirbek


Simplest way to solve this error

This error happens when you change your package name

In order to change your package name in a proper way you have to follow below steps

By following below steps you can solve this error

step-1:-

1.GO TO :---

project>[your_app_name]>Android [your_app_name]>app>src

In src folder you can find 3 files Debug,main & profile

go to each file separately and change package name of their AndroidManifest.xml files

Now,you are half away from solving this error.

Step-2:-

Now , go to build.gradle file located in

project>[your_app_name]>Android [your_app_name]>app>build.gradle

here you can find this code defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.appname" minSdkVersion 16 targetSdkVersion 29 versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" }

just change package name com.example.appname to your suitable package name

Step-3:-

Now go to

project>[your_app_name]>Android [your_app_name]>app>src>main>java>mainactivity

***Caution****** if you are using Kotlin with flutter then you have to go here:--

project>[your_app_name]>Android [your_app_name]>app>src>main>kotlin>mainactivity

You can change the package name of your app After going to Mainactivity.kotlin or mainactivity.java

It should work perfectly...Please provide feedback to this.

ALSO DON'T FORGET TO CHANGE PACKAGE NAME OF THE FOLDER [Go to src>main>kotlin or java>com.example.app]

like image 22
raman raman Avatar answered Nov 17 '22 03:11

raman raman


Had the same issue with some phones with different architecture. The app started crashing when I open it. Here is a fix that worked for me:

defaultConfig {
    ...
    multiDexEnabled true
    ndk {
        abiFilters 'x86', 'armeabi-v7a'
    }
}

Had to add ndk in android/app/build.gradle file and it worked like a charm.

I hope this can help someone.

like image 11
Satish Saini Avatar answered Nov 17 '22 01:11

Satish Saini