3

I needed to add a android.support.v4.widget.NestedScrollView to my project, which requires the V4 support library according to this question. In the answer it said . . .

You need to add this line in dependencies:

compile 'com.android.support:support-v4:23.4.0'

...I assumed that referred to the build.gradle file. I have two - a top-level one and a module one. Only my top-level one had a dependencies keyword, so I put it there. But when I did I got

Error:(8, 0) Gradle DSL method not found: 'compile()'

...which is addressed in this question here as well as this question where it indicates I need to move it to the build.gradle for my module. But the module build.gradle has a completely different structure so I don't know where it goes.

My top-level build.gradle looks like this:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        compile 'com.android.support:support-v4:23.4.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

And my module-level one looks like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 16
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.assemblyguide.remote"
        minSdkVersion 16
        targetSdkVersion 16
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

Where do I put the compile statement (or the dependencies clause it goes into) in the module build.gradle to avoid that error, and why do the two build.gradle files look so completely different?

Bonus question: I'm new to Android Studio and I didn't have to know this stuff for Eclipse. How much of a Gradle expert should I plan to be to use Android Studio and where can I get a basic understanding of Gradle without having to get a PhD in it?

Community
  • 1
  • 1
user316117
  • 7,299
  • 18
  • 70
  • 141

2 Answers2

1

I suggest you download the full Gradle distribution, which comes with the "User Guide" PDF. Read it from top to bottom, skipping chapters that are truly not relevant to you. You'll avoid having to ask many questions.

Direct link to Gradle User Manual pdf

In your case, you should remove the "compile" line you added in the "buildscript" block. You likely need to replace your "allprojects" block with the following:

allprojects {
    repositories {
        jcenter()
    }    
    dependencies {
        compile 'com.android.support:support-v4:23.4.0'
    }
}
kkarakk
  • 927
  • 6
  • 18
David M. Karr
  • 11,418
  • 13
  • 71
  • 144
-1

You should declare the the dependencies at the end of your main project module. Usually it is the app module. Find a build.gradle file there and follow the instructions shown here
It should look like this one

R. Zagórski
  • 18,351
  • 5
  • 59
  • 86