NullPointerException NullPointerException - 3 months ago 38
Android Question

Is necessary to import support-v4 and appcompat-v7 to use them?

I'm using AppCompatActivity and some more things like fragments etc... These are some of the imports of my activity:

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;


I copyed from the google samples these dependencies:

dependencies {
compile 'com.google.android.gms:play-services-ads:9.4.0'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
}


Now I'm trying to delete them and i noticed that I can delete these:

compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.4.0'


Deleting them, my project works perfectly... why?

I'm compiling with this:

compileSdkVersion 23
buildToolsVersion "23.0.3"
minSdkVersion 14
targetSdkVersion 22

Answer

The support design library itself depends on the appcompat-v7 and support-v4 libraries. So the explicit dependencies you removed are pulled in automatically as transitive dependencies. Running ./gradlew app:dependencies confirms this:

_releaseCompile - ## Internal use, do not manually configure ##
+--- com.android.support:design:23.4.0
|    +--- com.android.support:recyclerview-v7:23.4.0
|    |    +--- com.android.support:support-annotations:23.4.0 -> 24.0.0
|    |    \--- com.android.support:support-v4:23.4.0 -> 24.0.0 (*)
|    +--- com.android.support:appcompat-v7:23.4.0 -> 24.0.0
|    |    +--- com.android.support:support-v4:24.0.0 (*)
|    |    +--- com.android.support:support-vector-drawable:24.0.0
|    |    |    \--- com.android.support:support-v4:24.0.0 (*)
|    |    \--- com.android.support:animated-vector-drawable:24.0.0
|    |         \--- com.android.support:support-vector-drawable:24.0.0 (*)
|    \--- com.android.support:support-v4:23.4.0 -> 24.0.0 (*)