pchlebda
pchlebda

Reputation: 11

What is com.android.support:appcompat-v7?

I am not familiar with using Android Studio. Earlier I used Eclipse. Could you explain me what is gradle in Android studio. I have problem with Android Studio. What confused me is that it uses the same android sdk as eclipse but when I create a new project weird things happens:

  1. There is required :com.android.support:appcompat-v7:+ (what it is ? eclipse does not require it)
  2. My MainActivity extends ActionBarActivity instead of Activity why is that ?

Upvotes: 0

Views: 1510

Answers (2)

Piyush Agarwal
Piyush Agarwal

Reputation: 25858

Actiobbar is introduced in api level 11. com.android.support:appcompat-v7:+ is a support library which allows you to have an ActionBar in your app for devices running on Android 3.0 or below.

Android Studio default project includes it automatically in dependencies and extends ActionbarActivity instead of Activity in order to use it.

You can check the same in your module's build.gradle file, you will find something like this under your dependencies block.

 compile 'com.android.support:appcompat-v7:+'

There are two possible solutions to get rid of this

  1. Remove above line from dependencies block and extend Activity instead of ActionBarActivity in your Activity classes.

  2. Download support repository from Android SDK Manager.

Support Repository and Google Repository shown in SDK manager are not required for Eclipse but in order use Google Play Services and Support libraries in Android Stodio you have to download them.

EDIT(android plugin not found error, asked in comments below ) :

Make sure you have this either in your root level build.gradle file or at the top of module's build.gradle file to let build system know where your gradle pguin is and what is the version : (before apply plugin: 'android')

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.8.+'
    }
}

Upvotes: 2

Raghunandan
Raghunandan

Reputation: 133560

Its a support library called appcompat. You need to reference that if you need actionbar below api level 11 (Whether its android studio or eclipse).

If you need actionbar below api level 11 your Activity needs to extend ActionBarActivity.

If you are targetting api level 11 and above then you don't need to extend ActionBarActivity and reference AppCompat. You can simply extend Activity and you will have actionabr by default.

Check Adding the Action Bar in the below link.

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

Check for Adding libraries with resources using Android Studio @

https://developer.android.com/tools/support-library/setup.html

Upvotes: 2

Related Questions