46

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?

Zoltán Györkei
  • 1,025
  • 5
  • 13
  • 21
  • 2
    adb logcat, see what is printed when the device crashes - this may require a debug build – Jonah Williams May 11 '18 at 22:29
  • Thanks for the tip. The debug apk works on the phone just as I want to, but when I pulled adb logcat of the release apk, the carsh report (added to the question) shows that the Dart VM uses softfp instead of hardfp. As much as I could understand, this is some architectural level stuff and it might be a bug of the Dart VM. Or is there anything I should change in my build.gradle or AndroidManifest.xml to force the use of hardfp? – Zoltán Györkei May 12 '18 at 05:48
  • 1
    Ahh, probably https://github.com/flutter/flutter/issues/17387. Should be fixed by now if you switch to master – Jonah Williams May 12 '18 at 05:59
  • Yes, that was the problem. Thank you! ;) – Zoltán Györkei May 12 '18 at 06:17
  • 1
    I have the same problem especially with firebase plugins .I think the problem lies within what version of flutter you are using and what the firebase plugins uses – griffins Jul 28 '19 at 17:07
  • In my case I had a splashscreen. Removing the splashscreen worked for me – CodedRomero Nov 02 '20 at 11:45

21 Answers21

72

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.

Jorge Luis
  • 902
  • 12
  • 25
Lebohang Mbele
  • 3,321
  • 1
  • 15
  • 20
  • This might not be the correct answer for OP but it did help me out. I changed my package name and forgot to edit the MainActivity one as well. – Amine Aug 31 '19 at 17:38
  • 1
    Is this the same for Kotlin designed Flutter apps? – MaylorTaylor Oct 23 '19 at 04:10
  • 4
    Missed renaming the package in android/app/src/.../MainActivity.kt Thank you! – Dylan Moore Mar 11 '20 at 16:42
  • This is not the right reply for this question, but fixed my build! Should you repost this as a Question and Answer on a separated topic? – mikegross May 20 '20 at 13:02
  • 1
    For Flutter Apps you also need to change MainActivity.kt as well as all the others mentioned above. I had already changed all the above, only to find my app also starting and crashing until that was done. – Rob Mascaro Jun 25 '20 at 01:38
  • This fixed my problem – Demian S Aug 24 '20 at 17:09
  • i have this problem and after many research i decide that create new project from main project and after test i find that a svg file was spoiled and after delete it my problem solved – mohammad shabani Sep 09 '20 at 22:50
35

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

Ian
  • 33,605
  • 26
  • 118
  • 198
temirbek
  • 1,415
  • 1
  • 14
  • 27
23

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]

raman raman
  • 1,655
  • 4
  • 22
  • 34
11

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.

Satish Saini
  • 2,880
  • 3
  • 24
  • 38
  • 1
    not sure if it was multidex or ndk, but this fixed it for me. – maddesa Jun 03 '19 at 01:07
  • 1
    Just a heads up: When I added this to my `app/build.gradle`, and tried to build an app bundle (`flutter build appbundle`), it stripped every architecture from the appbundle except 1. I'm not sure of the fix, but beware when using this and deploying with appbundles – Luciano Feb 08 '20 at 05:54
8

I had the same problem and none of the options here helped me. Finally, I found about logcat and realised my app was crashing because of Crashlytics package.

In short, I ran the below command in terminal to show logs from the device which helped me not only find the culprit but how to resolve the issue. You can leave it running in background.

adb logcat

You might have to add below path to you path environment variables. Or just cd to it.

C:\Users\[USERNAME]\AppData\Local\Android\sdk\platform-tools

See the output below. I am sure if this happens again because of whatever reason, I should be able to figure out why instead of speculating what caused it.

enter image description here

ravish.hacker
  • 1,189
  • 14
  • 21
4

In my case, I only had to run:

flutter build apk --release --no-shrink
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Steve
  • 914
  • 8
  • 17
  • related to this, I noticed the flag android.enableR8 was created as true in android/gradle.properties when building, I set it to false too. Always when deleted was created again as true. – Randolfo Sep 24 '20 at 09:57
  • or `flutter build apk --debug-- no-shrink` in case you don't want the release one – loonix Nov 10 '20 at 15:06
3

Here is the solution:

In the file build.gradle are the follow:

buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
     //       signingConfig signingConfigs.debug
            // colocado isso para release
            signingConfig signingConfigs.release

            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

just change minifyEnabled and useProguard to false and run flutter build again.

3

The reason it was crashing me was because of a third-party library on startup. To check which library is causing the crash, look at the logs using Logcat by going to View > Tool Windows > Logcat on Android Studio. Then, restart the app and inspect the output. For me, it was Firebase Auth library which was causing the crash. I just updated that library to love my problem. I hope this helps someone. If not, "Stay calm, and keep reading, you will find it eventually".

Harsh Verma
  • 529
  • 6
  • 10
3

