Flutter firebase_messaging: ^6.0.13 failing with exception: - android

I am trying to implement push notification with firebase_messaging: ^6.0.13,
Flutter: Build errors for firebase_messaging”
I have looked through all similar cases, Migrated my project to AndroidX but I still cannot resolve my Android build errors:
Followed procedures.
Flutter clean
flutter packages pub cache repair
Restart Android
Remake emulator nothing is working
Migrated project to AndroidX
Tried downgrading the plugin versions
Exception:
Using hardware rendering with device Android SDK built for x86. If you get graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle... 0.6s
Resolving dependencies... 2.5s
/home/rajeshpatil/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-6.0.13/android/src/main/java/io/flutter/plugins/firebasemessaging/FirebaseMessagingPlugin.java:80: error: cannot find symbol
onAttachedToEngine(binding.getApplicationContext(), binding.getBinaryMessenger());
^
symbol: method getBinaryMessenger()
location: variable binding of type FlutterPluginBinding
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':firebase_messaging:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* 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 2s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 3.3s
Gradle task assembleDebug failed with exit code 1
project-level/build.gradle:
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
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
}
app-level/build.gradle:
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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.helloworld"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
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 {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
gradle.properties:
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
Flutter Doctor:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v1.10.7, on Linux, locale en_IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.43.0)
[✓] Connected device (1 available)
• No issues found!

It looks like you are working on an older flutter project, try a few things and see if these help.
1) Update your flutter SDK. You are currently using a pretty old version of flutter, and a beta build that was never a stable release. Even if this doesnt solve your problem it would be wise to upgrade. You can do so by running flutter upgrade in your terminal.
2) You may be trying to use an older version of certain firebase packages, including messaging. Try changing classpath 'com.google.gms:google-services:4.3.0'
in your project gradle.build to classpath 'com.google.gms:google-services:3.2.1'. Do this only if updating your flutter SDK doesnt fix the issue, and if this doesnt help change it back.
3) Try increasing your minSDKVersion for the project in the app-level/build.gradle, in the past when I have had similar issues this fixed my problems around sdk version 21.

Related

Execution failed for task ':app:processReleaseMainManifest', while building flutter apk

I have an app that was building fine before I formated my PC. I installed everything flutter needs and what I had in my previous install and tried to build my app after cloning from github. It results in failure.
PS D:\flutter_projects\uni-access> flutter build apk
Running "flutter pub get" in uni-access... 1.849ms
💪 Building with sound null safety 💪
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processReleaseMainManifest'.
> Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module #6732aa85
* 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 29s
Running Gradle task 'assembleRelease'... 30,6s
Gradle task assembleRelease failed with exit code 1
My flutter env.
PS D:\flutter_projects\uni-access> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.1, on Microsoft Windows [Version 10.0.22000.978], locale el-GR)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Chrome - develop for the web
[✗] Visual Studio - develop for Windows
✗ Visual Studio not installed; this is necessary for Windows development.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components
[!] Android Studio (not installed)
[✓] VS Code (version 1.71.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
! Doctor found issues in 2 categories.
I have java 17 and my build.gradle in android/app is the following.
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: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
// compileSdkVersion flutter.compileSdkVersion
compileSdkVersion 32
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.example.flutter_uni_access"
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
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 platform('com.google.firebase:firebase-bom:29.2.1')
implementation 'com.google.firebase:firebase-analytics'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// implementation 'com.android.support:multidex:2.0.1'
}
This problem seems bizzare. I have tried flutter clean, gradle clean, deleting the .gradle dir from my user dir. Still nothing.

Flutter build apk failing with BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 62

