2

Just created a new Android app in Studio and I set compileSdkVersion and minSdkVersion to 16, because I want to make sure that I don't use any features in later versions of Android by accident.

However, this line in my build.gradle seems to lead to compilation errors after changing these:

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

When I comment it out, compilation will be successful. Do I not need this line? I thought it was necessary for ActionBar, etc.

Do I have the wrong idea to be changing the compileSdkVersion to 16 in the first place to make sure that I don't use new features?

Ken
  • 530
  • 4
  • 11
  • 30
  • I get tons of errors like these: Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Inverse'. Error:(123, 21) No resource found that matches the given name: attr 'android:colorPrimaryDark'. – Ken Aug 29 '15 at 19:24
  • You have to use API23 to compile. You can't use API16. http://stackoverflow.com/questions/32102553/android-studio-not-working-while-building-app-using-appcompat-v23-and-api21/32103832#32103832 – Gabriele Mariotti Aug 30 '15 at 06:01

4 Answers4

2

I believe you want to support sdk version 16+, to do this, just set minSdkVersion to 16 and use compileSdkVersion as latest, i.e. 23

By doing this, if you use new features introduced in version 17+, error/warning would be displayed upon compile or when you edit your code in Android Studio.

Edit: some more details

One of the reason why you should do this, because you can have something like this in your code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
}

Actually this is also how the support library work.

http://developer.android.com/training/basics/supporting-devices/platforms.html

Derek Fung
  • 8,171
  • 1
  • 25
  • 28
1

You should update your Android SDK Platform to latest Android 6.0 API 23.

I got the same problem because I just updated the Support Library from SDK Manager and didn't update the SDK Platform.

Check this out
(source: techentice.com)



Or 'com.android.support:appcompat-v7:22.2.1' instead of downloading the SDK Platform

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
zackygaurav
  • 4,369
  • 5
  • 26
  • 40
1

However, this line in my build.gradle seems to lead to compilation errors after changing these: compile 'com.android.support:appcompat-v7:23.0.0'

It happens because the support libraries v23 require the API23 to compile the project.

In your build.gradle change the compileSdkVersion to 23.

  compileSdkVersion 23

When I comment it out, compilation will be successful. Do I not need this line? I thought it was necessary for ActionBar, etc.

Using a minsdk=16 I suggest you using the appcompat library. Widget like Toolbar, and all the design support library (CollapsingToolbar, Snackbar...) require the appCompat.

Also if you want to backport the material design in api16, you need it.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
1

if you want to compile with latest version than update & install your SDK to latest which is at this time API 23.

If you really want to compile & provide support of your app on API 16 & want not to add support of later version (which does not make sense for me may be for you its good) then according to your statement

I set compileSdkVersion and minSdkVersion to 16, because I want to make sure that I don't use any features in later versions of Android

then set compileSdkVersion to 16, minSdkVersion to 16, targetSdkVersion to 16

& dependencies as compile 'com.android.support:appcompat-v6:16.0.0'

check your API 16 section in SDK. it should be install

enter image description here

And you build.gradle should be like this

apply plugin: 'com.android.application'

android {
    compileSdkVersion 16
    buildToolsVersion "16.0.0"

    defaultConfig {
        applicationId "com.example.inzi.mapofcontacts"
        minSdkVersion 16
        targetSdkVersion 16
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v6:16.0.0'
}

According to your question it may help you.

Inzimam Tariq IT
  • 6,548
  • 8
  • 42
  • 69