27

I have imported a project in Android Studio that was built in it. I require v4 and v7 library in the project. This is how my build.gradle looks like

build.gradle

apply plugin: 'android-library'

android {
    compileSdkVersion 19
    buildToolsVersion '20'
    defaultConfig {
        applicationId 'com.example.sdk'
        minSdkVersion 9
        targetSdkVersion 19
        versionCode 1
        versionName '1.0'
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:20.0.+'
    compile 'com.android.support:support-v4:20.0.+'
}

When I sync with gradle then it always gives error message

Failed to find: com.android.support:support-v4:20.0.+ & Failed to find: com.android.support:appcompat-v7:20.0.+

enter image description here

enter image description here

Please support & thanks in advance.

N Sharma
  • 33,489
  • 95
  • 256
  • 444

4 Answers4

52

The Android support repository was missing,So go to Android SDK, install the Android Support Repository and Android Support Library. Also you can use the following

compile 'com.android.support:support-v4:20.0.0'
compile 'com.android.support:appcompat-v7:20.0.0'

instead of

compile 'com.android.support:appcompat-v7:20.0.+'
compile 'com.android.support:support-v4:20.0.+'
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
Bijesh P V
  • 798
  • 7
  • 14
12

Note: If you're developing with Android Studio, select and install the Android Support Repository item instead.

see here.

4

From Android Studio go to: Tools >> Android >> SDK Manager

Select and install "Extras|Android Support Repository"

HexAndBugs
  • 5,549
  • 2
  • 27
  • 36
Kishan Vaghela
  • 7,678
  • 5
  • 42
  • 67
1

add maven to your gradle file (project)

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

and use this gradle wrapper:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

and downgrade to gradle plugin to be 2.3.1

classpath 'com.android.tools.build:gradle:2.3.1'
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Raafat Alhmidi
  • 1,106
  • 12
  • 18