問題描述
添加 V4支持庫到 android studio,我遵循了這個文檔:https://developer.android.com/tools/support-library/setup.html#libs-without-res 但我得到一個錯誤.這就是我所做的
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
- SDK manager> 已安裝 Android 支持庫和 Android 存儲庫.
- 轉到 Build.Gradle 并添加文檔中給出的行.Build.Gradle 現在看起來像這樣:
//頂級構建文件,您可以在其中添加所有子項目/模塊通用的配置選項.
// 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.+"
}
}
}
然后,我收到一個提示我同步 gradle 的彈出窗口.當我同步 Gradle 時,我收到此錯誤:
Then, I get a popup that suggest that I sync gradle. When i sync Gradle, i get this error:
錯誤:(20, 0) Gradle DSL 方法未找到:'compile()'可能的原因:
Error:(20, 0) Gradle DSL method not found: 'compile()' Possible causes:
我是否缺少任何步驟?請建議.
Am i missing any step? Please suggest.
Build.Gradle(應用程序)
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'])
}
推薦答案
在幾乎所有情況下,您的依賴項都應該放在單個模塊的 build.gradle 文件中,而不是放在最頂層的 build.gradle 文件中.在您的情況下,這意味著應該將依賴項添加到 app
模塊的 build.gradle 文件中:
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.+"
}
您應該刪除頂層 build.gradle 的整個 allprojects
部分.
And you should remove the entire allprojects
part of the top level build.gradle.
這篇關于出現錯誤“未找到 Gradle DSL 方法:'compile()'"同步 Build.Gradle 時的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!