Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't Android Support Libraries work in my project?

Using Android Studio, I followed the steps at https://developer.android.com/tools/support-library/setup.html as acurately as I could, but it told me the following error:

Error:Could not find method compile() for arguments [com.android.support:appcompat-v7:18.0.+] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@18899229.

Please install the Android Support Repository from the Android SDK Manager. Open Android SDK Manager compile error

But I have already installed the Support Repository and Library! Since I also got an error saying compile doesn't belong in the dependencies block, so I changed it to classpath, and got the following, similar error:

Error:Could not find any version that matches com.android.support:appcompat-v7:18.0.+. Required by: :ExpenseTracker:unspecified

Please install the Android Support Repository from the Android SDK Manager. Open Android SDK Manager could not find and proof of install

As you can see here, it still thinks the ASR isn't installed, but as the screenshot proves, it is. So what am I doing wrong here?

like image 581
Ky. Avatar asked Jul 07 '14 22:07

Ky.


2 Answers

I think you're placing these lines in the wrong file.

They should go in the module's build.gradle file, not in the project's one (which this would seem to be, from the screenshot).

Also, the dependencies tag should not be a child of anything else. something like:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    ...
}

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

EDIT Did you see the comment? :)

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
like image 71
matiash Avatar answered Oct 19 '22 06:10

matiash


My problem was that after letting Android Studio upgrade the Gradle plugin to the latest version, it had messed up the dependency section of my module's build file. It had concatenated the dependency declaration lines together (except for the lines that were mere comments). Separating the lines (placing each dependency declaration in a single line) fixed the issue.

like image 44
Javad Avatar answered Oct 19 '22 04:10

Javad