2014-06-27 16 views
39

Tôi đang cố gắng sử dụng CardView mới từ Android L. tôi cập nhật tất cả mọi thứ trong bộ quản lý SDK, nhưng tôi tiếp tục nhận được lỗi sau:Không [INSTALL_FAILED_OLDER_SDK] Android-L

Failure [INSTALL_FAILED_OLDER_SDK]

Đây là build.gradle của tôi file:

apply plugin: 'android' 

android { 
    compileSdkVersion 'android-L' 
    buildToolsVersion '20.0.0' 

    defaultConfig { 
     applicationId "www.thomascbeerten.com.nieuwetests" 
     minSdkVersion 8 
     targetSdkVersion 20 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      runProguard false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    // Support Libraries 
    compile 'com.android.support:support-v4:19.1.0' 
    compile 'com.android.support:appcompat-v7:19.1.0' 
    compile 'com.android.support:gridlayout-v7:19.1.0' 
    compile 'com.android.support:mediarouter-v7:19.1.0' 
    // compile 'com.android.support:support-v13:19.1.0' 
    compile 'com.android.support:recyclerview-v7:+' 
} 

Trả lời

54

Recently there was a post here regarding the L SDK's incompatibility with prior versions of Android. I've been digging in AOSP repositories for quite a few hours now, and determined that the tools behave this way because they are designed to treat preview platforms differently. If you compile against a preview SDK (android-L), the build tools will lock minSdkVersion and targetSdkVersion to that same API level. This results in the produced application being unable to be installed on devices running older releases of Android, even if your application isn't doing anything specific to L. To make matters worse, the new support libs (CardView, RecyclerView, Palette, etc.) are also locked into the L API level, even though--according to their repository names--they should work on API level 7 just fine (and they do!).

Xem bài Reddit tôi về here này, với một workaround.

+0

Cảm ơn bài viết tuyệt vời! Bây giờ tôi hoàn toàn hiểu :) – TomCB

+26

Trong khi câu trả lời này về mặt lý thuyết có thể trả lời câu hỏi, [nó là tốt hơn] (http://meta.stackexchange.com/a/8259/237685) để bao gồm các phần thiết yếu của câu trả lời ở đây, và cung cấp liên kết để tham khảo. – hichris123

+0

vì vậy bạn nên làm theo hướng dẫn tại http://www.reddit.com/r/androiddev/comments/297xli/howto_use_the_v21_support_libs_on_older_versions/ và bạn sẽ có thể cài đặt trên các thiết bị cũ hơn cùng lúc khi biên dịch bằng Android L – Gabor

5

Khi bạn đã giải quyết các vấn đề trên như đã đề cập bởi Eddie. Bạn cũng có thể gặp phải một lỗi khác ;;

Error:Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light'. 

Điều này sẽ có trong tệp styles.xml của bạn. Việc sửa chữa nhanh chóng là để thay thế nó với những điều sau đây:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<!--<style name="AppTheme" parent="android:Theme.Material.Light">--> 
<style name="AppTheme" parent="android:Theme.Holo.Light"> 
</style> 

0

Khi bạn biên dịch với L nó thực sự làm cho một sự thay đổi trong quá trình biên soạn thiết minSdkVersion của bạn để L. Nếu bạn muốn sử dụng RecyclerView hoặc CardView tôi khuyên bạn nên kiểm tra số RecyclerViewLib. RecyclerView và CardView đã được chuyển vào thư viện này để không có vấn đề L phiên bản min. Tác giả cũng đã giải thích trong số blog post cách tất cả các mã liên quan đến L đã được xóa để sử dụng an toàn.

Để thêm RecyclerViewLb để dự án của bạn chỉ cần thêm dòng sau vào phụ thuộc của bạn trong tập tin build.gradle của bạn:

compile 'com.twotoasters.RecyclerViewLib:library:[email protected]' 

Sau đó, bạn không muốn thêm compile 'com.android.support:recyclerview-v7:+' để build.gradle của bạn như bạn sẽ nhận được thông qua RecyclerViewLib.

2

Thay đổi

android { 
    compileSdkVersion 'android-L' 
    buildToolsVersion '20.0.0' 

để

android { 
    compileSdkVersion 21 
    buildToolsVersion '21.0.2' 

Note android-L là trong dấu nháy đơn nhưng 21 thì không. 21 là một số nguyên chứ không phải là một chuỗi.

0

Tôi vừa gặp sự cố này. Điều này có thể xảy ra khi phiên bản sdk tối thiểu và mục tiêu được tạo của bạn được đặt thành phiên bản API/HĐH cao hơn so với điện thoại của bạn đang chạy. Nếu bạn đang sử dụng Android Studio, hãy chuyển đến Tệp> Cấu trúc dự án> và chỉnh sửa cài đặt relavent rồi chạy lại.

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