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

时间:2016-04-07 10:17:37

标签: android android-studio gradle android-gradle build.gradle

我的根 <ToggleButton.Style> <Style TargetType="ToggleButton"> <Style.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter Property="ToolTip" Value="Active"></Setter> </Trigger> </Style.Triggers> <Setter Property="ToolTip" Value=""></Setter> </Style> </ToggleButton.Style> 就像这样:

build.gradle

为什么我无法管理我的Android支持库版本:

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

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}' } 在Groovy中运行,为什么它在Gradle中不起作用?

2 个答案:

答案 0 :(得分:5)

使用:

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}", ] }

module/build.gradle

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

myClass<T>

答案 1 :(得分:0)

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