Hi, when I do flutter run, everything works fine. but when I want to build to apk, it throws this error
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithR8ForRelease'.
java.lang.IllegalArgumentException: Multiple entries with same key: Method com.google.firebase.iid.FirebaseInstanceId.zza Proto LLL com.google.android.gms.tasks.Task java.lang.String java.lang.String=Encoded method Method com.google.firebase.iid.FirebaseInstanceId.zza Proto LLL com.google.android.gms.tasks.Task java.lang.String java.lang.String and Method com.google.firebase.iid.FirebaseInstanceId.zza Proto LLL com.google.android.gms.tasks.Task java.lang.String java.lang.String=Encoded method Method com.google.firebase.iid.FirebaseInstanceId.zza Proto LLL com.google.android.gms.tasks.Task java.lang.String java.lang.String
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 27s
Picked up _JAVA_OPTIONS: -Xmx512M
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 28.6s
Gradle task assembleRelease failed with exit code 1
Below is my android/build.gradle
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
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
}
Below is my 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"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.giftedhands.app"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
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.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
apply plugin: 'com.google.gms.google-services'
i'm also facing same issue,i runned flutter clean and after that this issue is comming up before it was fine and i was able to build apks but those apks were not as same as i expected so i tried flutter clean and tried to build again then this happened to me
someone resolve this issue fast please馃槬馃様 i got a client.
i noticed something! i just cloned my flutter repository and build apk,build went fine,but the apk is having issues like it is not as same as it is while running the app by flutter run
use the --no-shrink.
flutter build apk --split-per-abi --no-shrink
it worked for me.
@budescode
Hey thank you so much worked for me馃馃ぉ
although few components are not working like in flutter run case but atleast i got the app thaks man
Same error here after upgrade firebase dependencies to match firebase_core: ^0.5.0
i have these firebase dependencies:
firebase_auth: ^0.18.0+1
firebase_core: ^0.5.0
cloud_firestore: ^0.14.0+2
firebase_storage: ^4.0.0
firebase_dynamic_links: ^0.6.0
and my build.grade is:
defaultConfig {
applicationId "app.web.funfly"
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
after the error I tryied to upgrade flutter (I`m on beta channel) but nothing changed.
use the --no-shrink.
flutter build apk --split-per-abi --no-shrink
it worked for me.
flutter build apk --no-shrink
worked for me
flutter build apk --no-shrink worked but it completly disable shrink and code optmization.
I found out that you can only remove the problematic class from the optimization by
add a proguard-rules.pro file into your /android/app directory
-keep class com.google.firebase.iid.FirebaseInstanceId { zza(...); }
modify you release entry at the build.gradle file to use your proguard-rules.pro file:
...
buildTypes {
release {
// Enables resource shrinking, which is performed by the
// Android Gradle plugin.
shrinkResources true
// Enables code shrinking, obfuscation, and optimization for only
// your project's release build type.
minifyEnabled true
useProguard true // obfuscate
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
...
@gabera I can't get your fix to work, but adding --no-shrink fixes it - of course the APK is huge then. Any ideas how to fix it?
@gabera tried your fix and the build itself is successful however the second i get try to fetch data from firestore i get a hard crash
This worked for me:-
Add this to dependencies in App-level build.gradle (< project >/< app-module >/build.gradle):
implementation platform('com.google.firebase:firebase-bom:25.12.0')
Most helpful comment
use the --no-shrink.
flutter build apk --split-per-abi --no-shrink
it worked for me.