'Flutter Unable to instantiate activity ComponentInfo Main Activity
I'm using vs code (to code) and android studio (to get virtual device). I just merged and pulled the project I'm working on this morning, and first, have a very long time to wait to build my project. So i stopped all, uninstalled my app from my virtual device, then cleaned and run by "flutter run". Now I have these errors:
Using hardware rendering with device AOSP on IA Emulator. If you notice graphics artifacts, consider enabling software rendering with
"--enable-software-rendering".
Launching lib\main.dart on AOSP on IA Emulator in debug mode...
Running Gradle task 'assembleDebug'... 6,0s
√ Built build\app\outputs\flutter-apk\app-debug.apk.
E/AndroidRuntime(11190): FATAL EXCEPTION: main
E/AndroidRuntime(11190): Process: com.example.coming_soon, PID: 11190
E/AndroidRuntime(11190): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.coming_soon/com.example.coming_soon.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.coming_soon.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.coming_soon-g9Xk6gs-AdO4Khd-H_dR3g==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.coming_soon-g9Xk6gs-AdO4Khd-H_dR3g==/lib/x86, /data/app/com.example.coming_soon-g9Xk6gs-AdO4Khd-H_dR3g==/base.apk!/lib/x86, /system/lib]]
E/AndroidRuntime(11190): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2843)
E/AndroidRuntime(11190): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
E/AndroidRuntime(11190): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
E/AndroidRuntime(11190): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
E/AndroidRuntime(11190): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
E/AndroidRuntime(11190): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
E/AndroidRuntime(11190): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(11190): at android.os.Looper.loop(Looper.java:193)
E/AndroidRuntime(11190): at android.app.ActivityThread.main(ActivityThread.java:6669)
E/AndroidRuntime(11190): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(11190): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime(11190): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/AndroidRuntime(11190): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.coming_soon.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.coming_soon-g9Xk6gs-AdO4Khd-H_dR3g==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.coming_soon-g9Xk6gs-AdO4Khd-H_dR3g==/lib/x86, /data/app/com.example.coming_soon-g9Xk6gs-AdO4Khd-H_dR3g==/base.apk!/lib/x86, /system/lib]]
E/AndroidRuntime(11190): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
E/AndroidRuntime(11190): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime(11190): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime(11190): at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:69)
E/AndroidRuntime(11190): at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:41)
E/AndroidRuntime(11190): at android.app.Instrumentation.newActivity(Instrumentation.java:1215)
E/AndroidRuntime(11190): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2831)
E/AndroidRuntime(11190): ... 11 more
Here is my flutter doctor -v
[√] Flutter (Channel stable, 2.5.3, on Microsoft Windows [version 10.0.19043.1348], locale fr-FR)
• Flutter version 2.5.3 at C:\Users\Johanne\Development\sdks\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 18116933e7 (5 weeks ago), 2021-10-15 10:46:35 -0700
• Engine revision d3ea636dc5
• Dart version 2.14.4
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at C:\Users\Johanne\AppData\Local\Android\sdk
• Platform android-31, build-tools 31.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 2020.3)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
[√] VS Code (version 1.62.2)
• VS Code at C:\Users\Johanne\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.28.0
[√] Connected device (3 available)
• AOSP on IA Emulator (mobile) • emulator-5556 • android-x86 • Android 9 (API 28) (emulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 95.0.4638.69
• Edge (web) • edge • web-javascript • Microsoft Edge 95.0.1020.44
• No issues found!
Here is my android.manifest :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.coming_soon">
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:label="coming_soon"
android:icon="@mipmap/ic_launcher">
<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>
</manifest>
I already searched and found similar issues, but I wasn't able to solve my problem. I tried to create a MainActivity.java file, but got new errors, so I deleted it. Did I miss something?
Solution 1:[1]
For me, the solution was to simply run flutter clean
and flutter pub get
in the project directory.
Solution 2:[2]
For me the solution was to fix the name of the package in MainActivity.kt for some reason the last part was doubled.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Miki VanouĊĦek |
Solution 2 | Nicolas Thomas |