Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle fails to resolve dependency in Android Studio

I have imported a Phonegap project in Android Studio and I made it a Gradle-based project.
Now I'm trying to compile some external dependencies and I get this error :

Error:(72, 13) Failed to resolve: com.loopj.android:android-async-http:1.4.6 Show in File
Show in Project Structure dialog

I've tried to add those dependencies by going in File-> ProjectStructure-> Dependencies and adding them "automatically". Android Studio do find the libraries and he add them in my build.gradle but I still get the same error...

here is a part of my build.gradle file (the dependencies are at the bottom) :

import java.util.regex.Pattern

apply plugin: 'android'

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0+'
    }
}

ext.multiarch=false

android {
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }

    defaultConfig {
        versionCode Integer.parseInt("" + getVersionCodeFromManifest() + "0")
    }

    compileSdkVersion 21
    buildToolsVersion "21.0.0"

    if (multiarch || System.env.BUILD_MULTIPLE_APKS) {
        productFlavors {
            armv7 {
                versionCode defaultConfig.versionCode + 2
                ndk {
                    abiFilters "armeabi-v7a", ""
                }
            }
            x86 {
                versionCode defaultConfig.versionCode + 4
                ndk {
                    abiFilters "x86", ""
                }
            }
            all {
                ndk {
                    abiFilters "all", ""
                }
            }
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.loopj.android:android-async-http:1.4.6'
    compile 'org.altbeacon:android-beacon-library:2+@aar'
    for (subproject in getProjectList()) {
        compile project(subproject)
    }
}

thanks for any help :)

like image 613
Théo Richard Avatar asked Apr 23 '15 13:04

Théo Richard


2 Answers

this should not be inside buildscript, keep it outside buildscript. use jcenter() or mavenCentral() on depending your requirement.

repositories {
    mavenCentral()
}

Also you are using wrong plugin. if building for app, use

apply plugin: 'com.android.application'

if building for library, use

apply plugin: 'com.android.library'
like image 136
Amrut Bidri Avatar answered Oct 01 '22 19:10

Amrut Bidri


Add this part to your build.gradle outside the buildscript part.:

repositories {
     jcenter()
}

Don't confuse this repository with the repository used by buildscript part.They are different.

Also change

apply plugin: 'android'

in

apply plugin: 'com.android.application'
like image 38
Gabriele Mariotti Avatar answered Oct 01 '22 19:10

Gabriele Mariotti