Android Studio 3.0——unable to resolve dependency for cordovalib

今天突然想起以前弄过的Cordova,于是便下来重新玩玩,一开始Android Studio还没更新,一切正常。然而当我选择确定更新为3.0并同时更新了gradle后,项目竟然开始报错

unable to resolve dependency for cordovalib...打开build.gradle看了后其中dependencies是这样写的

dependencies {
   compile fileTree(dir: 'libs', include: '*.jar')
// SUB-PROJECT DEPENDENCIES START

debugCompile(project(path: "CordovaLib", configuration: "debug")) releaseCompile(project(path: "CordovaLib", configuration: "release"))

// SUB-PROJECT DEPENDENCIES END}
感觉没毛病,非常nice,于是特地查了下3.0版的dependencies是否有变动,一查果然有妖孽作祟,如果你没有一个libary项目,原来的写法并不会有问题,但加入一个lib的写法
需做如下改动
dependencies {
    implementation fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
//    debugCompile(project(path: "CordovaLib", configuration: "debug"))
//    releaseCompile(project(path: "CordovaLib", configuration: "release"))
    // SUB-PROJECT DEPENDENCIES END
    implementation project(':CordovaLib')
    debugImplementation project(':CordovaLib')
    releaseImplementation project(':CordovaLib')
}
将compile替换成implementation即可完美解决上述问题,至于为何官方要做这个改动,原因可以去官网看看,或者是看这篇博客安卓工程依赖方式

没有更多推荐了,返回首页