When I run the app on android emulator the app builds and it also installs but the wierd thing is that it installs two instances of same app and then crashes with this error :
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.guru_bot_app.es/com.guru_bot_app.es.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.guru_bot_app.es.MainActivity" on path: DexPathList[[zip file "/data/app/~~4QzHj9LJNWyBLf_LM9bcJg==/com.guru_bot_app.es-PPq2q8fJVWEq6JY8ZQe_mg==/base.apk"],nativeLibraryDirectories=[/data/app/~~4QzHj9LJNWyBLf_LM9bcJg==/com.guru_bot_app.es-PPq2q8fJVWEq6JY8ZQe_mg==/lib/arm64, /data/app/~~4QzHj9LJNWyBLf_LM9bcJg==/com.guru_bot_app.es-PPq2q8fJVWEq6JY8ZQe_mg==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
My android>build.gradle :
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// classpath 'com.google.gms:google-services:4.3.13'
// implementation 'com.google.apis:google-api-services-people:v1-rev20210903-1.32.1'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
My android>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 plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
namespace "com.guru_bot_app.es"
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.guru_bot_app.es"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
signingConfigs {
release {
storeFile file('../../../../keystore/keystore.jks')
storePassword 'notrealpassword'
keyAlias 'key'
keyPassword 'notrealpassword'
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
My AndroidManifest.xml file :
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="guru_bot_app"
android:name="${applicationName}"
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"
/>
<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 have tried a lot of things but nothing is working. I have tried invalidate cache and restart. Flutter clean and then build. Change emulator but nothing is solving this issue.
I am mostly preplexed for why its installing two instances of same app.