Can I use the latest version of the appcompat library with a project that is targeting sdk 21

独自空忆成欢 提交于 2019-12-11 10:26:54

问题


I dont know much about this appcompat library so apologies if this isnt the smartest question.

I have a project that i was having a problem with. Turns out i had the targetSdkVersion set to 23 and it was causing me a problem since i wanted to use 21. So I changed it to 21.

In my build.gradle I have compile com.android.support:appcompat-v7:23.1.1.

And this causes the following problems when i try to build:

C:\Users\Conor\Documents\Programming\AndroidStudioProjects\AndroidStudioProjects\RouteTracker\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.1.1\res\values-v23\values-v23.xml

Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.

Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'. Error:Execution failed for task ':app:processDebugResources'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\Conor\AppData\Local\Android\sdk\build-tools\21.0.0\aapt.exe'' finished with non-zero exit

So I tried to use appcompat of com.android.support:appcompat-v7:21.1.0 (as it was the only one i could definitively find), but it didnt work either. Says it couldnt find it and tells me to use the latest version, which is 23.1.1.

So should I be using 23.1.1? If so, any ideas what these errors are about?


回答1:


Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.

It happens because you are using the support libraries v23 which require to compile with API 23.

Change in your build.gradle this line:

compileSdkVersion 23

You can use another version of the support library but:

  • pay attention to have another dependencies which use a latest version
  • the 21.1.0 doesn't exist
  • use the right api to compile

Here the full list:

  //it requires compileSdkVersion 23
  compile 'com.android.support:appcompat-v7:23.1.1'
  compile 'com.android.support:appcompat-v7:23.1.0'
  compile 'com.android.support:appcompat-v7:23.0.1'
  compile 'com.android.support:appcompat-v7:23.0.0'

  //it requires compileSdkVersion 22
  compile 'com.android.support:appcompat-v7:22.2.1'
  compile 'com.android.support:appcompat-v7:22.2.0'
  compile 'com.android.support:appcompat-v7:22.1.1'
  compile 'com.android.support:appcompat-v7:22.1.0'
  compile 'com.android.support:appcompat-v7:22.0.0'

  //it requires compileSdkVersion 21
  compile 'com.android.support:appcompat-v7:21.0.3'
  compile 'com.android.support:appcompat-v7:21.0.2'
  compile 'com.android.support:appcompat-v7:21.0.0'



回答2:


No. AppCompat latest update remove some old dependencies. This is only available with v23. So, You have to update your code with targetSdkVersion 23.(marshmallow).




回答3:


You have got your solution but the answer to your questions 'Can I use the latest version of the appcompat library with a project that is targeting sdk 21' is as follows. Project lib should be compatible with 'compileSdkVersion' & not necessarily with targetSdkVersion. Ideally your compileSdkVersion & targetSdkVersion would be same but if your requirement is to target lower targetSdkVersion then you can keep it lower than compileSdkVersion.



来源:https://stackoverflow.com/questions/34624808/can-i-use-the-latest-version-of-the-appcompat-library-with-a-project-that-is-tar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!