How to Solve if application crashes on startup in Flutter

How to Solve if application crashes on startup in Flutter

While running the application on the emulator it just works fine, flutter build apk is successful, I can either release the new version on Google Play or just install the app on phone it crashes. So today, we will learn How to Solve if the application crashes on startup in Flutter.

How to Solve if the application crashes on startup in Flutter?

After following this guide on 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 are the same.

The 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 the below steps

By following the below steps you can solve this error.

Step 1.

  1. GO TO:—
project>[your_app_name]>Android [your_app_name]>app>src

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

go to each file separately and change the 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

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 sdk in the android/app/build.gradle file and it worked like a charm.

In the file build.gradle is the following:

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.

Sometimes it can be also solved by the below command

flutter clean

When you use 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"/>

iOS – within Info.plist

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

When we upgrade flutter has been this:

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

to

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

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 a unique one, using below command you get folder:

Google SHA

keytool -exportcert -list -v -alias foldername -keystore /directory

Conclusion:

Thanks for being with us on a Flutter Journey !!!

So in this article, we have been through So today, we will learn How to Solve if the application crashes on startup in Flutter.

Keep Learning !!! Keep Fluttering !!!

Still, need Support for Flutter Development? Do let us know.

Flutter Agency is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

Flutter Agency is one of the most popular online portals dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge on Flutter.

Abhishek Dhanani

Written by Abhishek Dhanani

Abhishek Dhanani, a skilled software developer with 3+ years of experience, masters Dart, JavaScript, TypeScript, and frameworks like Flutter and NodeJS. Proficient in MySQL, Firebase, and cloud platforms AWS and GCP, he delivers innovative digital solutions.

Leave a comment

Your email address will not be published. Required fields are marked *

Discuss Your Project

Connect with Flutter Agency's proficient skilled team for your app development projects across different technologies. We'd love to hear from you! Fill out the form below to discuss your project.

Have Project For Us

Get in Touch

"*" indicates required fields

ready to get started?

Fill out the form below and we will be in touch soon!

"*" indicates required fields