How to solve: Could not resolve Android dependency due to Bad Gateway: 502

Question

Asked by Migalv on December 15, 2021 (source).

On the 8th of December I started having issues to run an Android project (Created with the Flutter framework) that had already been published to the Google Play and never had issues when compiling before.

The error I was getting was the following:

Could not determine the dependencies of task ':app:processDebugResources'.
> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.



   > Could not resolve com.google.android.gms:play-services-measurement-base:[18.0.0].
     Required by:


         project :app > project :firebase_analytics > com.google.firebase:firebase-analytics:18.0.0 > com.google.android.gms:play-services-measurement:18.0.0


         project :app > project :firebase_analytics > com.google.firebase:firebase-analytics:18.0.0 > com.google.android.gms:play-services-measurement-api:18.0.0
         project :app > project :firebase_analytics > com.google.firebase:firebase-analytics:18.0.0 > com.google.android.gms:play-services-measurement-sdk:18.0.0
         project :app > project :firebase_analytics > com.google.firebase:firebase-analytics:18.0.0 > com.google.android.gms:play-services-measurement:18.0.0 > com.google.android.gms:play-services-measurement-impl:18.0.0
         project :app > project :firebase_analytics > com.google.firebase:firebase-analytics:18.0.0 > com.google.android.gms:play-services-measurement-api:18.0.0 > com.google.android.gms:play-services-measurement-sdk-api:18.0.0





      > Failed to list versions for com.google.android.gms:play-services-measurement-base.
         > Unable to load Maven meta-data from https://google.bintray.com/exoplayer/com/google/android/gms/play-services-measurement-base/maven-metadata.xml.
            > Could not get resource 'https://google.bintray.com/exoplayer/com/google/android/gms/play-services-measurement-base/maven-metadata.xml'.


               > Could not GET 'https://google.bintray.com/exoplayer/com/google/android/gms/play-services-measurement-base/maven-metadata.xml'. Received status code 502 from server: Bad Gateway

So I started digging and found out that my recent changes were not the issue. And it seems that the Bintray download center was sunset on the 1st of December (google.bintray.com)

Since I'm using a old version of some of the Firebase packages it seems that this link has been shutdown and now I'm not able to compile my application.

Flutter doctor output:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel unknown, 2.0.3, on macOS 11.4 20F71 darwin-arm, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.63.1)
[✓] Connected device (3 available)

• No issues found!

This is my build.gradle:

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        mavenCentral()
        jcenter()
        
    }

    dependencies {
        classpath 'com.google.gms:google-services:4.3.5'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.1'
        classpath 'com.android.tools.build:gradle:3.5.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

And this 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) {
  throw new GradleException("versionCode not found. Define flutter.versionCode in the local.properties file.")

}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
  throw new GradleException("versionName not found. Define flutter.versionName in the local.properties file.")
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

android {
    compileSdkVersion 30

    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.reliqium.reliqium"
        minSdkVersion 24
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
        release {
           if (System.getenv()["CI"]) { // CI=true is exported by Codemagic
               storeFile file(System.getenv()["FCI_KEYSTORE_PATH"])
               storePassword System.getenv()["FCI_KEYSTORE_PASSWORD"]
               keyAlias System.getenv()["FCI_KEY_ALIAS"]
               keyPassword System.getenv()["FCI_KEY_PASSWORD"]
           } else {
                keyAlias System.getenv("RELIQIUM_ANDROID_KEYSTORE_ALIAS")
                keyPassword System.getenv("RELIQIUM_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD")
                storeFile file(System.getenv("HOME") + "/keystores/reliqiumapp.keystore")
                storePassword System.getenv("RELIQIUM_ANDROID_KEYSTORE_PASSWORD")
           }
       }
   }

    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 'com.android.support:multidex:1.0.3'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.facebook.android:facebook-core:7.0.1'
    implementation 'com.facebook.android:facebook-login:7.0.1'
    implementation "com.airbnb.android:lottie:3.5.0"
    implementation "com.android.support.constraint:constraint-layout:2.0.4"
}

The version of the Flutter Firebase packages are the following:

I know, these are outdated versions of the Firebase packages (For multiple reasons it's not viable to upgrade them to their next versions)

The issue seems to be with the Firebase Analytics package. I have tried to remove it but then I get a similar error for the Firebase Cloud Firestore package which is required for the application.

Please can someone help me with this. I have tried multiple things but nothing seems to solve this issue and I need to compile the app to launch a new version soon!

Answer

Question answered by Migalv (source).

I solved the issue by upgrading my Gradle version to v4.1.0

android/build.gradle:

dependencies {
  ...
  classpath 'com.android.tools.build:gradle:4.1.0'
  ...
}

android/gradle/wrapper/gradle-wrapper.properties:

...
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip

(EDIT): You also need a couple more things:

  1. Remove the jcenter() from your build.gradle
buildscript {
  ...
  repositories {
    google()
    mavenCentral() // add this
    // jcenter() // remove this
  }
}
...

allprojects {
  repositories {
     google()
     mavenCentral()// ADD THIS
     // jcenter() // REMOVE THIS
  }
}
  1. Switch minifyEnabled & shrinkResources to false in the app/build.gradle:
android {
  ... 
  buildTypes {
    release {
      signingConfig signingConfigs.release
      minifyEnabled false // ADD THIS
      shrinkResources false // ADD THIS
    }
  }
  ...
}
ANDROID FIREBASE FLUTTER GRADLE
SHARE: