我应该为我的compileSdkVersion设置什么?

时间:2017-10-21 20:42:50

标签: android

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.ta2323.ftsm.lab_recyclerview_a160158"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
    compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
    compile 'com.android.support:cardview-v7:26.0.0-alpha1'
}

有人能帮助我吗?我不知道该使用什么,我很困惑使用哪个版本。有人可以解释更多细节吗? 这是我在构建gradle中的编码。

3 个答案:

答案 0 :(得分:1)

<强> compileSdkVersion

compileSdkVersion属性指定编译目标。

最新的目标sdk版本是26,所以使用compile sdk版本26​​。

compileSdkVersion是针对该应用编译的API的版本。这意味着您可以使用该API版本中包含的Android API功能(以及所有以前的版本)。如果您尝试使用API​​ 16功能但将compileSdkVersion设置为15,则会出现编译错误。如果将compileSdkVersion设置为16,只要应用程序的执行路径不尝试调用API 16特定的API,您仍然可以在API 15设备上运行该应用程序。

查看更多here

答案 1 :(得分:0)

使用与构建工具版本的前缀相同的编译SDK版本。并且总是去寻找最新的。所以现在使用26。

答案 2 :(得分:0)

您应该始终在build.gradle中使用相同的版本:

  1. compileSdkVersion
  2. buildToolsVersion
  3. targetSdkVersion
  4. 支持图书馆
  5. 因为您将support librarybuildToolsVersion设置为版本26,所以您需要坚持使用 26 来完成上述所有列表。这是因为在使用buildToolsVersion "26.0.1"时,您要为API 26指定构建工具。因此,您需要将build.gradle更改为类似的内容(阅读评论):

    apply plugin: 'com.android.application'
    
    android {
    
      /**
       * compileSdkVersion specifies the Android API level Gradle should use to
       * compile your app. This means your app can use the API features included in
       * this API level and lower.
       */
    
      compileSdkVersion 26
    
      /**
       * buildToolsVersion specifies the version of the SDK build tools, command-line
       * utilities, and compiler that Gradle should use to build your app. You need to
       * download the build tools using the SDK Manager.
       *
       * If you're using Android plugin 3.0.0 or higher, this property is optional—
       * the plugin uses the minimum required version of the build tools by default.
       */
    
      buildToolsVersion "26.0.2"
    
        defaultConfig {
            // Defines the minimum API level required to run the app.
            minSdkVersion 15
    
            // Specifies the API level used to test the app.
            targetSdkVersion 26
    
            ...
        }
    
    }
    
    dependencies {  
        ...
        // NEVER USE ALPHA Version in your dependencies.
        compile 'com.android.support:appcompat-v7:26.1.0'
        compile 'com.android.support:recyclerview-v726.1.0'
        compile 'com.android.support:cardview-v7:26.1.0'
    }
    

    Configure Your Build

    了解详情