[Solved] Dependency ‘androidx.activity:activity:1.8.0’ requires libraries
When we create a new project in Android Studio, and run this project. The compilation fails and this error appears in logcat window.
An issue was found when checking AAR metadata:
Dependency ‘androidx.activity:activity:1.8.0’ requires libraries and applications that
depend on it to compile against version 34 or later of the
Android APIs. :app is currently compiled against android-33. Also, the maximum recommended compile SDK version for Android Gradle
plugin 7.3.0 is 33. Recommended action: Update this project’s version of the Android Gradle
plugin to one that supports 34, then update this project to use
compileSdkVerion of at least 34. Note that updating a library or application’s compileSdkVersion (which
allows newer APIs to be used) can be done separately from updating
targetSdkVersion (which opts the app in to new runtime behavior) and
minSdkVersion (which determines which devices the app can be installed
on).
Solve Dependency ‘androidx.activity:activity:1.8.0’ requires libraries
There are two ways to solve this ‘Dependency ‘androidx.activity:activity:1.8.0′ requires libraries’.
Method 1: Upgrade compiled sdk version
First method is to upgrade the compiled and targeted sdk version from 33 to 34. Upgrade the version and run again the project, the issue will be resolved.
android {
namespace 'com.android.mydeomo'
compileSdk 34
defaultConfig {
applicationId "com.android.mydeomo"
minSdk 21
targetSdk 34
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
Method 2: Downgrade Material plugin
This error can also be resolved by downgrading our material plugin. replace this implemantation: implementation ‘com.google.android.material:material:1.10.0’ with: implementation ‘com.google.android.material:material:1.8.0’
Replace this line
implementation 'com.google.android.material:material:1.10.0'
To this
implementation 'com.google.android.material:material:1.8.0'
Now sync project and run again. It will install the app.
If you visit the Maven repository page for material 1.10.0, you will notice a section called ‘Compile Dependencies.’ This section lists the dependencies required for the material dependency to compile and function properly. Typically, these compile dependencies are automatically included when you declare the main dependency in your project.
The first dependency in the list is ‘activity 1.8.0,’ which is only compatible with ‘compileSdk’ versions greater than or equal to 34. To resolve this compatibility issue, you can either downgrade the material dependency or upgrade your project’s ‘compileSdk’ version.
You can also read how to download image from url in android kotlin