您的位置:首页 > 移动开发 > Android开发

Android studio gradle依赖,依赖爆红,fileTree一句代码实现项目lib下的所有jar包全部自动依赖

2017-09-11 11:02 609 查看

Android studio依赖项目是使用gradle管理的,依赖一个项目、一个jar包、一个工程,都可以在这里进行配置,

直接一句代码

compile 'com.google.code.gson:gson:2.2.4'


就可以轻松实现项目依赖,Android studio会自动从远程代码仓库下载这个jar包或者项目代码,不要太爽,省去了诸多操作,下面看看我的一个项目的依赖

dependencies {

compile project(':androidcrop')
compile project(':pullToRefresh')
compile project(':recyclerview')
compile project(':pushSDK')
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.android.support:appcompat-v7:24.2.1'
compile files('libs/achartengine-1.2.0.jar')
compile files('libs/alicloud-android-sdk-httpdns-1.0.7.jar')
compile files('libs/alipaySdk-20151112.jar')
compile files('libs/AMap3DMap_5.2.0_AMapNavi_5.1.0_AMapSearch_5.1.0_AMapLocation_3.4.0_20170602.jar')
compile files('libs/cmbkeyboard.jar')
compile files('libs/com.umeng.message_v3.0.6.jar')
compile files('libs/EventBus-2.4.0.jar')
compile files('libs/libammsdk.jar')
compile files('libs/logback-android-1.1.1-4.jar')
compile files('libs/open_
4000
sdk_r5756_lite.jar')
compile files('libs/slf4j-api-1.7.7.jar')
compile files('libs/umeng-analytics-v6.0.1.jar')
compile files('libs/volley-1.0.19.jar')
compile files('libs/weibosdkcore_v3.1.1.jar')
}


可以看到,住项目,依赖的,有project工程比如:

compile project(':androidcrop')


,有从远程代码库下载的jar包比如:

compile 'com.google.code.gson:gson:2.2.4'


也有本地lib的jar包比如:

compile files('libs/EventBus-2.4.0.jar')


,从远程代码库下载的jar包,显示的基本上可以理解为是一个连接地址,如果后续有新版本的jar包,as会自动提示更新,如果依赖的是本地libs里的jar就不会有这种提示了。

问题1:

问题:看到这个
dependencies {}
里面是有很多的内容的,虽然可以精细的看到每一个依赖,但是有时候,也会漏掉一些什么依赖东西,特别是在eclipse项目转Android studio项目的时候,我就是遇到了这样的问题,不知道漏掉了啥,这个时候,可以有一句代码来代替这一条条的精细依赖——–>

compile fileTree(include: ['*.jar'], dir: 'libs')


这行代码就可以实现自动依赖,lib下的所有jar,会根目录下 libs下所有.jar结尾的文件都依赖

问题2:

问题:就是这个依赖的地方,有时候会发现,依赖条目爆红了,提示

This support library should not use a different version (24) than the compileSdkVersion (23) less... (Ctrl+F1)
There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion.)




看一下详细提示,



其实很简单,说的很明显,是编译版本过低,应用版本过高,这样就相互扯着蛋蛋,相当的难受,处理办法相当简单,把版本改为一样的就OK了。也就是在这个依赖的地方,把24改为23,—–>24.2.1改为23.0.1就OK了;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