user3290180
user3290180

Reputation: 4410

Android studio: how to properly use the support library AppCompat?

I know there are many versions such as v4, v7, v8, v13, v14, v17, etc and they aren't in order of upgrades. What I don't understand is the meaning of this checkbox in Android Studio when you create a new project and choose an empty activity

Backwards compatibility (AppCompat)

The description says

if false, this activity will be Activity instead of AppCompatActivity

It's a bit foggy to me, then I checked the library and I found out that it was android.support.v7.app.AppCompatActivity

The descriptions says that

v7 Support Libraries There are several libraries designed to be used with Android 2.3 (API level 9) and higher.

Again I don't understand whether I have to use it or not, depending on different cases. If I set the maximum target API, what is the necessary minSdk to not use it?

Upvotes: 1

Views: 578

Answers (2)

Darish
Darish

Reputation: 11481

Please note that, when you opt out support libraries, you can not get benefit of the powerful RecyeclerView, CardView, DesignSupportLib etc. Because these libs are dependent on appCompat


what version should we use in order to avoid the support library?

You can use any version as min sdk version. It does not matter. Support lib is included in every project by default by android studio, you have to remove it manually.

How to create new project without support library?

  • While creating a new project,set min sdk version as 14 (just for example), don't add any activities during the wizard dialog. Just create a project with no activities. Then after you can add code as you wish
  • You can remove the support library , removing the dependency from your build.gradle

     dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        //compile 'com.android.support:appcompat-v7:25.2.0'
    }
    
  • Replace your theme parent in styles.xml into a non AppCompat version like Holo.Light

Upvotes: 0

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363677

It is not simple to answer your question.

The Support Libraries provide a wide range of classes for building apps, from fundamental app components, to user interface widgets, to media handling, to TV app components.

Many of the classes are backward compatible implementations, but some of them are new features in their own right.

It is very important this step. Not all support libraries are used to support backward implementation.

For example in your application you will need to use some components like:

  • RecyclerView
  • CardView
  • ViewPager
  • Design Library
  • .....

In particular the design support library has a dependency with the appcompat library.

It means that you can't avoid the use of the support libraries only using a minSdk. Or in other words you have to use them always.

Here more info about the support libraries.

Upvotes: 1

Related Questions