I faced the same behavior (the app just closes on launch without any errors or warning, etc) and resolved it by using command:

flutter clean

That's happened to me when I haven't relaunch the app on the simulator for a while (a few months). And I guess related to some Flutter updates / etc.

atereshkov
  • 4,311
  • 1
  • 38
  • 49
3

For me it was because I used admob and forgot to add the APPLICATION_ID to AndroidManifest.xml

<meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="app-id"/>
Morad
  • 2,761
  • 21
  • 29
2

On the Terminal, I used:

flutter pub upgrade
Nimantha
  • 6,405
  • 6
  • 28
  • 69
KDC
  • 591
  • 1
  • 10
  • 26
2

While working on flutter at android studio : I had the same issue , but finally I concluded that when you add new dependency on the file called pubspec.yaml located at your app "root directory" and that dependency is not configured in the correct way such as {{flutter_facebook_login: ^1.2.0}} so if you need it so configure it at the right way or do not use it at all. ^_^ Have a good day at android studio

1

I was facing same issue after flutter upgrade.

In my app, multiDexEnabled true was enabled in build.gradle file and it was working fine before the upgrade. I had added it earlier to fix another crash.

See this for the same: Flutter android app crashes upon startup if I include a certain package

Kon
  • 4,023
  • 4
  • 24
  • 38
Keerti Purswani
  • 4,878
  • 3
  • 16
  • 29
1

After a day I resolved, no advice above was helpful because I had already tried them all. Among which :

  • flutter clean
  • flutter upgrade
  • check if packages is the same in the gradle and manifests
  • multiDexEnable true
  • and other solutions...

In my case the solution when i upgrade flutter has been this:

  classpath 'com.android.tools.build:gradle:3.3.1'

to

  classpath 'com.android.tools.build:gradle:3.3.2'

That's right, it was enough to update the tools gradle. Infact the project compiled without errors and started the app. But when the app started it closed by itself without any error message. So be careful of the gradle. I hope with this you will save hours of stress.

AlexPad
  • 10,364
  • 3
  • 38
  • 48
1

In android\build.gradle

classpath 'com.android.tools.build:gradle:3.5.0'

In combination with the new released Gradle 6.6, so at gradle\wrapper\gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Miguel Chavez
  • 161
  • 1
  • 2
  • 14
0

For those who've done a refactor/changed package name using Kotlin and none of the above worked (my case), check this: make sure that in your app/src/main directory there is a MainActivity file in BOTH the app/src/main/java and the app/src/main/kotlin directories. For me, there was no file in the java folder and this caused the crash (and of course make sure you've done all the above as well).

Oprimus
  • 1,652
  • 3
  • 11
  • 20
  • how did you fixed it? how did you add the MainActivity.java ? im facing this error and none of the above works – KDC Jan 14 '20 at 00:28
0

The problem I faced was due to "firebase_crashlytics" not being installed correctly.

Basically the entries in [project]/android/build.gradle and [project]/android/build.gradle were not updated correctly in my case which simply crashed the app without any details in any of the logs.

Then I redid all the steps in "ReadMe" section of the plugin and it worked fine.

https://pub.dev/packages/firebase_crashlytics

Basically, when you face app crash error without any logs to help you, ensure you check your newly added plugins and that you have installed them correctly.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
dj079
  • 1,389
  • 8
  • 14
0

As Morad mentioned, not referencing AdMob correctly will cause your app to crash on launch and may not even give a clue about the crash. This is true for both iOS and Android.

Android - within AndroidManifest.xml

<meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="your-app-id"/>

iOS - within Info.plist

    <key>GADApplicationIdentifier</key>
    <string>your-app-id</string>

Follow the instructions here: https://pub.dev/packages/firebase_admob

If you don't know your App ID, you can find it at https://admob.google.com and on the left click "Apps" and then "View All Apps" (as long as you set up your ads already).

Sludge
  • 6,072
  • 5
  • 31
  • 43
0

In my case, the issue was that I was using Android studio version 3.6.1 with gradle-wrapper.properties distribution version 6.0.0-all. To resolve this, I have changed it to 4.10.1-all .

vids
  • 381
  • 3
  • 5
0

Open android studio, get SHA keys from gradle and update the key in google console, upload your google JSON list in your project, make sure your SHA key should be unique one, using below command you get folder:

Google SHA

keytool -exportcert -list -v -alias foldername -keystore /directory
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
0

From here: https://stackoverflow.com/a/69234372/487812

This is an issue with latest Flutter version , I fixed it with the below eidt ,

This is a workaround and it works for me .

  1. go to MainActivity.kt
  2. Import import android.os.Build
  3. Paste this override fun onFlutterUiDisplayed() { if (Build.VERSION.SDK_INT >= 100) { //I gave 100 just to confirm , it shoud be android ver 10 reportFullyDrawn(); } }
  4. flutter clean
  5. flutter run
the_new_mr
  • 3,476
  • 5
  • 42
  • 57