首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >targetSdkVersion gradle奇异值

targetSdkVersion gradle奇异值
EN

Stack Overflow用户
提问于 2018-08-31 12:16:55
回答 1查看 499关注 0票数 1

所以,我从Github克隆了这个项目,在浏览它的build.gradle时,我发现了这个奇怪的配置,特别是对于targetSdkVersion。现在,在我详细介绍它是什么之前,让我先提一下这个项目有两个模块--app(主要模块)和callrecord(封装呼叫记录功能)

下面是相同文件的build.gradle文件:

代码语言:javascript
复制
apply plugin: 'com.android.application'

android {
    compileSdkVersion project.sdk

    defaultConfig {
        applicationId "com.aykuttasil.callrecorder"
        minSdkVersion project.minSdk
        targetSdkVersion project.sdk
        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:appcompat-v7:$supportVersion"
    testCompile 'junit:junit:4.12'
    compile project(':callrecord')
}

你能看见吗?

我不明白compileSdkVersion project.sdk这句话。这个项目"object“也在其他地方被引用过。

首先,为什么有人要使用这个属性?其次,我如何找出它是什么版本?

EN

回答 1

Stack Overflow用户

发布于 2018-08-31 12:25:48

为什么有人要使用这个属性?

  • 背后的主要目的是使用此属性在一个地方配置Android项目模块的所有变量
  • 因此在一个地方更改它将在整个项目中生效

我怎么知道它是什么版本?

它将在gradle.propertiesbuild.gradle中的

中提供

查看一下该项目的

示例

这是一篇关于它的好文章

gradle.properties

代码语言:javascript
复制
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
android.useAndroidX = true
android.enableJetifier = false

#gradle.properties
myTargetSdkVersion=27
myCompileSdkVersion=27
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

在您的Build.Gradle中使用

代码语言:javascript
复制
android {
    compileSdkVersion project.myTargetSdkVersion.toInteger()
    defaultConfig {
        applicationId "com.example.nilesh.myapplication"
        minSdkVersion project.myMinSdkVersion.toInteger()
        targetSdkVersion project.myTargetSdkVersion.toInteger()
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52108359

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档