2015-09-04 143 views
0

我试图按照建议的方法将此library包含到我当前的项目中here 这导致打破了我的项目和I我在图书馆 error 这里的build.gradlle文件收到以下错误是该项目的的build.gradle(更新):gradle.build错误(28,0):未找到Gradle DSL方法:'apply()'

// 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:1.2.3' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

subprojects { 
    ext.global_compileSdkVersion = 22 
    ext.global_buildToolsVersion = "23.0.0 rc2" 
} 

的build.gradle的应用模块:

// Top-level build file where you can add configuration options common to all sub-projects/modules. 
apply plugin: 'com.android.application' 

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:1.2.3' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

android { 
    compileSdkVersion 22 
    buildToolsVersion "23.0.0 rc2" 
} 

subprojects { 
    ext.global_compileSdkVersion = 22 
    ext.global_buildToolsVersion = "23.0.0 rc2" 
} 

和我想添加库中的build.gradle:

/* 
* Copyright (C) 2015 Haruki Hasegawa 
* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
*  http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 

apply plugin: 'com.android.library' 

ext { 
    // required for 'android-maven-publish.gradle' 
    mavenPublishDestDir = new File(rootDir, "repository").absolutePath 
    mavenPublishDataFile = file('./library-data.properties').absolutePath 
    mavenPublishSigningSetting = file('../signing/library-maven-publish-signing.properties').absolutePath 
} 

// Common configurations 

android { 

    defaultConfig { 
     minSdkVersion 9 
     targetSdkVersion 22 

     def dataProps = new Properties() 
     dataProps.load(project.file(project.mavenPublishDataFile).newDataInputStream()) 

     versionCode dataProps.VERSION_CODE.toInteger() 
     versionName dataProps.VERSION_NAME 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      shrinkResources false 
      consumerProguardFiles 'proguard-rules.pro' 
     } 
     debug { 
      minifyEnabled false 
      shrinkResources false 
      consumerProguardFiles 'proguard-rules.pro' 
     } 
    } 
} apply plugin: 'java' 

dependencies { 
    compile 'com.android.support:appcompat-v7:22.2.1' 
    compile 'com.android.support:recyclerview-v7:22.2.1' 
} 

tasks.withType(JavaCompile) { 
    options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked" 
} 

和settings.gradle

include ':app', ':advancedRecyclerView' 

它是什么,我做错了什么?

回答

1

首先,您不能在顶层文件中使用apply插件。
然后删除此行

apply plugin: 'com.android.application' 

使用这个库在你的项目是导入它作为一个行家不依赖本地克隆代码的最好方法。

compile 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.7.4' 

你应该有这样的结构:

root 
    app 
    build.gradle 
    build.gradle 
    settings.gradle 

settings.gradle

include ':app' 

在顶级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:1.3.0' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

app/build.gradle

apply plugin: 'com.android.application' 

android { 
    defaultConfig { 
     //.... 
    } 

    //.... 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 

    //Add the library 
    compile 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.7.4' 
} 
+0

好吧,我加了他们试图解决这个错误。我现在删除它们,但我仍然得到相同的错误 –

+1

@A_Matar检查更新的答案。一定要使用gradle版本2.4+。 –

+0

你是如何得到这一行的:com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.7.4我希望能够在将来为我自己的任何库格式化它 –

0

这是不是为OP的答案,但可使用他人谁得到的错误

Gradle DSL method not found: 'apply()' 

在我的情况下,问题竟然是的build.gradle的编码文件。我在文本编辑器中编辑了文件,并保存为UTF-8-BOM,Gradle显然不接受。因此,解决方案仅仅是以ANSI或UTF-8(无BOM)编码重新保存文件。

相关问题