My app used to run perfectly fine a few days ago, I did NOT do any updates and today it is not building.
My system -
HP 15s eq2144au
AMD Ryzen 3 5300U
Flutter doctor -
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, 2.13.0-0.0.pre.604, on Microsoft Windows [Version 10.0.22000.613], locale en-IN)
[!] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
X cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
X Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.11)
[√] Android Studio (version 2021.1)
[!] Android Studio
X android-studio-dir = /usr/local/android-studio
X Android Studio not found at /usr/local/android-studio
[√] VS Code (version 1.66.2)
[√] Connected device (3 available)
[√] HTTP Host Availability
! Doctor found issues in 2 categories.
The error -
PS C:\Users\my_user_name\Documents\my_project_folder> flutter build apk
Building with sound null safety
Building with Flutter multidex support enabled.
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\my_user_name\Documents\my_project_folder\android\build.gradle' line: 27
* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
> Could not open proj generic class cache for build file 'C:\Users\my_user_name\Documents\my_project_folder\android\app\build.gradle' (C:\Users\my_user_name\.gradle\caches\6.7\scripts\1l5ett1r4oxtcv991nxlv5dyv).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 62
* 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 1s
Running Gradle task 'assembleRelease'... 1,804ms
Gradle task assembleRelease failed with exit code 1
What I have tried -
I have tried setting the compileSdkVersion in the build.gradle file located in project_folder\android\app to 28 and then 30 but that changes nothing.
My build.gradle file located in project_file\android\ -
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.google.gms:google-services:4.3.10'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My build.gradle file located in project_folder/android/app -
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 {
compileSdkVersion 30
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 myappid
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:29.0.4')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.android.support:multidex:1.0.3'
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
When I run it on Chrome, it works fine, the problem is only with Android.
Thanks!

Flutter : Getting appcenter:verifyReleaseResources Error When Trying to Build in AppCenter

I have followed this blog to build my app on AppCenter
Exactly did the same process
https://medium.com/#maite.daluz11/deploy-flutter-apps-using-appcenter-ec28e8d940bf
APPCENTER BUILD OUTPUT IS SHOWING
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':appcenter:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking failed
/Users/runner/.gradle/caches/transforms-2/files-2.1/a528b13ac93e64cafa3d0480e2c93207/core 1.1.0/res/values/values.xml:142:5-173:25: AAPT: error: resource android:attr/fontVariationSettings not found.
/Users/runner/.gradle/caches/transforms-2/files-2.1/a528b13ac93e64cafa3d0480e2c93207/core-1.1.0/res/values/values.xml:142:5-173:25: AAPT: error: resource android:attr/ttcIndex not found.
BUILD FAILED in 2m 16s
Running Gradle task 'assembleRelease'... 137.7s (!)
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
✏️ Creating `android/settings_aar.gradle`... 1ms
✓ `android/settings_aar.gradle` created successfully.
Building plugin appcenter...
Running Gradle task 'assembleAarRelease'... 35.1s
✓ Built build/app/outputs/repo.
Building plugin appcenter_analytics...
Running Gradle task 'assembleAarRelease'... 2.7s
✓ Built build/app/outputs/repo.
Building plugin appcenter_crashes...
Running Gradle task 'assembleAarRelease'... 2.4s
✓ Built build/app/outputs/repo.
Building plugin flutter_plugin_android_lifecycle...
Running Gradle task 'assembleAarRelease'... 20.9s
Gradle 5.4.1
Resolved com.android.tools.build:gradle:3.5.0 in :classpath
Resolved androidx.annotation:annotation:1.1.0 in :releaseRuntimeClasspath
Resolved io.flutter:flutter_embedding_release:1.0.0-ae90085a8437c0ae94d6b5ad2741739ebc742cb4 in :releaseCompileClasspath
Resolved androidx.annotation:annotation:1.1.0 in :releaseCompileClasspath
Resolved androidx.annotation:annotation:1.1.0 in :releaseCompileClasspath
Resolved com.android.tools.lint:lint-gradle:26.5.0 in :lintClassPath
/Users/runner/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-1.0.11/android/src/main/java/io/flutter/embedding/engine/plugins/lifecycle/FlutterLifecycleAdapter.java:8: error: package androidx.lifecycle does not exist
import androidx.lifecycle.Lifecycle;
^
/Users/runner/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-1.0.11/android/src/main/java/io/flutter/embedding/engine/plugins/lifecycle/FlutterLifecycleAdapter.java:22: error: cannot find symbol
public static Lifecycle getActivityLifecycle(
^
symbol: class Lifecycle
location: class FlutterLifecycleAdapter
2 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
BUILD FAILED in 18s
The plugin flutter_plugin_android_lifecycle could not be built due to the issue above.
My android/app/build.gradle is:
android {
compileSdkVersion 29
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.flutter_tls_identity"
minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
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
}
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
def appCenterSdkVersion = '4.0.0'
implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
}
My android/build.gradle is:
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
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
}
My android/app/appcenter-post-clone.sh is:
#!/usr/bin/env bash
#Place this script in project/android/app/
cd ..
#fail if any command fails
set -e
#debug log
set -x
cd ..
git clone -b beta https://github.com/flutter/flutter.git
export PATH=`pwd`/flutter/bin:$PATH
flutter channel stable
flutter doctor
echo "Installed flutter to `pwd`/flutter"
#build APK
#if you get "Execution failed for task ':app:lintVitalRelease'." error, uncomment next two lines
#flutter build apk --debug
#flutter build apk --profile
flutter build apk --release
#if you need build bundle (AAB) in addition to your APK, uncomment line below and last line of this script.
#flutter build appbundle --release --build-number $APPCENTER_BUILD_ID
#copy the APK where AppCenter will find it
mkdir -p android/app/build/outputs/apk/; mv build/app/outputs/apk/release/app-release.apk $_
#copy the AAB where AppCenter will find it
#mkdir -p android/app/build/outputs/bundle/; mv build/app/outputs/bundle/release/app-release.aab $_
My gradle.properties is
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
My pubspec.yaml dependencies is
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
path_provider:
image_picker:
appcenter:
appcenter_analytics:
appcenter_crashes:
My gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
Solution to the error is;
1 - Open your android/build.gradle & add the following code under your last subprojects
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion 28 --> This is the version in my android/app/build.gradle
buildToolsVersion "28.0.3"
}
}
}
}
2 - Right click to the android[flutter_app_name] folder & go to Flutter -> Open Android module in Android Studio
3 - Under your Project folder open android -> android [appcenter] -> build.gradle & make sure the following Versions are same with the one's in your android/app/build.gradle
compileSdkVersion
buildToolsVersion
minSdkVersion
targetSdkVersion
group 'com.aloisdeniel.flutter.appcenter'
version '1.0-SNAPSHOT'
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
}
}
rootProject.allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 28 --> Make sure this version is same with the one in your android/app/build.gradle
buildToolsVersion '28.0.3' --> Make sure this version is same with the one in your android/app/build.gradle
defaultConfig {
minSdkVersion 21 --> Make sure this version is same with the one in your android/app/build.gradle
targetSdkVersion 28 --> Make sure this version is same with the one in your android/app/build.gradle
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
}
dependencies {
def appCenterSdkVersion = '1.10.0'
implementation "com.microsoft.appcenter:appcenter:${appCenterSdkVersion}"
}
}
4 - Do the same process for the android [appcenter_analytics] & android [appcenter_crashes].
5 - In terminal type flutter clean and after it finishes type flutter build apk.

