Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove support library (appcompat_v7) [Eclipse]

I've updated my eclipse and ADT Plugin to the latest version recently and recognised some big changes. Whenever I create a new Android Application Project there appears a new appcompat_v7 library which wasn't present before and also a fragment_main.xml . Why is that? Why is the activity_main.xml file not preferred for activity layout directly anymore and why appcompat library is now included in every project ? I tried to remove eclipse/adt/sdk many times and remove the support library from sdk manager but got no result ! I realize it has something to do with actionbar but the problem is that whenever I create a new project a red exclamation mark shows up on both project's file and appcompat_v7 file and this prevents me from compiling/running the application or even sometimes appcompat_v7 file doesn't create and the only thing I get is damaged code here's a picture :http://i.stack.imgur.com/XJMfW.png

so how can I remove this dependency and thanks

like image 733
AlphaCode Avatar asked Mar 31 '14 18:03

AlphaCode


2 Answers

Why is that?

Because Google engineers added that stuff to the new-activity templates, for at least the "BlankActivity".

Why is the activity_main.xml file not preferred for activity layout directly anymore

You are certainly welcome to use activity_main.xml for whatever you want. It so happens that Google's current templates want you to use fragments. Google's templates are just templates. One can argue -- and I have, vehemently -- that a "BlankActivity" template should not be doing what it is doing. However, beyond that, it is just a template.

why appcompat library is now included in every project ?

Presumably, they wanted to start you off with a consistent action bar, even on older API levels.

I realize it has something to do with actionbar but the problem is that whenever I create a new project a red exclamation mark shows up on both project's file and appcompat_v7 file and this prevents me from compiling/running the application or even sometimes appcompat_v7 file doesn't create and the only thing I get is damaged code

I reported this issue a week or so ago.

so how can I remove this dependency

Step #1: Right-click over the project name in the Package Explorer, and choose Properties. Click on Android in the list of property categories on the left, and scroll down on the right to the bottom:

Eclipse Project Properties, Android Category

Step #2: In the list of attached library projects that you will now see in the properties dialog, you may see an entry akin to the "appcompat_v7_6" one that you see in the above screenshot. Your last digit will differ, and it may be that yours has a red X instead of a green checkmark. Regardless, if there is an entry for "appcompat_v7_NNN" in the list, click on it, then click the Remove button to the right of the list. Then, click the OK button to close up the dialog.

Step #3: In res/values/styles.xml, change the parent of AppBaseTheme from Theme.AppCompat.Light to @android:style/Theme.Light. In res/values-v11/styles.xml, change the parent of AppBaseTheme from Theme.AppCompat.Light to @android:style/Theme.Holo.Light. In rest/values-v14/styles.xml change the parent of AppBaseTheme from Theme.AppCompat.Light.DarkActionBar to @android:style/Theme.Holo.Light.DarkActionBar. Note that these values assume that you chose the default "Light theme with dark action bar" when you created the project -- you will need to make slight adjustments to those instructions for anything else.

Step #4: In res/menu/main/xml, remove xmlns:app="http://schemas.android.com/apk/res-auto" from the root <menu> element and the app:showAsAction="never" attribute from the <item> element.

Step #5: In your activity (e.g., MainActivity), change the parent class of the activity to something other than ActionBarActivity -- FragmentActivity would be a good choice, to minimize the number of other changes you will have to make immediately. Also, clean your imports (e.g., Ctrl-Shift-O).

At this point, other than perhaps cleaning your project (Project > Clean from the main menu), the appcompat stuff should be ripped out of a project created using the "BlankActivity" template and with a "Navigation Type" of "None". Other templates, or navigation options on the "BlankActivity" template, will probably require more work.

like image 83
CommonsWare Avatar answered Oct 23 '22 17:10

CommonsWare


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.

  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

like image 7
Steve Avatar answered Oct 23 '22 17:10

Steve