217

Why does Eclipse automatically add appcompat v7 library support whenever I create a new project?

I am creating a simple project whose MainActivity should extend Activity, but it does not. Eclipse automatically adds action bar support.

How do I create a simple project without the appcompat library? FYI, I have downloaded the latest version of ADT with everything updated recently. I am using Window 7 x64.

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Talha Q
  • 4,350
  • 4
  • 28
  • 40

10 Answers10

105

As stated in Android's Support Library Overview, it is considered good practice to include the support library by default because of the large diversity of devices and the fragmentation that exists between the different versions of Android (and thus, of the provided APIs).

This is the reason why Android code templates tools included in Eclipse through the Android Development Tools (ADT) integrate them by default.

I noted that you target API 15 in your sample, but the miminum required SDK for your package is API 10, for which the compatibility libraries can provide a tremendous amount of backward compatible APIs. An example would be the ability of using the Fragment API which appeard on API 11 (Android 3.0 Honeycomb) on a device that runs an older version of this system.

It is also to be noted that you can deactivate automatic inclusion of the Support Library by default.

Halim Qarroum
  • 13,985
  • 4
  • 46
  • 71
  • 54
    Well thats BS. I've been using eclipse at API level 10 for the past 2 months and its never imported the compatability library or a fragment layout until this freaking kitkat api came out. It seems at this point the simplest way to stop it appearing is not to create an Activity automatically. So you'll have to untick "create activity" and create your own when the project has been created. – user3223214 Mar 09 '14 at 13:52
  • here i have tried with min sdk version more then 11,but this library auto created again – Jay Vyas Mar 10 '14 at 12:46
  • 2
    Yeah, that's the point, the library will always be included because of the above reasons. – Halim Qarroum Mar 10 '14 at 15:27
  • And if we want to use Actionbar Sherlock? What this support lib v7 will mean for us? – Vasil Valchev Mar 29 '14 at 21:28
  • 1
    Well, the support library does provide backward compatibility for numerous components of the Android SDK. Not only for the ActionBar. You can find a whole bunch of supported APIs in the latest version of the support library. You might want to take a look at http://developer.android.com/tools/support-library/index.html for further details. – Halim Qarroum Mar 30 '14 at 01:32
  • 1
    Is it better to avoid the app_compat? – Broskiee Feb 22 '15 at 02:26
  • 2
    Jeez google!!! quit patching and patching and patching, all these bunch of supportLibrary errors and versions are driving us nuts. – Josh Jul 20 '15 at 09:44
59

Create a new Android Application Project and uncheck Create activity in step two (Configure project).

030
  • 10,842
  • 12
  • 78
  • 123
songhir
  • 3,393
  • 3
  • 19
  • 27
  • Thanks But `menu` folder wasn't created in my project. – Stephen Jul 01 '14 at 04:59
  • 1
    Deleting appcompat_v7 project from my workspace and creating a new android project by unchecking 'Create activity' option did the trick for me. Things specified in other answers didn't work for me. Thanks. – Srinivasan N Feb 25 '15 at 11:55
22

Why my eclipse automatically adds appcompat v7 library support whenever i create a new project

Because your target SDK is set to 15, in which the Action Bar is on by default and your minimum supported SDK is set to 10. Action Bar come out in 11, so you need a support library, Eclipse adds it for you. Reference.

You can configure project libraries in the build path of project properties.

Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110
  • 12
    If i configure the minimum sdk as 12 or 13 I still get the same behavior from eclipse... – mikey May 08 '14 at 00:58
18

Eclipse automatically created the appcompat_v7.Because of Kitkat Api launched itself it adds automatically appcompat_v7 and fragment_main.xml.

