2014-06-11 36 views
11

Tôi có một dự án mà tôi muốn định cấu hình trên máy tính của mình.Android Studio bỏ qua cờ thư viện -core

On anothe máy tính nó hoạt động, nhưng với phiên bản cũ của Android Studio 0.4.0 bất cứ khi nào tôi sử dụng 0.5.2

Các proble là sau khi tôi khởi động ứng dụng đó hiển thị lỗi

Build script error, unsupported Gradle DSL method found: 'coreLibrary()'! Possible causes could be:
- you are using Gradle version where the method is absent - you didn't apply Gradle plugin which provides the method - or there is a mistake in a build script

Nhưng trong để làm cho nó hoạt động, tôi phải sử dụng lá cờ này! Tôi đã cố gắng để kích hoạt nó trong phần cài đặt> biên dịch Android> "Add --core-thư viện" lá cờ, nhưng nó vô dụng ...

trong gradle tôi có phần tiếp theo của mã:

dexOptions { 
    coreLibrary true; 
} 

Lỗi này chỉ hiển thị sau khi kích hoạt dòng này ... Nếu không có nó, nó không hoạt động ...

LÀM THẾ NÀO ĐỂ TÔI CỐ ĐỊNH NÀY? Có lẽ đó là vì các phiên bản khác nhau .. nếu có thì làm thế nào tôi nên viết để làm cho nó hoạt động?

Sau khi thay đổi để coreLibrary = true Nó compilate Gradle tốt nhưng stille yêu cầu sau Run --core-thư viện cờ sử dụng .... Nhưng tôi đã thiết lập nó là true trong cài đặt ...

Nó không cho thấy hầu hết các lỗi tương tự:

Error:Execution failed for task ':BusKg:preDexDebug'. 
> com.android.ide.common.internal.LoggedErrorException: Failed to run command: 
    D:\Programms\Programms\adt-bundle-windows-x86_64-20131030\sdk\build-tools\android-4.4\dx.bat --dex --output D:\Android2\BUS.kg\marshrutka\BusKg\build\pre-dexed\debug\annotations-api-6.0.26-27e56569b50edbdd453f9bc0e568cde1fbfa621b.jar C:\Users\Viacheslav\.gradle\caches\modules-2\files-2.1\org.apache.tomcat\annotations-api\6.0.26\50aeafa144ed17913ed44d18ac61afd505a9e3e\annotations-api-6.0.26.jar 
Error Code: 
    1 
Output: 
    trouble processing "javax/xml/ws/WebServiceRef.class": 
    Ill-advised or mistaken usage of a core class (java.* or javax.*) 
    when not building a core library. 
    This is often due to inadvertently including a core library file 
    in your application's project, when using an IDE (such as 
    Eclipse). If you are sure you're not intentionally defining a 
    core class, then this is the most likely explanation of what's 
    going on. 
    However, you might actually be trying to define a class in a core 
    namespace, the source of which you may have taken, for example, 
    from a non-Android virtual machine project. This will most 
    assuredly not work. At a minimum, it jeopardizes the 
    compatibility of your app with future versions of the platform. 
    It is also often of questionable legality. 
    If you really intend to build a core library -- which is only 
    appropriate as part of creating a full virtual machine 
    distribution, as opposed to compiling an application -- then use 
    the "--core-library" option to suppress this error message. 
    If you go ahead and use "--core-library" but are in fact 
    building an application, then be forewarned that your application 
    will still fail to build or run, at some point. Please be 
    prepared for angry customers who find, for example, that your 
    application ceases to function once they upgrade their operating 
    system. You will be to blame for this problem. 
    If you are legitimately using some code that happens to be in a 
    core package, then the easiest safe alternative you have is to 
    repackage that code. That is, move the classes in question into 
    your own package namespace. This means that they will never be in 
    conflict with core system classes. JarJar is a tool that may help 
    you in this endeavor. If you find that you cannot do this, then 
    that is an indication that the path you are on will ultimately 
    lead to pain, suffering, grief, and lamentation. 
    1 error; aborting 

Cảm ơn trước sự giúp đỡ nào ...

+0

Bạn có chắc chắn muốn thực hiện việc này không? Thông báo lỗi này có vẻ khá nghiêm trọng. –

+0

Vâng ... tôi muốn ít nhất là để khởi động dự án và sau đó cố gắng sửa lỗi này ... Nhưng tiếc là tôi thậm chí không biết làm thế nào để kích hoạt lõi thư viện này – kimslava93

+0

Nếu bạn chưa hiểu sâu những gì đang diễn ra trên và BIẾT rằng bạn cần lá cờ này vì một lý do rất cụ thể, sau đó bạn có thể không cần nó. Đặc biệt, WebServiceRef là một chú thích cho các dịch vụ web J2EE, mà hầu như không có chỗ trong một ứng dụng Android. Tôi nghĩ rằng những gì bạn đang cố gắng làm có lẽ không có ý nghĩa gì trong Android. –

