To add V4 support libraries to android studio, i followed this document:https://developer.android.com/tools/support-library/setup.html#libs-without-res but I get an error. Here is what i did
// 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:0.13.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
dependencies {
compile "com.android.support:support-v4:18.0.+"
}
}
}
Then, I get a popup that suggest that I sync gradle. When i sync Gradle, i get this error:
Error:(20, 0) Gradle DSL method not found: 'compile()' Possible causes:
Am i missing any step? Please suggest.
Build.Gradle(app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.appt.shreyabisht.staymax"
minSdkVersion 15
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
In almost all cases, your dependencies should be put into the individual module's build.gradle files rather than at the top most level build.gradle file. In your case, that means the dependency should be added to the app
module's build.gradle file:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:support-v4:18.0.+"
}
And you should remove the entire allprojects
part of the top level build.gradle.
I have found that when I add an applicationSuffix
or versionNameSuffix
through the IDE menu (Build > Edit Build Types), it changes the dependencies section of my app build.gradle from this:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
testCompile 'org.json:json:20140107'
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile "com.android.support:support-vector-drawable:${supportLibVersion}" // VectorDrawableCompat
compile "com.android.support:animated-vector-drawable:${supportLibVersion}" // AnimatedVectorDrawableCompat
}
to this:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
testCompile 'org.json:json:20140107'
compile "com.android.support:appcompat-v7:${supportLibVersion}" compile "com.android.support:design:${supportLibVersion}" compile "com.android.support:support-vector-drawable:${supportLibVersion}"
// VectorDrawableCompat
compile "com.android.support:animated-vector-drawable:${supportLibVersion}"
// AnimatedVectorDrawableCompat
}
I don't know why, but it combines the first three "compile" lines into one line, and moves the two comments (to the next line in each case).
I solved the problem by editing the app build.gradle and putting each "compile" statement onto its own line.
This worked for me:
<home folder>/.gradle
folder.P.S.: Mine was a fresh project so I removed the project as well and created a new one, so there were no old gradle references from the project
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With