Android Gradle settings

2019-07-21 05:24发布

问题:

I'm very confused with gradle versioning settings. I found some information about this build system, but nowhere was written about versioning details. Can you explain what these options mean?

compileSdkVersion
buildToolsVersion
minSdkVersion
targetSdkVersion

The minSdkVersion is most obvious, because it means the minimal API we want to support, e.g. 14 (Android >= 4.0).

The targetSdkVersion:

This attribute informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app's forward-compatibility with the target version.

I don't quite understand that.

My case is to support devices from API 15. What are the proper settings for that?
I read somewhere that target should be the highest as possible, Android Studio tells me that too, but when I set this up and try to run on Nexus 5 I get:

Failure [INSTALL_FAILED_OLDER_SDK]

My build.gradle

android {
    compileSdkVersion 'android-L'
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "my.package.name"
        minSdkVersion 14
        targetSdkVersion 'L'
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

回答1:

According to official doc: http://developer.android.com/preview/setup-sdk.html#createProject if you would like to try out new features you should use these values:

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

It is the reason of Failure [INSTALL_FAILED_OLDER_SDK].

If you don't need android-L I suggest using these values:

defaultConfig {
        applicationId "my.package.name"
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }

Said that, there is an unofficial workaround described here (in any case I suggest that you don't use it)

Failure [INSTALL_FAILED_OLDER_SDK] Android-L