1

I am fighting against Android and compatibility library AppCompat and I am loosing. I come here crying for help.

Since I would like to use a NavigationDrawer (using the code automatically generated by Android Studio) I have to start using the AppCompat library. My app does not work any more because the builder cannot find the theme AppCompat.

I followed all the steps here: https://developer.android.com/tools/support-library/setup.html#add-library

This is the gradle file "Module:app":

apply plugin: 'com.android.application'

android {
  compileSdkVersion 19
  buildToolsVersion "19.1"

  defaultConfig {
    applicationId "it.misc.application"
    minSdkVersion 19
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}
 buildTypes {
      release {
         minifyEnabled false
         proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      }
      debug {
          debuggable true
      }
  }
} 

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   compile 'com.android.support:appcompat-v7:21.0.3'
   compile project(':another-library-here.')
}

And this is the res/values/style.xml

<resources>

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

</resources>

The error is:

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

Since I did everything the doc says and I also removed/reinstalled the compatibility library as suggested in an answer to another StackOverflow question, I do not know what else I could try.

Could it be related to the fact that I am using API and build tools ver. 19 and the the Android Support Library 21.0.3? (I think not, but ...)


This is the new gradle, but building keeps failing:

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.2"
    defaultConfig {
        applicationId "it.autostradetech.orchestra.negoziante"
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile project(':orchestra.autostradetech.it.')
}

Nothing changes if I set minSdkVersion to 14, 7, 8, or any other random number.

Antonio Sesto
  • 2,868
  • 5
  • 33
  • 51
  • Have you tried instead of `parent="android:Theme.AppCompat.Light.DarkActionBar"` use `parent="Theme.AppCompat.Light.DarkActionBar"` – Marcus Feb 16 '15 at 12:18
  • @Marcus Yes I tried changing that value with all the possibilities I could think of. – Antonio Sesto Feb 16 '15 at 12:38

4 Answers4

3

It's not android:Theme.AppCompat just Theme.AppCompat. Only resources from framework have the prefix.

Also change the compile SDK version to 21. The support library version, target SDK and compile SDK versions should correspond.

Eugen Pechanec
  • 37,669
  • 7
  • 103
  • 124
  • Thanks. Now it finds the theme. I have only 100 other parents who went missing. I accepted this job after years of developing with iOS and I thought I would have found a similar platform: I was wrong. – Antonio Sesto Feb 16 '15 at 13:14
  • Yes, read the edit please. After that do a clean build and you should be good to go. – Eugen Pechanec Feb 16 '15 at 13:15
  • Yes, it worked. Thanks: I owe you a beer. I don't know how that android: ended up there. – Antonio Sesto Feb 16 '15 at 13:26
1

Try changing compileSdkVersion and targetSdkVersion to 21, and change this in your Project Settings also. If you really want to use the appcompat-v7 library, then I suppose minSdkVersion should be at least 14.

EDIT: And it needs to be Theme.AppCompat.Light.DarkActionBar, not android:Theme.AppCompat.Light.DarkActionBar.

Yash Sampat
  • 30,051
  • 12
  • 94
  • 120
  • As a software requirement, I need to implement an app that works on Android 4.4 - I don't think I can use API 21. Or can I? – Antonio Sesto Feb 16 '15 at 12:26
  • 1
    @AntonioSesto: A `targetSdkVersion` of 21 will work on Android 4.4. The `targetSdkVersion` needs to be always 21 from now on because the new version of the `appcompat` library *must* be compiled against API 21. Projects that use this new library version also do not compile unless linked with API 21. – Yash Sampat Feb 16 '15 at 12:32
  • I modified the script according to your instructions, but the build fails. Nothing changes if I set minSdkVersion to 14. – Antonio Sesto Feb 16 '15 at 12:56
  • I just realized the problem. Please see the edited answer. And by the way, you do need to set `targetSdkVersion` and `compileSdkversion` as 21. – Yash Sampat Feb 16 '15 at 13:25
1

Replace:

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

with:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
  <!-- Customize your theme here. -->
</style>
Xcihnegn
  • 11,579
  • 10
  • 33
  • 33
0

Try this solution as suggested in this question.

  1. File->Import (android-sdk\extras\android\support\v7). Choose "appcompat"
  2. Project-> properties->Android. In the section library "Add" and choose "appCompat"
Community
  • 1
  • 1
Marcus
  • 6,697
  • 11
  • 46
  • 89
  • If I select File-> Import Module and I go to the location you said, the import fails because it does not find the file types it requires. – Antonio Sesto Feb 16 '15 at 12:50
  • Have you downloaded the support library [using the SDK manager?](https://developer.android.com/tools/support-library/setup.html#download) @AntonioSesto – Marcus Feb 16 '15 at 12:55
  • Yes, I did. I did step-by-step what Google says in the instructions (link in the question) -- I am using Android Studio. – Antonio Sesto Feb 16 '15 at 12:57