flutter android - Failed to list versions for com.google.android.gms:play-services-location

Got this err when compiling android, the used to be compiling ok but I have no idea what went wrong.
Ios compiles and works fine tho. I tried a few things including check gradle file has google() and the correct version etc but nothing helps.
*********************************************************
FAILURE: Build failed with an exception.
WARNING: This version of cloud_firestore will break your Android build if it or its dependencies aren't compatible with AndroidX.
* What went wrong:
Could not determine the dependencies of task ':app:preDebugBuild'.
See goo.gl/CP92wY for more information on the problem and how to fix it.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
This warning prints for all Android build failures. The real root cause of the error may be unrelated.
> Could not resolve com.google.android.gms:play-services-location:15.+.
*********************************************************
Required by:
project :app > project :location
> Failed to list versions for com.google.android.gms:play-services-location.
> Could not list versions using M2 pattern 'https://raw.github.com/g123k/ShortcutBadger/master/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier])(.[ext])'.
> Could not get resource 'https://raw.github.com/g123k/ShortcutBadger/master/com/google/android/gms/play-services-location/'.
> Could not GET 'https://raw.github.com/g123k/ShortcutBadger/master/com/google/android/gms/play-services-location/'. Received status code 400 from server: Bad Request
* 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 23s
Finished with error: Gradle task assembleDebug failed with exit code 1
root build.gradle
buildscript {
repositories {
google()
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1' // it was 3.3.1 before but didnt compile, 3.2.1 compiles but with firebase errors
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
google()
jcenter()
mavenLocal()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
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 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 {
compileSdkVersion 28
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.berkey.berkey"
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
// implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
// implementation 'androidx.legacy:legacy-support-v4:1.0.0'
//
// android.useAndroidX=true
// android.enableJetifier=true
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 {
// 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'
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'
Pubspec.yaml
description: A new Flutter project.
version: 1.2.0+3
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
algolia: ^0.1.3+2
firebase_auth: ^0.8.0+3
cupertino_icons: ^0.1.2
google_sign_in: ^4.0.1
cloud_firestore: ^0.9.0+1
firebase_storage: ^2.0.1
image_picker: ^0.5.0+3
location: ^2.0.0
firebase_messaging: ^3.0.1
geolocator: ^3.0.0
firebase_core: ^0.3.0+1
flutter_launcher_icons: "^0.7.0"
flutter_linkify: 1.0.3
url_launcher: ^5.0.1
permission_handler: '^2.2.0'
flutter_app_badger: ^1.0.2
flutter doctor
[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14.2 18C54, locale en-AU)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[!] iOS toolchain - develop for iOS devices (Xcode 10.1)
✗ Verify that all connected devices have been paired with this computer in Xcode.
If all devices have been paired, libimobiledevice and ideviceinstaller may require updating.
To update with Brew, run:
brew update
brew uninstall --ignore-dependencies libimobiledevice
brew uninstall --ignore-dependencies usbmuxd
brew install --HEAD usbmuxd
brew unlink usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
[✓] Android Studio (version 3.3)
[✓] Connected device (1 available)
Sometimes it's due to an issue with the internet connection. Try to check if you have a proper connection.

Flutter google_sign_in error : Unable to merge dex

Dear Flutter community,
I am banging my head on a seemingly simple task.
I want to add firebase authentication to my app. It worked on iOS but as I tried to implement it for android, I systematically get the error :
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle... Resolving dependencies... Running 'gradlew
assembleDebug'... Configuration 'compile' in project ':app' is
deprecated. Use 'implementation' instead. registerResGeneratingTask is
deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use
registerGeneratedFolders(FileCollection) registerResGeneratingTask is
deprecated, use registerGeneratedFolders(FileCollection) Configuration
'compile' in project ':google_sign_in' is deprecated. Use
'implementation' instead.
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge
dex
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Get more help at https://help.gradle.org
BUILD FAILED in 34s Finished with error: Gradle build failed: 1
I reproduced the error using 'flutter create' then adding Firebase capabilities following the codelab
https://codelabs.developers.google.com/codelabs/flutter-firebase/#4
Here is the only modification to pubspec.yaml
dependencies:
flutter:
sdk: flutter
google_sign_in: 0.3.1 # ONLY MODIFICATION
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.0
general build.gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.0' #ONLY MODIF
}
}
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
}
App build.gradle :
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withInputStream { stream ->
localProperties.load(stream)
}
}
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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 26
buildToolsVersion '26.0.3'
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.mycompany.test"
minSdkVersion 16
targetSdkVersion 26
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 {
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'
}
apply plugin: 'com.google.gms.google-services'
here is the flutter doctor output :
[✓] Flutter (on Mac OS X 10.13.2 17C88, locale fr-BE, channel master)
• Flutter at /Users/sergebesnard/flutter
• Framework revision 4d2c2aaaa1 (6 days ago), 2017-12-27 07:30:31 -0800
• Engine revision 7c126001d8
• Tools Dart version 1.25.0-dev.11.0
• Engine Dart version 2.0.0-edge.9e8a3e2d31621c1bdf6139d068e7898a2ac2ab5a
[✓] Android toolchain - develop for Android devices (Android SDK
27.0.2)
• Android SDK at /Users/sergebesnard/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-27, build-tools 27.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)
[✓] iOS toolchain - develop for iOS devices (Xcode 9.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 9.2, Build version 9C40b
• ios-deploy 1.9.2
• CocoaPods version 1.3.1
[✓] Android Studio (version 3.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)
[✓] IntelliJ IDEA Community Edition (version 2017.2.5)
• Flutter plugin version 18.0
• Dart plugin version 172.4155.35
[✓] Connected devices
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.0.0 (API 26) (emulator)
I am obviously new to Android development, and would prefer not to have to become expert to get the tutorial working. Every solution I found required tinkering with the .gradle files and only apply to react-native.
Thank you for your help !
I also had the same issue and I read that you had to include multiDexEnabled true in the app\build.gradle defaultConfig section. This worked for me.
This error means that some of your dependencies use a different version of the google play services.
You'd have to downgrade/upgrade plugins to unify the version used
Change minSdkVersion in android/app/build.gradle from 16 to 21
Final Versions
pubspec.yaml
cloud_firestore: ^0.8.2+3
android/build.gradle
classpath 'com.google.gms:google-services:3.2.1' // Google Services plugin
android/app/build.gradle
targetSdkVersion 27
minSdkVersion 21
Solved : incompatible versions used between plugin and framework.
Google SignIn plugin 0.4.0 and above should be used with new projects created with flutter create in its latest version.
The codelab is no longer valid and should be updated.
This link solved the same issue for me.
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:
Open android/app/build.gradle, then find the line that says
minSdkVersion 16.
Change that line to minSdkVersion 21.
Save the file.
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.
Also, to note, I did not have to set multiDexEnabled to true.
The problem here may be that the plugins you are depending on have conflicting gradle dependencies.
This SO answer here https://stackoverflow.com/a/49901209/90918 provides a description of how to solve this problem by finding the conflicting dependencies and overriding them.
Quoting the original answer:
Your two packages seem to disagree on their transitive dependencies.
One wants 11.6.+, the other wants 11.+ of some play-services
dependencies. Since both 11.6.2 and 11.8.0 are out there, this is
going to end up with a conflict.
If you run ./gradlew androidDependencies in your android/ folder,
you get a listing of the result of dependency resolution, containing,
among others, the following:
+--- :flutter_google_place_picker (variant: release)
+--- com.google.android.gms:play-services-location:11.8.0#aar
+--- com.google.android.gms:play-services-places:11.6.2#aar
+--- com.google.android.gms:play-services-maps:11.6.2#aar
+--- com.google.android.gms:play-services-base:11.8.0#aar
+--- com.google.android.gms:play-services-tasks:11.8.0#aar
+--- com.google.android.gms:play-services-basement:11.8.0#aar
These 11.6.2 and 11.8.0 packages are not going to work together. To
resolve this, you need to patch your dependencies to be consistent
with each other, or add a dependency override to the top level of your
android/app/build.gradle file and hope for the best:
configurations.all {
resolutionStrategy {
force 'com.google.android.gms:play-services-places:11.8.0'
force 'com.google.android.gms:play-services-location:11.8.0'
}
}
I had the same problem
I ve added on my App/build.gradle on android/defaultConfig the line :
multiDexEnabled true
and on dependencies
implementation 'androidx.multidex:multidex:2.0.1'
App/build.gradle look like this:
def localProperties = new Properties()
...
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
....
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
.....
implementation 'androidx.multidex:multidex:2.0.1'
}
it works for me
The reason is you are using the different version of dependencies. To fix this go to your project/App/src/ and open Build.gradle. Then Add multiDexEnabled true Line inside the default config section.
Ex:Like this
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
I had added admob_flutter: ^0.3.4 in my flutter app but didn't used anywhere. Removing from pubspec.yaml file works for me.

Categories

Resources