How do I make AGP Upgrade Assistant offer other versions?


I am brand new to Android and have been following the official walkthrough-style tutorials. I am on the second one, Build a simple app with text composables. Everything is fine with the code itself. The only difference is I am using IntelliJ Ultimate instead of standalone Android Studio.

I recently tried to build by clicking "Build & Refresh" in the Design pane. It failed with

> 18 issues were found when checking AAR metadata: > > Dependency 'androidx.core:core-ktx:1.17.0' requires Android Gradle plugin 8.9.1 or higher. > > This build currently uses Android Gradle plugin 8.6.0-alpha07. > > [17 other errors similar to the above, all saying 8.6.0-alpha07 isn't enough]

I read a ton of advice about modifying project settings files and upgrading gradle with .\gradlew.bat wrapper --gradle-version 8.14.3 but none of it helped. I do see a folder named 8.14.3 in my .gradle, so I know it's there, just not being called by IntelliJ. I've reverted the settings to what I think is the original state of the tutorial at the start of step 5, "Add a new text element".

I have managed to figure out so far that I need to use the AGP Upgrade Assistant in IntelliJ (Tools > Android > AGP Upgrade Assistant...). When I open it, it says "Upgrade Android Gradle Plugin from version 8.6.0-alpha07 to" and then a dropdown... but the only option in the dropdown is "8.6.0-alpha07". The info panel says "Up-to-date for Android Gradle Plugin version 8.6.0-alpha07". Clicking "Refresh" doesn't add more versions. I just updated IntelliJ itself and it changed nothing.

There are lots of search results for what to do if running the upgrade assistant causes errors but I couldn't find a single useful one for adding version options to the tool itself.

[EDIT: I discovered a file called gradle/libs.versions.toml that starts with

[versions]
agp = "8.6.0-alpha07"

that seemed promising. Changing the agp value to 8.14.3 just changed the error, unfortunately:

> Build file '...\HappyBirthday\build.gradle.kts' line: 2 > > Plugin [id: 'com.android.application', version: '8.14.3', apply: false] was not found in any of the following sources: > > * 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 ]

Am I at least on the right track? What else do I need to do here?

1
Feb 19 at 10:36 PM
User AvatarMirrorSymmetry
#android#gradle#intellij-idea#intellij-plugin

Accepted Answer

You are mixing two separate things:

  • Gradle
  • Android Gradle Plugin (AGP)

Gradle is the build tool that plugs everything together. Among others it retrieves all needed dependencies and runs the compiler to convert the source files you wrote into an executable application.

The Android Gradle Plugin (usually abbreviated to AGP) is a plugin for Gradle that adds a lot of aspects to the build process that are specific to creating an Android app.

There is a loose coupling between the two (see the compatibility matrix), but you always need both, and they both have different version numbers, although they look similar or even the same at first glance.


Now, your build files seem to run Gradle in version 8.14.3. This can be configured in the file gradle/wrapper/gradle-wrapper.properties. And you already discovered that the AGP version is specified in gradle/libs.versions.toml, which is your version catalog. You started out using AGP in version 8.6.0-alpha07.

The initial error message you got stated "Dependency [...] requires Android Gradle plugin 8.9.1 or higher". This means you should have set this in the version catalog (hold off for now, though, see below):

agp = "8.9.1"

You instead set it to 8.14.3 which is not an existing AGP version, it is a Gradle version. That's what your second error message is all about.

There is one last caveat, though. AGP also requires support by the IDE. There is a compatibility matrix for that as well, although it only lists specific versions of Android Studio. You use IntelliJ IDEA, however. Android Studio is built upon IntelliJ IDEA, and AGP is also compatible with it, but I'm not aware of an official list of the specific versions which are supported for a given AGP version.

The AGP Upgrade Assistant however detects the latest AGP version your IDE supports, so it never recommends higher versions (they wouldn't work in that IDE). That's most likely the reason you don't get anything newer recommended than 8.6.0-alpha07.

The AGP Upgrade Assistant is usually the right way to upgrade your AGP version because it also takes care of updating everything else that is required, like the Gradle version. In your case, however, you need to either upgrade your IDE or downgrade all your dependencies that require a newer AGP version. That is at least androidx.core:core-ktx from your first error message, but it may very well be other dependencies too that you'll only find out about when you actually try to build your app.


Long story short: I recommend you update your IDE (or switch to Android Studio if you cannot easily update your IntelliJ IDEA version). You can have them both installed in parallel, and you can even have different versions of the same IDE installed at the same time. The easiest way to manage different IDE versions is probably to use the JetBrains Toolbox.

After installing a newer IDE you can use the AGP Upgrade Assistant to update AGP to the newest version and also update Gradle to a matching one.

A little heads up: Right now there is a big switch taking place from AGP 8 to AGP 9, including a Gradle update to version 9 as well. Several things changed, and not all tools and dependencies in the wild are already compatible. So you might want to hold off of AGP 9 and Gradle 9 for now (yeah, I know, they both share the same version 9 - but they are still different versions). You should at least try to get your app to build with AGP 8 first, then you can try the upgrade to AGP 9.

User Avatartyg
Feb 20 at 12:48 AM
0