androidandroid-studiogradlecrashlytics

Upgrade from gradle 7 to gradle 8 in Android Studio fails to Sync gradle files


My application has been building fine using Gradle 7.X (and appropriate AGP). When only upgrading gradle and the AGP to the 8.0 (same when using the latest 8.X), I can no longer sync.

The following line from the build.gradle:

....
productFlavors {
        myapp{
            dimension "allBuilds"
            applicationId "com.mycompany.app.myapp"
            manifestPlaceholders = [ appLabel:getAppName("myapp") ]
....

The error reported is:

Build file 'C:\SVN\Trunk\AndroidAS\app\build.gradle' line: 371

A problem occurred evaluating project ':app'.
> Could not find method myapp() for arguments [build_dafdi2f917kzmqhe29txz3kwk$_run_closure1$_closure7$_closure17$_closure23@6697cf51] on BuildType$AgpDecorated_Decorated{name=productFlavors, debuggable=false, testCoverageEnabled=false, jniDebuggable=false, pseudoLocalesEnabled=false, renderscriptDebuggable=false, renderscriptOptimLevel=3, minifyEnabled=false, zipAlignEnabled=true, signingConfig=null, embedMicroApp=true, mBuildConfigFields={}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}} of type com.android.build.gradle.internal.dsl.BuildType$AgpDecorated.

I've tried reducing the file to entirely simple productFlavors and a single "myapp" flavour. The moment I add back in a flavour, the error appears.

If I just keep deleting portions of my build.gradle, I can get to this, and I still get the same error:

apply plugin: 'com.android.application'

android {
    namespace 'com.mycompany.app.myapp'

    buildTypes {
        productFlavors {
            myapp{
                applicationId "com.mycompany.app.myapp"
            }
        }
    }
}

That's about as simplified as it gets. It seems like it must be a configuration issue and not an issue with the gradle file itself.

Are there other changes that need to be made for this upgrade, something else in Android Studio (Android Studio Koala Feature Drop | 2024.1.2 Patch 1)?

The need for the upgrade is that I want to use the Crashlytics.log() and related methods.

Alternatly, is there any way to use Crashlytics breadcrumbs without upgrading to Gradle/AGP 8.X?

Thanks


Solution

  • I strongly recommend you switch to Kotlin DSL. By now it is the default DSL, you immediately get type-safe build scripts, actually helpful error messages if you mess up the syntax, and amazingly better IDE support if you use a good IDE like IntelliJ IDEA or Android Studio.

    Here especially the "actually helpful error messages" for example would kick in. The message you get means "something within the myapp { ... } block is wrong, but I don't tell you what". In this case it is a small block so not all too hard to find out, but sometimes you get the same for the android { ... } block for example and can then for a long time comment in and out random things to find the problem.

    I guess in your case the problem is, that you nest productFlavors within buildTypes where it does not belong (they are parallel). So my assumption is, that myapp is not considered a product flavor but a build type (which is supported by this part of your error message: on BuildType$AgpDecorated_Decorated{name=productFlavors"), and due to that the configured properties are not the ones that are expected.