title: Flutter app crashes on start when applying fire base ( java.lang.RuntimeException: Unable to instantiate activity)
body: <p>I had started a new  project in flutter and i was applying fire store to it.</p>
  
  <p>On following the steps to add my app to fire base it started to give error.</p>
  
  <p>The error found in log cat when started app was</p>
  
  <pre><code>04-04 14:54:56.061 24084-24084/? E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.firestoreflutterchat, PID: 24084
      java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.example.firestoreflutterchat-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.firestoreflutterchat-2, /vendor/lib, /system/lib]]
          at android.app.ActivityThread.installProvider(ActivityThread.java:4869)
          at android.app.ActivityThread.installContentProviders(ActivityThread.java:4461)
          at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4401)
          at android.app.ActivityThread.access$1500(ActivityThread.java:139)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:136)
          at android.app.ActivityThread.main(ActivityThread.java:5097)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:515)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
          at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.example.firestoreflutterchat-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.firestoreflutterchat-2, /vendor/lib, /system/lib]]
          at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
          at android.app.ActivityThread.installProvider(ActivityThread.java:4854)
          at android.app.ActivityThread.installContentProviders(ActivityThread.java:4461) 
          at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4401) 
          at android.app.ActivityThread.access$1500(ActivityThread.java:139) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270) 
          at android.os.Handler.dispatchMessage(Handler.java:102) 
          at android.os.Looper.loop(Looper.java:136) 
          at android.app.ActivityThread.main(ActivityThread.java:5097) 
          at java.lang.reflect.Method.invokeNative(Native Method) 
          at java.lang.reflect.Method.invoke(Method.java:515) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
          at dalvik.system.NativeStart.main(Native Method
  </code></pre>
  
  <p>The app i am running on kit kat version device Xt1030</p>
  
  <p>to remove this error i did some things in gradle and mostly described by others was multidex</p>
  
  <p>so this is my gradle files :</p>
  
  <pre><code>buildscript {
      ext.kotlin_version = '1.3.50'
      repositories {
          google()
          mavenCentral()
        //  maven { url 'https://github.com/yongjhih/android-gradle-plugin.m2/raw/master/' }
          jcenter()
  
      }
  
      dependencies {
          classpath 'com.android.tools.build:gradle:3.6.1'
          classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
          // Add this line
  
         // classpath 'com.google.gms:google-services:3.2.1'
          classpath 'com.google.gms:google-services:4.2.0'
          //com.google.android.gms to 11.4.2.
      }
  }
  
  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
  }
  </code></pre>
  
  <p>and gradle app:</p>
  
  <pre><code>def localProperties = new Properties()
  def localPropertiesFile = rootProject.file('local.properties')
  if (localPropertiesFile.exists()) {
      localPropertiesFile.withReader('UTF-8') { reader -&gt;
          localProperties.load(reader)
      }
  }
  
  def flutterRoot = localProperties.getProperty('flutter.sdk')
  if (flutterRoot == null) {
      throw new FileNotFoundException("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 plugin: 'kotlin-android'
  // Add this line
  apply plugin: 'com.google.gms.google-services'
  apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
  
  android {
      compileSdkVersion 28
  
  //    compileOptions {
  //        sourceCompatibility JavaVersion.VERSION
  //        targetCompatibility JavaVersion.VERSION 8
  //    }
      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.firestoreflutterchat"
          minSdkVersion 18
          targetSdkVersion 28
          versionCode flutterVersionCode.toInteger()
          versionName flutterVersionName
    //      testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  //        ndk {
  //            abiFilters 'armeabi-v7a'
  //        }
          multiDexEnabled true
  
  
  
  //        productFlavors {
  //            dev {
  //                // Enable pre-dexing to produce an APK that can be tested on
  //                // Android 5.0+ without the time-consuming DEX build processes.
  //                minSdkVersion 21
  //                flavorDimensions "versionCode"
  //            }
  //            prod {
  //                // The actual minSdkVersion for the production version.
  //                minSdkVersion 18
  //                flavorDimensions "versionCode"
  //            }
  //        }
  
      }
  
      buildTypes {
          release {
              multiDexKeepFile file('multidex-config.txt')
  
              // 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 {
      // add the Firebase SDK for Google Analytics
      implementation 'com.google.firebase:firebase-analytics:17.2.2'
      implementation 'androidx.multidex:multidex:2.0.0'
      implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
  }
  </code></pre>
  
  <p>And in manifest file it was told to change name :</p>
  
  <pre><code>android:name="io.flutter.app.FlutterApplication"
  </code></pre>
  
  <p>to </p>
  
  <pre><code>android:name="androidx.multidex.MultiDexApplication"
  </code></pre>
  
  <p>or on another way of doing this</p>
  
  <p>To add a class that extends flutter application</p>
  
  <p>which on performing</p>
  
  <pre><code>package com.example.firestoreflutterchat
  
      import android.content.Context
      import androidx.multidex.MultiDex
      import io.flutter.app.FlutterApplication
  
  
      class App : FlutterApplication() {
  
          override fun attachBaseContext(base: Context?) {
              super.attachBaseContext(base)
              MultiDex.install(this)
          }
      }
  </code></pre>
  
  <p>and then changing Android manifest from </p>
  
  <pre><code>android:name="io.flutter.app.FlutterApplication"
  </code></pre>
  
  <p>to </p>
  
  <pre><code>android:name=".App"
  </code></pre>
  
  <p>Now after doing all these still my app crash but with different error</p>
  
  <pre><code>04-05 18:22:18.266 10645-10645/com.example.firestoreflutterchat E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.firestoreflutterchat, PID: 10645
      java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.firestoreflutterchat/com.example.firestoreflutterchat.MainActivity}: java.lang.ClassCastException: com.example.firestoreflutterchat.MainActivity cannot be cast to android.app.Activity
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2124)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
          at android.app.ActivityThread.access$800(ActivityThread.java:139)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:136)
          at android.app.ActivityThread.main(ActivityThread.java:5097)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:515)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
          at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.ClassCastException: com.example.firestoreflutterchat.MainActivity cannot be cast to android.app.Activity
          at android.app.Instrumentation.newActivity(Instrumentation.java:1084)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2115)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257) 
          at android.app.ActivityThread.access$800(ActivityThread.java:139) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210) 
          at android.os.Handler.dispatchMessage(Handler.java:102) 
          at android.os.Looper.loop(Looper.java:136) 
          at android.app.ActivityThread.main(ActivityThread.java:5097) 
          at java.lang.reflect.Method.invokeNative(Native Method) 
          at java.lang.reflect.Method.invoke(Method.java:515) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
          at dalvik.system.NativeStart.main(Native Method) 
  </code></pre>