Trả lời

-4

cú pháp để xác định giá trị dexOptions là khác nhau; bạn cần một dấu bằng:

dexOptions { 
    coreLibrary = true; 
} 
+0

Xin cảm ơn! nó giúp trong việc biên soạn gradle! nó không hiển thị lỗi về coreLibrary không được hỗ trợ! NHƯNG nó vẫn yêu cầu sử dụng --core-library ... – kimslava93

+0

Bạn có chắc rằng Gradle thực sự hỗ trợ cờ này? Tôi không thấy bất kỳ tài liệu nào về nó. –

+0

Tôi thực sự không chắc chắn ... nhưng tôi đã thêm bên dưới câu hỏi của tôi những gì nó hiển thị ... và vì nó đã sẵn sàng dự án ... nhà phát triển trước đó cho biết tôi sử dụng nó ... – kimslava93

0

Tôi đã giải quyết được vấn đề này! Thật không may, tôi đã giải quyết nó chỉ bằng cách cài đặt phiên bản Android Studio 0.4.2 .... Các phương pháp khác không giúp được ... Có lẽ, sau này, tốt hơn là định cấu hình dự án cho phiên bản Android Studio mới.

1

Hi Tôi có cùng một vấn đề và tôi giải quyết nó bằng cách chọn hộp "Thêm --core-thư viện" trong/Preferences/biên dịch/Android Trình biên dịch

+0

Lỗi: Không thể hoàn thành việc thực thi Gradle. Nguyên nhân: Tùy chọn dòng lệnh không xác định '--core-library'. –

2

Tôi nghĩ rằng chúng ta không thể cho phép --core-library qua dexOptions.

Chúng tôi biết rằng dexOptions được giao cho đối tượng com.android.build.gradle.internal.dsl.DexOptions, thực hiện com.android.builder.core.DexOptions.

Từ mã nguồn, chúng tôi biết nó không hỗ trợ --core-library.

Từ Issue 79280: dexOptions in gradle plugin don't support coreLibrary

You can do it manually by

  • disable pre-dexing (this is because our cache would have issues if we allow adding extra params)
  • modify the Dex tasks to add --core-library as an extra parameters.
-1

Bạn sẽ phải loại trừ các thư viện mà đang gây ra vấn đề này. Ví dụ: -

compile('org.simpleframework:simple-xml:2.7.+'){ 
    exclude module: 'stax' 
    exclude module: 'stax-api' 
    exclude module: 'xpp3' 
} 
5

Trong Android Studio 1.1.0, điều hướng tới:

File -> Other Settings -> Default Settings -> Trình biên dịch -> Android Trình biên dịch

Bạn sẽ tìm thấy hộp kiểm để Add "--core-thư viện" cờ , nhưng điều này dường như không hoạt động.

Thay vì chỉnh sửa ứng dụng tập tin/build.gradle

Vô hiệu hóa trước Dexing bên android {} sử dụng

dexOptions { 
    preDexLibraries = false 
} 

và sửa đổi Dex task sử dụng

project.tasks.withType(com.android.build.gradle.tasks.Dex) { 
    additionalParameters=['--core-library'] 
} 

giải quyết vấn đề.

Edit: nội dung đầy đủ của ứng dụng/build.gradle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 21 
    buildToolsVersion "21.1.2" 

    defaultConfig { 
     applicationId "appId" 
     minSdkVersion 19 
     targetSdkVersion 21 
     versionCode 1 
     versionName "1.0" 
     multiDexEnabled true 
    } 

    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 

    dexOptions { 
     preDexLibraries = false 
     javaMaxHeapSize "4g" 
    } 

    project.tasks.withType(com.android.build.gradle.tasks.Dex) { 
     additionalParameters=['--core-library'] 
    } 

    packagingOptions { 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/MANIFEST.MF' 
     exclude 'META-INF/DEPENDENCIES' 
     exclude 'META-INF/LICENSE.txt' 
     // more exclude files here if conflicts 
    } 
} 
+0

bạn có thể chỉ hiển thị tệp 'AndroidManifest.xml' đang hoạt động không? – 4ntoine

+0

Thay đổi không có trong AndroidManifest.xml nhưng trong app/build.gradle. Cập nhật câu trả lời với nội dung của tệp. –

+3

Không còn hoạt động trong AndroidStudio 1.5 –

11
project.tasks.withType(com.android.build.gradle.tasks.Dex) { 
    additionalParameters=['--core-library'] 
} 

không hoạt động đúng, và nhận được lỗi:

Không thể lấy tài sản vô danh 'com' cho đối tượng của loại com.android.build.gradle.AppExtension.

Tôi giải quyết sự cố bằng cách thêm khối này vào khối android.

dexOptions { 
    preDexLibraries = false 
    additionalParameters=['--core-library'] 
} 

Hy vọng điều này hữu ích cho bạn!

+0

dexOptions chỉ với các tham số bổ sung làm việc cho tôi. Cảm ơn – Sriram

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