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.
This question is related to
android
eclipse
android-appcompat
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.
See http://hmkcode.com/add-actionbar-to-android-2-3-x/ for a simplified explanation and tutorial on the topic.
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.
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.
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.
android:showAsAction
in menu's main.xmlAlso 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"
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.
Create a new Android Application Project
and uncheck Create activity
in step two (Configure project).
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:
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
.
Delete fragment_main.xml and Appcompat file created in your Eclipse.
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>
In res/values/styles.xml:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
In res/values-v11/styles.xml you have to change like these:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
</style>
</resources>
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>
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>
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
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.
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.
Source: Stackoverflow.com