Best ways to solve these:

  1. Firstly in project,Right click->properties->Android.There you can see the red marked appcompat placed in Reference. Click that and Remove it.Then Tick the right target name in Project Build Target.

  2. Delete fragment_main.xml and Appcompat file created in your Eclipse.

  3. Edit and change your activity_main.xml like these:

    <?xml version="1.0" encoding="utf-8"?>
    
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />
    
    </RelativeLayout>
    
  4. In res/values/styles.xml:

    <resources>
    
        <style name="AppBaseTheme" parent="android:Theme.Light">
    
        </style>
    
        <!-- Application theme. -->
        <style name="AppTheme" parent="AppBaseTheme">
    
        </style>
    
    </resources>
    
  5. In res/values-v11/styles.xml you have to change like these:

    <resources>
    
        <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
        </style>
    
    </resources>
    
  6. In res/values-v14/styles.xml you have to change like these:

      <resources>
    
        <style name="AppBaseTheme" parent="android:Theme.Light">
        </style>
    
        <style name="AppTheme" parent="AppBaseTheme">
        </style>
    
    </resources>
    
  7. Change your menu/main.xml like these:

    <menu xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <item
            android:id="@+id/action_settings"
            android:orderInCategory="100"
            android:showAsAction="never"
            android:title="@string/action_settings"/>
    
    </menu>
    
  8. Finally change your MainActivity.java like these:

    import android.app.Activity;
    import android.os.Bundle;
    
    
    public class MainActivity extends Activity {
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
    }
    
    }
    

LikeWise you have to do it for creating a new project

Stephen
  • 9,899
  • 16
  • 90
  • 137
8

It's included because your minimum SDK version is set to 10. The ActionBar was introduced in API 11. Eclipse adds it automatically so your app can look more consistent throughout the spectrum of all android versions you are supporting.

Ahmad
  • 69,608
  • 17
  • 111
  • 137
4

If you are not targeting 2.x versions you can set your minimum sdk version of 4.x and then create project. Appcompat V7 lib wont be created.

Swapnil Kadam
  • 4,075
  • 5
  • 29
  • 35
4

I'm new with Android and the project appcompat_v7 always be created when I create new Android application project makes me so uncomfortable.

This is just a walk around. Choose Project Properties -> Android then at Library box just remove appcompat_v7_x and add appcompat_v7. Now you can delete appcompat_v7_x.

Uncheck Create Activity in create project wizard doesn't work, because when creating activity by wizard the appcompat_v7_x appear again. My ADT's version is v22.6.2-1085508.
I'm sorry if my English is bad.

Lê Quang Duy
  • 767
  • 7
  • 14
  • 1
    Check out so many answers are present here.This section is for answer.You have posted question in answer section. – Talha Q Apr 27 '14 at 06:56
  • 1
    I just want to show a way to remove appcompat_v7_x and I don't think this is a question. If I made a mistake please forgive me because I'm new with stackoverflow. – Lê Quang Duy Apr 28 '14 at 19:44
3

Sorry with my English, When you create a new android project, you should choose api of high level, for example: from api 17 to api 21, It will not have appcompat and very easy to share project. If you did it with lower API, you just edit in Android Manifest to have upper API :), after that, you can delete Appcompat V7.

nobjta_9x_tq
  • 1,205
  • 14
  • 16
2

According to http://developer.android.com/guide/topics/ui/actionbar.html

The ActionBar APIs were first added in Android 3.0 (API level 11) but they are also available in the Support Library for compatibility with Android 2.1 (API level 7) and above.

In short, that auto-generated project you're seeing modularizes the process of adding the ActionBar to APIs 7-10.

Example of ActionBar on Froyo

See http://hmkcode.com/add-actionbar-to-android-2-3-x/ for a simplified explanation and tutorial on the topic.

arkon
  • 2,209
  • 3
  • 27
  • 36
0

I noticed creation of 'appcompat' library while creating new android project with ADT 22.6.2 version, even when the minSDK was set to 11 and targetSDK was set 19

This was happening because, in the new project template android is using some attributes that are from the support library. For instance if a new project was created with actionbar then in the menu's main.xml one could find app:showAsAction="never" which is from support library.

  • If the app is targeted at android version 11 and above then one can change this attribute to android:showAsAction in menu's main.xml
  • Also the default theme set could be "Theme.AppCompat.Light.DarkActionBar" as shown below (styles.xml)

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
           <!-- API 14 theme customizations can go here. -->
       </style> 
    

    In this case the parent theme in style.xml has to be changed to "android:style/Theme.Holo.Light.DarkActionBar"

  • In addition to this if reference to Fragment,Fragments Manager from support library was made in the code of MainActivity.java, these have to appropriately changed to Fragment, FragmentManager of the SDK.
Jeevan
  • 8,532
  • 14
  • 49
  • 67