当前位置: 代码迷 >> 综合 >> 采用组件化方式管理依赖,在app或者module中引入dependencies.gradle 报错
  详细解决方案

采用组件化方式管理依赖,在app或者module中引入dependencies.gradle 报错

热度:49   发布时间:2023-12-02 10:15:34.0

参考:Gradle报错:Only Project and Settings build scripts can contain plugins {} blocks - 简书

 创建dependencies.gradle文件报错_lyhyrc的博客-CSDN博客

 当在app/module的build.gradle文件的plugins代码块中,用id 'xxxxx'的形式引入插件后 再用apply from:'dependencies.gradle '

plugins {id  'com.android.application'id 'kotlin-android'apply from :'../dep.gradle'
}

 会报如下错误 

class org.codehaus.groovy.ast.expr.TupleExpression cannot be cast to class org.codehaus.groovy.ast.expr.ArgumentListExpression

这是因为 plugins{ } 中只能用id的形式引入插件,apply from需要写在块的下面

plugins {id  'com.android.application'id 'kotlin-android'
}
apply from :'../dep.gradle'

但是这时候如果 dependencies.gradle里继续用了plusins{ },就会报如下错误

 Only Project and Settings build scripts can contain plugins {} blocks

 因为plugins目前还不能在自己创建的gradle文件中使用所以还是需要使用apply plugin

所以正确的写法应该是,在app/module中的build.gradle中 

plugins {id  'com.android.application'id 'kotlin-android'
}
apply from :'../dep.gradle'

在 dependencies.gradle中

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

总结: 用组件化方式管理依赖,app/module中可以用plugins{ id 'xxxxxx'} ,在自定义的gradle中用旧的 apply plugin:' xxxxx'

  相关解决方案