2014-11-09 21 views
13

Tôi đang làm việc trên một dự án Android, sử dụng Gradle như được đề cập bên dưới.Không tìm thấy phương pháp DSL Gradle: "classpath()"

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:0.12.+' 
    } 
} 

allprojects { 
    repositories { 
     mavenCentral() 
    } 
} 

dependencies { 
    classpath 'com.android.tools.build:gradle:0.12.+' 
    compile fileTree(dir: 'libs', include: '*.jar') 
    compile project(':workspace:darkmoon:darul-android:vitamio:vitamio') 
    compile project(':Dev:adt-bundle-mac-x86_64:sdk:extras:google:google_play_services:libproject:google-play-services_lib') 
} 

android { 
    compileSdkVersion 19 
    buildToolsVersion "20.0.0" 

    sourceSets { 
     main { 
      manifest.srcFile 'AndroidManifest.xml' 
      java.srcDirs = ['src'] 
      resources.srcDirs = ['src'] 
      aidl.srcDirs = ['src'] 
      renderscript.srcDirs = ['src'] 
      res.srcDirs = ['res'] 
      assets.srcDirs = ['assets'] 
     } 

     // Move the tests to tests/java, tests/res, etc... 
     instrumentTest.setRoot('tests') 

     // Move the build types to build-types/<type> 
     // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... 
     // This moves them out of them default location under src/<type>/... which would 
     // conflict with src/ being used by the main source set. 
     // Adding new build types or product flavors should be accompanied 
     // by a similar customization. 
     debug.setRoot('build-types/debug') 
     release.setRoot('build-types/release') 
    } 
} 

Nhưng khi tôi xây dựng nó, tiếp tục nhận được lỗi này: "Phương pháp DSL Gradle không tìm thấy", và nó chỉ vào sau dòng:

dependencies { 
    classpath 'com.android.tools.build:gradle:0.12.+' 
    compile fileTree(dir: 'libs', include: '*.jar') 
    compile project(':workspace:epsilonmobile:darul-android:vitamio:vitamio') 
    compile project(':Dev:adt-bundle-mac-x86_64:sdk:extras:google:google_play_services:libproject:google-play-services_lib') 
} 

Apologize nếu câu hỏi này là một chút Noob , Tôi mới sử dụng cả Gradle và Android Studio

Trả lời

14

Cấu hình classpath chỉ khả dụng cho phụ thuộc buildscript. Bạn cần phải loại bỏ dòng classpath 'com.android.tools.build:gradle:0.12.+' trong khối dependencies cấp cao nhất. (Gradle plugin cần phải được khai báo dưới buildscript { dependencies { ... } }.)

4

Trong một kịch bản gradle, các buildscript là một đặc biệt phần nơi bạn có thể tuyên bố sự phụ thuộc của xây dựng kịch bản riêng của mình (ví dụ: mã nhị phân theo yêu cầu của quá trình xây dựng).

Quy trình xây dựng gradle là không có gì hơn là một quá trình java và do đó nó hỗ trợ phụ thuộc classpath bình thường.

com.android.tools.build:gradle:0.12.+ xác định nhị phân theo yêu cầu của quá trình xây dựng (nó chứa mã có thể hiểu/thực hiện phần android của tập lệnh xây dựng).

Gói ứng dụng Android sẽ được tạo bởi tập lệnh này không cần mã nhị phân com.android.tools.build:gradle:0.12.+ để chạy trên thiết bị Android của bạn (tức là gói ứng dụng tất nhiên đã được tạo khi chạy trên thiết bị): không có lý do nào để khai báo nó một lần nữa trong các phụ thuộc cấp cao nhất (đó là những phụ thuộc theo yêu cầu của ứng dụng của bạn)

Các vấn đề liên quan