Repository: flutter
Issue: Flutter Android app “Unable to instantiate activity” (Pre-Launch crash report)
Labels: platform-android,tool,a: release,P2,c: fatal crash,team-android,triaged-android

I build my app as a "release" build (with signing and all) to publish it to PlayStore. I get a lot of crash reports from the "Pre-launch report" within PlayStore (see "actual results"). The build process, however, worked as expected without any failure. Also, the debug build and split-by-abi build is working without any problems or crashes. The deploy to PlayStore also does not cause any problems.

## Steps to Reproduce

This is the folder structure of the Android app (Originally I used another folder structure "app/main/kotlin/com/domain/MainActivity.kt" but with the same result):

[Link to Imgur for package structure](https://i.stack.imgur.com/jTFcD.png)

This is the `gradle.build` which is on the androids folder level:

```
    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')
    logger.info("DEBUG - FLUTTER ROOT: " + flutterRoot)
    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"
    
    buildscript {
        ext.kotlin_version = '1.3.50'
        repositories {
            google()
            jcenter()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:3.5.3'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath 'com.google.gms:google-services:4.3.3'
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
        }
    }
    
    rootProject.buildDir = '../build'
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
    }
    subprojects {
        project.evaluationDependsOn(':app')
    }
    
    /*
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    */
    
    def keystoreProperties = new Properties()
    def keystorePropertiesFile = rootProject.file('key.properties')
    if (keystorePropertiesFile.exists()) {
        keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
    }
    
    android {
        compileSdkVersion 28
        packagingOptions {
            exclude ("META-INF/shared_core_release.kotlin_module")
        }
        defaultConfig {
            applicationId "com.domain"
            minSdkVersion 25
            targetSdkVersion 28
            compileSdkVersion 28
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        signingConfigs {
            release {
                keyAlias keystoreProperties['keyAlias']
                keyPassword keystoreProperties['keyPassword']
                storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
                storePassword keystoreProperties['storePassword']
            }
        }
    
        buildTypes {
            release {
                minifyEnabled true
                signingConfig signingConfigs.release
                sourceSets {
    
                    main {
                        manifest.srcFile 'app/src/main/AndroidManifest.xml'
                        res.srcDirs = ['app/src/main/res']
                    }
                }
            }
        }
    }
    
    flutter {
        source '..'
    }
    
    dependencies {
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    }
```
    
And this is the referenced `AndroidManifest.xml`:

```
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="com.domain">
        <application
            android:name="io.flutter.app.FlutterApplication"
            android:label="App"
            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">
                <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>
        <!-- omitted -->
    </manifest>
```

This is the content of `app/src/main/kotlin/com.domain/MainActivity.kt`:

```
    package com.domain
    
    import androidx.annotation.NonNull;
    import io.flutter.embedding.android.FlutterActivity
    import io.flutter.embedding.engine.FlutterEngine
    import io.flutter.plugins.GeneratedPluginRegistrant
    
    class MainActivity: FlutterActivity() {
        override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
            GeneratedPluginRegistrant.registerWith(flutterEngine);
        }
    }

```

This is the excerpt from `flutter doctor`:

```
    [√] Flutter (Channel stable, v1.17.5, on Microsoft Windows [Version 10.0.18362.900], locale de-DE)
        • Flutter version 1.17.5 at C:\flutter
        • Framework revision 8af6b2f038 (9 days ago), 2020-06-30 12:53:55 -0700
        • Engine revision ee76268252
        • Dart version 2.8.4
    
    [!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
        • Android SDK at C:\Users\xxx\AppData\Local\Android\Sdk
        • Platform android-29, build-tools 29.0.3
        • ANDROID_HOME = C:\Users\xxx\AppData\Local\Android\Sdk
        • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
        X Android license status unknown.
          Try re-installing or updating your Android SDK Manager.
          See https://developer.android.com/studio/#downloads or visit visit
          https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions.
    
    [√] Android Studio (version 4.0)
        • Android Studio at C:\Program Files\Android\Android Studio
        • Flutter plugin version 46.0.2
        • Dart plugin version 193.7361
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    
    [√] IntelliJ IDEA Ultimate Edition (version 2019.3)
        • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.4
        • Flutter plugin version 44.0.3
        • Dart plugin version 193.6911.31
    
    [√] Connected device (1 available)
        • Android SDK built for x86 • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
```

The deployment to the PlayStore itself works without problems. I already looked into the AAB file (and the .dex file) but it's obfuscated. I already tried to build with `--no-shrink` and `--no-obfuscate` but this does not work for some reason

Any help would be highly welcome to resolve this problem.

**Expected results:** 
I like the app to run the pre-check without these errors.

**Actual results:**

```
    Crash java.lang.RuntimeException: Unable to instantiate activity 
    ComponentInfo{com.domain/com.domain.MainActivity}: java.lang.ClassNotFoundException: Didn't find 
    class "com.domain.MainActivity" on path: DexPathList[[zip file "/data/app/com.domain-1/base.apk", zip 
    file "/data/app/com.domain-1/split_config.arm64_v8a.apk", zip file "/data/app/com.domain- 
    1/split_config.xxhdpi.apk"],nativeLibraryDirectories=[/data/app/com.domain-1/lib/arm64, 
    /data/app/com.domain-1/base.apk!/lib/arm64-v8a, /data/app/com.domain- 
    1/split_config.arm64_v8a.apk!/lib/arm64-v8a, /data/app/com.domain- 
    1/split_config.xxhdpi.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
```