Qazi Muaaz
Qazi Muaaz

Reputation: 1

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.uow/com.example.uow.MainActivity}

App launches on both physical and virtual devices but only for a second, showing a blank white screen and then shows a dialog that xxx has stopped working.

using latest flutter and latest packages.

Debug console VS code with physical device:

Launching lib\main.dart on Nexus 6P in debug mode... Parameter format not correct - √ Built build\app\outputs\flutter-apk\app-debug.apk. E/AndroidRuntime(18660): FATAL EXCEPTION: main E/AndroidRuntime(18660): Process: com.example.uow, PID: 18660 E/AndroidRuntime(18660): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.uow/com.example.uow.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.uow.MainActivity" on path: DexPathList[[zip file "/data/app/~~qbQtrDUlPVDpUgF2_cqf1Q==/com.example.uow-zqtGS9vJh4yr2iNiXDdufQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~qbQtrDUlPVDpUgF2_cqf1Q==/com.example.uow-zqtGS9vJh4yr2iNiXDdufQ==/lib/arm64, /data/app/~~qbQtrDUlPVDpUgF2_cqf1Q==/com.example.uow-zqtGS9vJh4yr2iNiXDdufQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]] E/AndroidRuntime(18660): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3582) E/AndroidRuntime(18660): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3813) E/AndroidRuntime(18660): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) E/AndroidRuntime(18660): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) E/AndroidRuntime(18660): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) E/AndroidRuntime(18660): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2308) E/AndroidRuntime(18660): at android.os.Handler.dispatchMessage(Handler.java:106) E/AndroidRuntime(18660): at android.os.Looper.loopOnce(Looper.java:201) E/AndroidRuntime(18660): at android.os.Looper.loop(Looper.java:288) E/AndroidRuntime(18660): at android.app.ActivityThread.main(ActivityThread.java:7898) E/AndroidRuntime(18660): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(18660): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) E/AndroidRuntime(18660): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) E/AndroidRuntime(18660): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.uow.MainActivity" on path: DexPathList[[zip file "/data/app/~~qbQtrDUlPVDpUgF2_cqf1Q==/com.example.uow-zqtGS9vJh4yr2iNiXDdufQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~qbQtrDUlPVDpUgF2_cqf1Q==/com.example.uow-zqtGS9vJh4yr2iNiXDdufQ==/lib/arm64, /data/app/~~qbQtrDUlPVDpUgF2_cqf1Q==/com.example.uow-zqtGS9vJh4yr2iNiXDdufQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]] E/AndroidRuntime(18660): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) E/AndroidRuntime(18660): at java.lang.ClassLoader.loadClass(ClassLoader.java:379) E/AndroidRuntime(18660): at java.lang.ClassLoader.loadClass(ClassLoader.java:312) E/AndroidRuntime(18660): at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95) E/AndroidRuntime(18660): at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45) E/AndroidRuntime(18660): at android.app.Instrumentation.newActivity(Instrumentation.java:1328) E/AndroidRuntime(18660): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3569) E/AndroidRuntime(18660): ... 12 more Error waiting for a debug connection: The log reader stopped unexpectedly Error launching application on Nexus 6P. Exited (sigterm)

Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.uow">
  <!-- 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. -->
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  <application android:name="${applicationName}" android:label="uow" android:icon="@mipmap/ic_launcher">
    <meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_API_KEY"/>

    <activity android:name=".MainActivity" android:exported="true" 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>

app/build.gradle:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services' 

android {
    compileSdkVersion 33

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.uow"
        minSdkVersion 27
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
       
    }

    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
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-analytics'
    implementation platform('com.google.firebase:firebase-bom:31.1.0')
}

project build.gradle:

buildscript {
    ext.kotlin_version = '1.7.21'
    repositories {
        google()
        jcenter()
        mavenCentral()  // Maven Central repository
    }

    dependencies {
        classpath "com.android.tools.build:gradle:7.0.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.13'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()  // Maven Central repository
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

gradle.properties:

org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
org.gradle.java.home=C:\\Program Files\\Android\\Android Studio\\jre

gradle-wrapper-properties:

#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip

flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.3.8, on Microsoft Windows [Version 10.0.22621.819], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[√] Chrome - develop for the web
[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2021.3)
[√] VS Code (version 1.73.1)
[√] Connected device (4 available)
[√] HTTP Host Availability

! Doctor found issues in 1 category.

Upvotes: 0

Views: 376

Answers (1)

Qazi Muaaz
Qazi Muaaz

Reputation: 1

I fixed the issue by changing all the gradle related files to these ones I am sharing below. the issue seemed to be associated with the gradle version. Hope this helps.

build.gradle:

buildscript {
    ext.kotlin_version = '1.6.10'
    repositories {
        google()
        mavenCentral()  // Maven Central repository
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.1.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.13'
    }
}
allprojects {
    repositories {
        google()
        mavenCentral()  // Maven Central repository
    }
}
rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
    delete rootProject.buildDir
}


app level build.gradle:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android' 

android {
    compileSdkVersion 33

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.uow"
        minSdkVersion 27
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
       
    }

    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
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-analytics'
    implementation platform('com.google.firebase:firebase-bom:31.1.0')
     implementation("androidx.multidex:multidex:2.0.1")
}

gradle properties:


org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
org.gradle.java.home=C:\\Program Files\\Android\\Android Studio\\jre

gradle wrapper properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

androidmanifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.example.uow"
 xmlns:tools="http://schemas.android.com/tools">
  <!-- 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. -->
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  <application 
      android:name="${applicationName}" 
      android:label="uow" 
      android:icon="@mipmap/ic_launcher">


    <activity 
        android:name=".MainActivity" 
        android:exported="true" 
        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.NormalTheme" 
          android:resource="@style/NormalTheme" />
      <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>


main activity:



package com.example.uow

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}

Upvotes: 0

Related Questions