Why can’t I build the program? I will post the tool environment and debug information later
About Android Studio:
Android Studio Ladybug | 2024.2.1 Patch 1
Build #AI-242.23339.11.2421.12483815, built on October 11, 2024
Runtime version: 21.0.3±79915917-b509.11 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 15.0.1
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 2048M
Cores: 8
Metal Rendering is ON
Registry:
ide.experimental.ui=true
i18n.locale=
Non-Bundled Plugins:
com.jetbrains.edu (2024.10-2024.2-1604)
Debug information
2 issues were found when checking AAR metadata:
-
Dependency ‘androidx.core:core:1.15.0’ requires libraries and applications that
depend on it to compile against version 35 or later of the
Android APIs.:app is currently compiled against android-34.
Recommended action: Update this project to use a newer compileSdk
of at least 35, for example 35.Note that updating a library or application’s compileSdk (which
allows newer APIs to be used) can be done separately from updating
targetSdk (which opts the app in to new runtime behavior) and
minSdk (which determines which devices the app can be installed
on). -
Dependency ‘androidx.core:core-ktx:1.15.0’ requires libraries and applications that
depend on it to compile against version 35 or later of the
Android APIs.:app is currently compiled against android-34.
Recommended action: Update this project to use a newer compileSdk
of at least 35, for example 35.Note that updating a library or application’s compileSdk (which
allows newer APIs to be used) can be done separately from updating
targetSdk (which opts the app in to new runtime behavior) and
minSdk (which determines which devices the app can be installed
on).
I found the answer:
Change compileSdk
to 35.
- Open
app/build.gradle
file or (Gradle Scripts/build.gradle.kts
if you are using the Android folder structure). - Locate the
android
block. - Modify the
compileSdk
to 35
Before:
android {
namespace = "com.example.lemonade"
compileSdk = 34
...
After:
android {
namespace = "com.example.lemonade"
compileSdk = 35
...
The error you’re encountering indicates that your project is currently compiled with Android API level 34, but the dependencies you’re using (androidx.core:core:1.15.0 and androidx.core:core-ktx:1.15.0) require API level 35 or higher to compile properly.
Steps to Fix the Issue:
Update compileSdk Version: You need to update your project’s compileSdk version to at least 35 to meet the requirements of the dependencies.
Open your build.gradle file (or build.gradle.kts if using Kotlin DSL) in the app module.
Find the compileSdkVersion line and change it to 35:
For Groovy (build.gradle):
groovy
Copy code
android {
compileSdkVersion 35
// other configurations...
}
For Kotlin (build.gradle.kts):
kotlin
Copy code
android {
compileSdk = 35
// other configurations...
}
Sync Gradle: After making this change, sync your project with Gradle files. In Android Studio, you can do this by clicking “Sync Now” in the bar that appears at the top after modifying build.gradle.
Check for Other Dependencies: After updating compileSdkVersion, check if there are any other dependencies or libraries that might also need to be updated. If you use the AndroidX libraries, it’s generally a good idea to ensure all related libraries are up-to-date.
Optional: Update targetSdkVersion (if needed)
While updating compileSdkVersion is required, you may also want to update targetSdkVersion to 35 if you intend to make use of new runtime behavior associated with the latest SDK.
In the same build.gradle file, you can set targetSdkVersion (optional but recommended for newer features):
For Groovy:
groovy
Copy code
android {
targetSdkVersion 35
// other configurations…
}
For Kotlin:
kotlin
Copy code
android {
targetSdk = 35
// other configurations…
}
Why This Is Happening:
The libraries androidx.core:core:1.15.0 and androidx.core:core-ktx:1.15.0 are designed to work with Android API level 35 or higher. Since your project is using API level 34 (android-34), Gradle is flagging this mismatch.
Once you update to compileSdkVersion 35, you should no longer see this error.
Summary:
Update compileSdkVersion to 35 in your build.gradle file.
Sync your project with Gradle.
Optionally update targetSdkVersion to 35 for better compatibility.
After these changes, the dependencies should work correctly with your project.