Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio - Can't specify own minSdkVersion

After installing the Android L Developer Preview SDK earlier today I wanted to make my app compatible with both Android L and older versions such as Jelly Bean. My app uses a minSdkVersion of 16 but since I tried out the developer preview Android Studio doesn't seem to respect my minSdkVersion. I'm trying to get my app to run on my Galaxy Nexus (API 19) and here's the error I get:

enter image description here

Here's my AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.simon.holocountownapp"
    android:versionCode="45"
    android:versionName="4.1.1" >

<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="L" />

...

Here's my build.gradle:

apply plugin: 'android'

android {
    compileSdkVersion 'android-L'
    buildToolsVersion '20'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 'L'
    }
    buildTypes {
        release {
            runProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile 'com.doomonafireball.betterpickers:library:1.5.2'
    compile 'uk.co.androidalliance:edgeeffectoverride:1.0.1'
    compile 'com.readystatesoftware.systembartint:systembartint:+'
    compile "com.android.support:support-v4:+"
    compile "com.android.support:support-v13:+"
}
like image 318
SweSnow Avatar asked Jun 26 '14 22:06

SweSnow


3 Answers

See my post to /r/AndroidDev here that provides a workaround.

like image 118
Eddie Avatar answered Oct 10 '22 14:10

Eddie


You are using this dependency:

compile "com.android.support:support-v4:+"

In this way you are using the support-v4 in L-preview (21-rc1).

This support lib is declaring minSdkVersion L (you can check the Manifest).

You have to force the minSdkVersion to be 'L' (check the doc: http://developer.android.com/preview/setup-sdk.html)

On the development environment, open the build.gradle file for your module and make sure that:

compileSdkVersion is set to 'android-L'
minSdkVersion is set to 'L'
targetSdkVersion is set to 'L'

It is not a bug, but this is because these APIs are not final. It is a way to prevent installing the apps on a final API 21 device or publishing it on the store using support lib 21-r1.

like image 21
Gabriele Mariotti Avatar answered Oct 10 '22 14:10

Gabriele Mariotti


In developer documentation says (http://developer.android.com/preview/setup-sdk.html):

On the development environment, open the build.gradle file for your module and make sure that:

  • compileSdkVersion is set to 'android-L'
  • minSdkVersion is set to 'L'
  • targetSdkVersion is set to 'L'

It seems that can't be backward compatible (right now).

like image 36
Albert Avatar answered Oct 10 '22 16:10

Albert