Flutter: How to Fix Java. Lang. Runtimeexception: Unable to Instantiate Application

I developed two mobile apps simultaneously on last year (finished beta around September) using Flutter. Right now we are on the verge of releasing the apps. However, as of today only one of the two apps can run on Android, despite being almost clones.

The exception happens after I build the app, when it is installed on the device (both physical and emulator have been tested).

I get the following exception, however I do not now how to handle it.

E/AndroidRuntime(19942): FATAL EXCEPTION: main
E/AndroidRuntime(19942): Process: co.gaiostudios.doctor_pro_app, PID: 19942
E/AndroidRuntime(19942): java.lang.RuntimeException: Unable to instantiate application co.gaiostudios.doctor_pro_app.Application: java.lang.ClassNotFoundException: Didn't find class "co.gaiostudios.doctor_pro_app.Application" on path: DexPathList[[zip file "/data/app/~~1dsMLb7FTFTVdMbbaoYBBQ==/co.gaiostudios.doctor_pro_app-QQpEwzuef3pNrcFJBbTdBQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~1dsMLb7FTFTVdMbbaoYBBQ==/co.gaiostudios.doctor_pro_app-QQpEwzuef3pNrcFJBbTdBQ==/lib/x86, /data/app/~~1dsMLb7FTFTVdMbbaoYBBQ==/co.gaiostudios.doctor_pro_app-QQpEwzuef3pNrcFJBbTdBQ==/base.apk!/lib/x86, /system/lib, /system_ext/lib]]
E/AndroidRuntime(19942):    at android.app.LoadedApk.makeApplication(LoadedApk.java:1244)
E/AndroidRuntime(19942):    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6683)
E/AndroidRuntime(19942):    at android.app.ActivityThread.access$1300(ActivityThread.java:237)
E/AndroidRuntime(19942):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
E/AndroidRuntime(19942):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(19942):    at android.os.Looper.loop(Looper.java:223)
E/AndroidRuntime(19942):    at android.app.ActivityThread.main(ActivityThread.java:7656)
E/AndroidRuntime(19942):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(19942):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/AndroidRuntime(19942):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/AndroidRuntime(19942): Caused by: java.lang.ClassNotFoundException: Didn't find class "co.gaiostudios.doctor_pro_app.Application" on path: DexPathList[[zip file "/data/app/~~1dsMLb7FTFTVdMbbaoYBBQ==/co.gaiostudios.doctor_pro_app-QQpEwzuef3pNrcFJBbTdBQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~1dsMLb7FTFTVdMbbaoYBBQ==/co.gaiostudios.doctor_pro_app-QQpEwzuef3pNrcFJBbTdBQ==/lib/x86, /data/app/~~1dsMLb7FTFTVdMbbaoYBBQ==/co.gaiostudios.doctor_pro_app-QQpEwzuef3pNrcFJBbTdBQ==/base.apk!/lib/x86, /system/lib, /system_ext/lib]]
E/AndroidRuntime(19942):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
E/AndroidRuntime(19942):    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime(19942):    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime(19942):    at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
E/AndroidRuntime(19942):    at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
E/AndroidRuntime(19942):    at android.app.Instrumentation.newApplication(Instrumentation.java:1158)
E/AndroidRuntime(19942):    at android.app.LoadedApk.makeApplication(LoadedApk.java:1236)
3

1 Answer

I believe there could be multiple root causes. For me it was due to old configurations for previous firebase versions in build.gradle and AndroidManifest.xml files. I generally tried to rebuild these files to the state of a new flutter project and just added the configurations that are required in the current FlutterFire configs for Android.

The key to get passed this error message was to remove in AndroidManifest.xml <application android:name=".Application"

delete the Application.kt file (that was previously required)

and leave

<activity
            android:name=".MainActivity"

This needs to be done for both AndroidManifest.xml files in main and debug folders!

My new AndroidManifest.xml now looks like this:

<manifest xmlns:android=""
package="com.yourproject">
<application
    android:label="Your App Name"
    android:icon="@mipmap/launcher_icon">
    <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
        <!-- Specifies an Android theme to apply to this Activity as soon as
             the Android process has started. This theme is visible to the user
             while the Flutter UI initializes. After that, this theme continues
             to determine the Window background behind the Flutter UI. -->
        <meta-data
          android:name="io.flutter.embedding.android.NormalTheme"
          android:resource="@style/NormalTheme"
          />
        <!-- Displays an Android View that continues showing the launch screen
             Drawable until Flutter paints its first frame, then this splash
             screen fades out. A splash screen is useful to avoid any visual
             gap between the end of Android's launch screen and the painting of
             Flutter's first frame. -->
        <meta-data
          android:name="io.flutter.embedding.android.SplashScreenDrawable"
          android:resource="@drawable/launch_background"
          />
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <!-- Don't delete the meta-data below.
         This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />
</application>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest