Reputation: 34507
Hi I am developing app in flutter. When I am trying to build flutter then I am getting an error Unable to merge dex
.
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.")
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 27
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.xyz"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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-jre7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.google.firebase:firebase-core:16.0.0'
}
apply plugin: 'com.google.gms.google-services'
buildscript {
ext.kotlin_version = '1.1.51'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.0.0'
}
}
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
}
Does anyone know how to resolve it in flutter ?
Upvotes: 0
Views: 667
Reputation: 1002
Following this link solved a very similar issue for me.
** I did not not have to set multiDexEnabled to true
First I set dependencies in my pubspec.yaml to
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.8.2
and ran flutter packages get
in my IDE's terminal.
Also I had to change the minimum target SDK version:
This alone may fix your problem; however I had to also do the following because some of my dependency versions were mismatched.
I had to open android/app/build.gradle
, then add the following line as the last line in the file:
apply plugin: 'com.google.gms.google-services'
Next, I had to open android/build.gradle
, then inside the buildscript tag, add a new dependency:
buildscript {
repositories {
// ...
}
dependencies {
// ...
classpath 'com.google.gms:google-services:3.2.1' // new
}
}
After this my app finally ran on the android emulator.
The link has a more complete walkthrough if you get stuck.
Upvotes: 0
Reputation: 176
take this steps :
flutter clean
flutter build
or run using flutter run
.i hope this will help .
Upvotes: 0
Reputation: 445
Try adding this in app build.gradle
android {
defaultConfig {
multiDexEnabled true
}
}
change
classpath 'com.google.gms:google-services:4.0.0'
implementation 'com.google.firebase:firebase-core:16.0.0'
to
classpath 'com.google.gms:google-services:4.0.1'
implementation 'com.google.firebase:firebase-core:16.0.1'
And also open the project in Android studio and clean, rebuild or simply run flutter clean command
Upvotes: 4