shr*_*sht 23 android android-gradle-plugin


要向Android studio添加V4支持库,我按照以下文档:https://developer.android.com/tools/support-library/setup.html#libs-without-res但是我收到错误.这就是我做的
//顶级构建文件,您可以在其中添加所有子项目/模块共有的配置选项.
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.+"
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我得到一个弹出窗口,建议我同步gradle.当我同步Gradle时,我收到此错误:
错误:(20,0)未找到Gradle DSL方法:'compile()'可能的原因:
我错过了任何一步吗?请建议.
的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'])
}
Run Code Online (Sandbox Code Playgroud)
ian*_*ake 37
在几乎所有情况下,应将依赖项放入单个模块的build.gradle文件中,而不是放在最顶级的build.gradle文件中.在您的情况下,这意味着应该将依赖项添加到app模块的build.gradle文件中:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:support-v4:18.0.+"
}
Run Code Online (Sandbox Code Playgroud)
你应该删除allprojects顶级build.gradle 的整个部分.
C. *_*odd 12
我发现,当我添加applicationSuffix或versionNameSuffix通过IDE菜单(建设>编辑生成类型),它改变了我的应用程序的build.gradle的依赖关系部分从这个:
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
}
Run Code Online (Sandbox Code Playgroud)
对此:
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
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么,但它将前三个"编译"行合并为一行,并移动两个注释(在每种情况下移动到下一行).
我通过编辑app build.gradle并将每个"compile"语句放在自己的行上来解决了这个问题.
| 归档时间: |
|
| 查看次数: |
76902 次 |
| 最近记录: |