如何管理和引用特定的依赖库版本?

时间:2022-06-13 08:08:54

I have my root build.gradle like this:

我的root build.gradle是这样的:

...
ext{
  buildToolsVersion = '23.2.1'
}
...

Why cannot I manage my Android support libraries version like this:

为什么我不能像这样管理我的Android支持库版本:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:${rootProject.ext.buildToolsVersion}'
    compile 'com.android.support:design:${rootProject.ext.buildToolsVersion}'
}

${} works in Groovy, why does not it work in Gradle?

$ {}适用于Groovy,为什么它不能在Gradle中运行?

2 个解决方案

#1


5  

Use:

使用:

In root/build.gradle:

在root / build.gradle中:

ext {
    //Version
    supportLibrary = '23.2.1'

    //Support Libraries dependencies
    supportDependencies = [
            design           :         "com.android.support:design:${supportLibrary}",
            recyclerView     :         "com.android.support:recyclerview-v7:${supportLibrary}",
            cardView         :         "com.android.support:cardview-v7:${supportLibrary}",
            appCompat        :         "com.android.support:appcompat-v7:${supportLibrary}",
            supportAnnotation:         "com.android.support:support-annotations:${supportLibrary}",
    ]
}

In your module/build.gradle:

在您的module / build.gradle中:

dependencies {
    //......
    compile supportDependencies.appCompat
    compile supportDependencies.design
}

#2


0  

my fault.
'com.android.support:appcompat-v7:${rootProject.ext.buildToolsVersion}'
equals
"com.android.support:appcompat-v7:\${rootProject.ext.buildToolsVersion}".
so it should be "com.android.support:appcompat-v7:${rootProject.ext.buildToolsVersion}" with double quotes.

我的错。 'com.android.support:appcompat-v7:${rootProject.ext.buildToolsVersion}'等于“com.android.support:appcompat-v7:\${rootProject.ext.buildToolsVersion}”。所以它应该是“com.android.support:appcompat-v7:${rootProject.ext.buildToolsVersion}”,带双引号。

#1


5  

Use:

使用:

In root/build.gradle:

在root / build.gradle中:

ext {
    //Version
    supportLibrary = '23.2.1'

    //Support Libraries dependencies
    supportDependencies = [
            design           :         "com.android.support:design:${supportLibrary}",
            recyclerView     :         "com.android.support:recyclerview-v7:${supportLibrary}",
            cardView         :         "com.android.support:cardview-v7:${supportLibrary}",
            appCompat        :         "com.android.support:appcompat-v7:${supportLibrary}",
            supportAnnotation:         "com.android.support:support-annotations:${supportLibrary}",
    ]
}

In your module/build.gradle:

在您的module / build.gradle中:

dependencies {
    //......
    compile supportDependencies.appCompat
    compile supportDependencies.design
}

#2


0  

my fault.
'com.android.support:appcompat-v7:${rootProject.ext.buildToolsVersion}'
equals
"com.android.support:appcompat-v7:\${rootProject.ext.buildToolsVersion}".
so it should be "com.android.support:appcompat-v7:${rootProject.ext.buildToolsVersion}" with double quotes.

我的错。 'com.android.support:appcompat-v7:${rootProject.ext.buildToolsVersion}'等于“com.android.support:appcompat-v7:\${rootProject.ext.buildToolsVersion}”。所以它应该是“com.android.support:appcompat-v7:${rootProject.ext.buildToolsVersion}”,带双引号。