Resolving appcompat-v7:21.0.0 Resource Matching Error: android:actionModeShareDrawable

Nov 20, 2025 · Programming · 11 views · 7.8

Keywords: Android Development | appcompat-v7 | Resource Matching Error | compileSdkVersion | Android 5.0 | Gradle Configuration

Abstract: This article provides an in-depth analysis of the common appcompat-v7:21.0.0 resource matching error in Android development, focusing on the root cause of the missing 'android:actionModeShareDrawable' attribute. Through systematic solutions, it details how to correctly configure the compilation target version in three mainstream development environments: Android Studio, Eclipse, and IntelliJ IDEA, ensuring compatibility between the support library and Android 5.0 Lollipop API. The article also offers complete configuration examples and best practice recommendations to help developers thoroughly resolve such resource reference errors.

Problem Background and Error Analysis

During Android application development, resource matching errors frequently occur when using the appcompat-v7 support library. Specifically, the build process displays the error message "No resource found that matches the given name: attr 'android:actionModeShareDrawable'". This error typically appears at line 36 in the values-v11/values.xml file, indicating that the system cannot locate the specified Android attribute resource.

From a technical perspective, android:actionModeShareDrawable is a new attribute introduced in Android 5.0 Lollipop (API level 21), used to define the share icon in action mode. When developers use the appcompat-v7:21.0.0 support library in their projects but set the compilation target version below API 21, resource reference failures occur. This happens because the support library attempts to reference attributes defined in higher API versions, while the current compilation environment cannot provide these resource definitions.

Environment Preparation and Prerequisites

Before resolving this issue, it is essential to ensure the development environment is correctly configured. First, download the latest extras components and Android 5.0 SDK via the Android SDK Manager. A complete development environment should include:

// Check if SDK components are complete
Android SDK Tools (latest version)
Android SDK Platform-tools
Android SDK Build-tools
Android 5.0 (API 21) SDK Platform
Android Support Repository
Android Support Library

The completeness of the environment configuration directly affects the effectiveness of subsequent solutions. If necessary SDK components are missing, other related compilation errors may still occur even after modifying project configurations.

Android Studio Solution

For projects using Android Studio and the Gradle build system, the solution is relatively straightforward. Modify the build.gradle file of the application module to set compileSdkVersion to 21. Although technically not absolutely necessary to change targetSdkVersion, following Android development best practices, it is recommended to update targetSdkVersion to 21 as well, ensuring the application can fully utilize the features of the latest APIs.

Specific configuration modification example:

android {
    compileSdkVersion 21
    
    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

After completing the configuration modifications, Gradle project synchronization must be performed. In Android Studio, this can be done by clicking the "Sync Project with Gradle Files" button or selecting File > Sync Project with Gradle Files from the menu. This step ensures the Gradle build system re-parses the project configuration and applies the new compilation settings.

Eclipse Development Environment Configuration

When using the appcompat-v7 support library in the Eclipse environment, special attention is required. Simply copying the jar file to the libs directory is insufficient. The support library must be imported into the workspace as a library project. This process includes the following key steps:

First, import the appcompat library project via File > Import > Android > Existing Android Code into Workspace. After import, mark it as a library project in the project properties (Properties > Android > check "Is Library"). Then add a reference to this library project in the main project (Properties > Android > Library > Add).

After configuring the library project, resource errors are typically found in folders such as values-v11, values-v14, and values-v21 under the res directory. These errors include:

error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material'.
error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.*'.
error: Error: No resource found that matches the given name: attr 'android:actionModeShareDrawable'.

The key to resolving these errors lies in modifying the project.properties file of the android-support-v7-appcompat project. Change the original target=android-19 to target=android-21. This modification tells Eclipse to use the Android 5.0 SDK to compile the support library project, thereby correctly parsing resources and styles defined in higher API versions.

After making the changes, execute Project > Clean to clean the project and rebuild. This step ensures Eclipse recompiles all resource files and applies the new target platform settings.

IntelliJ IDEA Configuration Method

For IntelliJ IDEA projects not using Gradle, the configuration process is similar to Eclipse. First, the appcompat support library must be imported as a module, not just relied upon as a jar file. If only the jar file is used, NoClassDefFoundError exceptions will occur at runtime because the resource files included in the support library cannot be correctly loaded via the jar method.

After importing the support library module, resource errors similar to those in Eclipse will be encountered during the build process:

Error:android-apt-compiler: [appcompat] resource found that matches the given name: attr 'android:colorPrimary'.
Error:(75, -1) android-apt-compiler: [appcompat] C:\[Your Path]\sdk\extras\android\support\v7\appcompat\res\values-v21\styles_base.xml:75: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton'.

The solution is to configure dependencies through module settings: Right-click the appcompat module > Open Module Settings (F4) > In the Dependencies tab, select Android API 21 Platform from the dropdown menu. After applying the settings, execute Build > Rebuild Project to rebuild the entire project.

Root Cause and Technical Principles

Understanding the root cause of this issue helps prevent similar problems. The design of the Android support library allows developers to use features of higher API versions on lower-version devices. This is achieved through resource aliasing and style inheritance mechanisms. When the support library references high-version attributes like android:actionModeShareDrawable, it expects the compilation environment to provide definitions for these attributes.

In technical implementation, the support library defines styles and attribute references for Android 5.0 in the values-v21 directory. When the compilation target version is below 21, the Android build tools cannot parse these high-version resources, leading to compilation errors. This is the fundamental reason why the compilation target must be set to API 21 or higher.

Best Practices and Preventive Measures

To avoid similar compatibility issues, developers are advised to follow these best practices:

Keep SDKs and development tools updated regularly; check and install the latest Android SDK components periodically. Clearly define the target API level during project planning to ensure compatibility of all dependent libraries. When using the Gradle build system, properly configure the relationship between minSdkVersion, targetSdkVersion, and compileSdkVersion:

// Recommended version configuration strategy
minSdkVersion 14    // Support as many devices as possible
targetSdkVersion 21 // Optimize for the latest API
compileSdkVersion 21 // Compile using the latest API

Regularly check project dependencies to ensure consistency of all support library versions. In team development environments, establish unified development environment configuration standards to avoid build issues caused by environmental differences.

Extended Knowledge and Related Technologies

In addition to the actionModeShareDrawable attribute, Android 5.0 Lollipop introduced numerous new Material Design-related attributes. Understanding the purposes of these attributes and methods for handling compatibility is crucial for modern Android development. Common Material Design attributes include:

android:colorPrimary
android:colorPrimaryDark
android:colorAccent
android:statusBarColor
android:navigationBarColor

These attributes have corresponding compatibility implementations in the appcompat support library, enabling developers to achieve Material Design visual effects on lower-version Android devices. Understanding the resource mapping mechanisms and style inheritance systems of the support library helps resolve similar compatibility issues more effectively.

Through systematic environment configuration and correct project settings, developers can fully leverage the powerful features of the Android support library while avoiding common resource reference errors. This problem-solving approach also applies to other types of Android development compatibility issues.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.