No virtual method at(Ljava/lang/Object;I)Landroidx/compose/animation/core/KeyframesSpec$KeyframeEntity – Android

by
Alexei Petrov
android android-jetpack-compose

Quick Fix: Updating the androidx.compose.material3:material3 dependency to version 1.2.0-rc01 should resolve the issue with the missing virtual method. This specific version seems to have addressed the issue while maintaining compatibility with the rest of the dependencies from the BOM.

The Problem:

You have upgraded Compose to 2024.01.00 and are now encountering a NoSuchMethodError for at(Object, int) in KeyframesSpec.KeyframesSpecConfig. This error is likely due to a breaking change in the Compose animation library.

The Solutions:

Solution 1: Downgrade the version of `androidx.compose.material3` to `1.2.0-rc01`

It appears that the version of `androidx.compose.material3` included in the BOM for `2024.01.00` is broken. To fix this issue, you can downgrade the version of `androidx.compose.material3` to `1.2.0-rc01` while keeping the rest of the versions from the BOM until they release the next version which will hopefully fix this.

To do this, add the following line to your `build.gradle` file:

implementation 'androidx.compose.material3:material3:1.2.0-rc01'

\n

Solution 2: Downgrade material3 lib version to 1.2.0-rc01

\n

As suggested in the issue tracker, you can temporarily fix the issue by downgrading the material3 lib version to 1.2.0-rc01 in your project’s build.gradle file. Here’s how to do that:

\n

  1. Open your project’s build.gradle file (usually app/build.gradle).
  2. Locate the dependencies section.
  3. Find the line that includes the material3 lib dependency and change the version to “1.2.0-rc01”. It should look like this:
  4. dependencies {
        implementation("androidx.compose.material3:material3-android:1.2.0-rc01")
    }
    
  5. Save the build.gradle file.
  6. Rebuild your project.

\n

After following these steps, the CircularProgressIndicator should work as expected. This is a temporary solution until a new compose BOM version is released with material3-android:1.2.0-rc01 included.

\n

To check for updates, keep an eye on the issue tracker (linked in the Solution 1) for further announcements.

Solution 3: Downgrading the Material 3 library version to 1.2.0-rc01

The issue seems to be caused by a recent update to the Compose BOM, which has broken the compatibility between Compose Animation and Material 3. To resolve this, you can temporarily downgrade the version of the Material 3 library to 1.2.0-rc01, which is known to be compatible with the current version of Compose Animation.

To downgrade the Material 3 library version, you can either edit your `libs.version.toml` file (if you’re using a version management tool like JitPack) or add the following line to your `build.gradle` file:

implementation("androidx.compose.material3:material3:1.2.0-rc01")

After making this change, you should be able to build your project without encountering the `NoSuchMethodError` exception.

Solution 4: Revising CircularProgressIndicator Usage

To resolve the No virtual method at(Ljava/lang/Object;I)Landroidx/compose/animation/core/KeyframesSpec$KeyframeEntity; error encountered with CircularProgressIndicator, we need to adjust how we’re using the component. The key change is to include a progress value within the CircularProgressIndicator.

Before:

CircularProgressIndicator()

This usage did not specify a progress value, leaving it undefined.

After:

CircularProgressIndicator(
    progress = 0.89f,
)

Now, we explicitly set the progress value to "0.89f". You can adjust this value to suit your specific needs.

Alternatively, if you prefer not to provide a hard-coded progress value, consider upgrading to the latest version of the Material 3 dependency. This update may address the issue without requiring the manual setting of progress.

Q&A

I am facing a similar error while upgrading to Compose 2024.01.00. What is causing this issue?

The error is due to a bug in the latest version of Material 3. Downgrade to version 1.2.0-rc01 as a temporary solution.

I found a related issue, where can I track its progress?

You can follow the issue on Google’s Issue Tracker: https://issuetracker.google.com/issues/322214617

Is there a way to fix the issue without downgrading the Material 3 library?

You can try adding a hard-coded "progress" value to CircularProgressIndicator component.