'Could not find com.android.support:appcompat-v7:24.2.1

I am trying to build an application on my real device using Android Studio but it gives me an error:

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.
> Could not find com.android.support:appcompat-v7:24.2.1    .
   Required by:
       MyApplication:app:unspecified

The appcompat-v7:24.2.1 is installed and located at ...\sdk\extras\android\m2repository\com\android\support\appcompat-v7\24.2.1.

I also put this directory in the "library repository" in file > project structure but the problem was not solved. Thanks a lot.



Solution 1:[1]

Update your android studio to the latest version.

Solution 2:[2]

It's better to use android latest versions. But you can resolve by replace below code in your app/build.gradle file

android {
    compileSdkVersion 24
    buildToolsVersion "24.2.1"
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 24
        ...
}

Dependencies as follows:

compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:design:24.2.1'

Solution 3:[3]

Follow these steps:

  1. update version of build tools and dependences in buyild.gradle(Module)

    android {
      compileSdkVersion 24
      buildToolsVersion "24.2.1"
      defaultConfig {
      minSdkVersion 19
      targetSdkVersion 24
      ...
    }
    

and dependences

compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:design:24.2.1'
  1. Uses Maven google repository instead of google() in build.gradle(project)

    buildscript {
     repositories {
         jcenter()
         maven {
             url 'https://maven.google.com'
         }
     }
    .....
    
    allprojects {
     repositories {
         maven {
             url 'https://maven.google.com'
         }
         jcenter()
     }
    }
    

Note: Android Studio 4.1.1 Gradle 6.5

enter image description here

enter image description here

Solution 4:[4]

I have just used Maven google repository in build.gradle(project) :

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
        maven {
            url 'https://maven.google.com'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Solution 5:[5]

Update your Android Studio to the latest version to resolve

Solution 6:[6]

Make sure you have compile 'com.android.support:appcompat-v7:25.1.0 in your app/build.gradle.

Solution 7:[7]

Maybe it is because of your minimal SDK version, and you need to migrate to AndroidX as SDK does not support legacy support components

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gabriele Mariotti
Solution 2 Charitha Ratnayake
Solution 3 mehrdad eilbeygi
Solution 4 Noor Hossain
Solution 5 jwthanh
Solution 6 Gabriele Mariotti
Solution 7 Madina Saidova