No resource found that matches the given name '

2019-02-07 19:51发布

问题:

I try to change my HelloWorld Application holo theme to Material.Light.DarkActionBar theme(As said by What's new Android Development tools session). But I got following error. I try to change target SDK version is 21. But We didn't have 21 SDK in SDK Manager. In that session,they said,set style xml for v-21.

values/styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

</resources>

values-v21/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    !-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>
</resources>

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

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

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

Error:

Error:Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light.DarkActionBar'.
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Applications/Android Studio.app/sdk/build-tools/android-4.4W/aapt package -f --no-crunch -I /Applications/Android Studio.app/sdk/platforms/android-20/android.jar -M /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/intermediates/manifests/debug/AndroidManifest.xml -S /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/intermediates/res/debug -A /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/intermediates/assets/debug -m -J /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/generated/source/r/debug -F /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/intermediates/libs/app-debug.ap_ --debug-mode --custom-package com.ramapps.helloworld -0 apk
  Error Code:
    1
  Output:
    /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/intermediates/res/debug/values-v21/values.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light.DarkActionBar'.

回答1:

You can try to set the values in the build.gradle like this (updated for API 25):

android {
  compileSdkVersion 25
  buildToolsVersion "25.0.3"
  defaultConfig {
    minSdkVersion 21 //oldest version you would like to support
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    ...
  }
}


回答2:

We can not install apps that target L Preview on anything but L devices.

Changing res/values/styles.xml, Theme.Material.Light to Theme.Light and following build.gradle worked for me.

android {
    compileSdkVersion 20
    buildToolsVersion '20.0.0'
    defaultConfig {
        applicationId 'com.example.android.market.licensing'
        minSdkVersion 13
        targetSdkVersion 20
        versionCode 1
        versionName '1.0'
    }

Although Theme.Material.Light is part of the 20sdk version but somehow it is not working for me.



回答3:

Set Target of Your Application to API Level 21 from AssemblyMenifest.xml or add <uses-sdk android:targetSdkVersion="21" android:minSdkVersion="19" /> tag to your AssemblyMenifest.xml



回答4:

I changed Theme.Material.Light to Theme.Light and it worked for me.



回答5:

I think the problem here is that you need to set your buildToolsVersion to pre Android L version.

Here my gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        applicationId "com.mayuonline.ribbit"
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    // You must install or update the Support Repository through the SDK manager to use this dependency.
    compile 'com.android.support:support-v13:19.+'
}

Also make sure to change the styles.xml as below

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

This should resolve the problem.