Android Studio gradle 文件中 ${supportLibVersion} 用法

2017-04-14 11:56:21

一般我们在项目中的gradle会添加如下库文件


[html] view plain copy

  1. dependencies {  

  2.     compile 'com.android.support:appcompat-v7:23.1.0'  

  3.     compile 'com.android.support:design:23.1.0'  

  4.     compile 'com.android.support:pallete-v7:23.1.0'  

  5.     compile 'com.android.support:cardview-v7:23.1.0'  

  6.     compile 'com.android.support:recyclerview-v7:23.1.0'  

  7. }  


所以每次升级的时候都要修改后面的23.1.0版本号,Android开发小组的Chris Banes想出了这样的一个方法,不用每次修改每个版本,而只需要修改一次就行了,如下


[html] view plain copy

  1. ext {  

  2.     supportLibVersion = "23.1.1"  

  3. }  

  4.   

  5. dependencies {  

  6.     compile "com.android.support:appcompat-v7:${supportLibVersion}"  

  7.     compile "com.android.support:design:${supportLibVersion}"  

  8.     compile "com.android.support:recyclerview-v7:${supportLibVersion}"  

  9.     compile "com.android.support:cardview-v7:${supportLibVersion}"  

  10. }  


但是有个注意点:



[html] view plain copy

  1. compile 'com.android.support:appcompat-v7:${supportLibVersion}'  

上面这种写法不对


[html] view plain copy

  1. compile "com.android.support:appcompat-v7:${supportLibVersion}"  

这种写法才是正确的


上面这种方式,如果有新版本,Android Studio还是会提醒你的,所以放心的去用吧!


  • 2021-01-16 09:31:14

    Xcode两种引入图片的方法

    如果是纯代码,图片名需要手动添加@2x,@3x等倍数标识,且需要指明后缀.png,.jpg;IB添加图片的话只需要指明后缀就好,不用添加倍数标识。

  • 2021-01-16 09:39:32

    iOS 更改状态栏、导航栏颜色,电池颜色

    注意事项,两种方法设置View controller-based status bar appearance 的值不一样,并且如果你的plist里面没有View controller-based status bar appearance,你需要新建一个。然后就可以成功了。

  • 2021-01-16 09:45:19

    tabbar的titlePositionAdjustment设置文字距离

    指定相应的数据去偏移一个位置,向右或者向下为正值,向左或者向上为负值,不过首先你得有一个相对位置的坐标。而tabbarItem文字的坐标是底部为x轴,y轴则是tabbarItem的centerX;

  • 2021-01-16 09:49:13

    Cocoapods如何查看项目中引入库的版本号

    项目中已经安装过Cocoapods,并生成了Podfile.lock文件。 打开终端,cd命令切换到项目中的Podfile.lock文件目录下,执行命令:cat Podfile.lock 即可。也可以用文本方式打开 Podfile.lock 文件。示例如下: