Dip*_* s. 5 android gradle build.gradle gradle-kotlin-dsl
虽然转换build.gradle为build.gradle.kts手动过程,但我在下面的代码段中努力进行转换。
我多次尝试使缓存失效并重新启动工作室。但是,android.varinatFilter 无法识别。
android.variantFilter { variant ->
if (variant.buildType.name == 'release'
&& variant.getFlavors().get(0).name == 'development') {
variant.setIgnore(true)
}
if (variant.buildType.name == 'debug'
&& variant.getFlavors().get(0).name == 'production') {
variant.setIgnore(true)
}
}
Run Code Online (Sandbox Code Playgroud)
依赖项的 Properties 类Java.util.Properties未在.kts文件中解析,并且 FileInputStream 类也Java.io无法识别。
def getProps(path) {
Properties props = new Properties()
props.load(new FileInputStream(file(path)))
return props
}
Run Code Online (Sandbox Code Playgroud)
同时应用 kotlin 注释处理器
kapt 'androidx.lifecycle:lifecycle-common-java8:2.1.0' To
kapt {'androidx.lifecycle:lifecycle-common-java8:2.1.0'}
Run Code Online (Sandbox Code Playgroud)
不起作用并返回编译时错误。
任何帮助,将不胜感激。
更新
依赖项的 Properties 类
Java.util.Properties未在.kts文件中解析,并且 FileInputStream 类也Java.io无法识别。
这将通过使缓存无效并重新启动来解决。(按顺序开始重构项目级别 gradle,然后是 settings.gradle,然后是 app.gradle 文件)
对于kapt {'androidx.lifecycle:lifecycle-common-java8:2.1.0'}- 请使用双引号,例如kapt {"androidx.lifecycle:lifecycle-common-java8:2.1.0"},请在此处查看详细信息。
另请对方法使用以下语法:
import java.io.FileInputStream
import java.util.Properties
/***/
fun getProps(path: String): Properties {
val props = Properties()
props.load(FileInputStream(file(path)))
return props
}
Run Code Online (Sandbox Code Playgroud)
变化:
fun而不是defpath: Stringnew不需要关键字val,例如,如果编译器能够理解该类型,则无需手动输入。Unit。对于过滤器 - 我没有使用过这个。但请考虑:
variant.getFlavors().get(0).name为variant.flavors[0].namevariant.setIgnore(true)为variant.ignore=true| 归档时间: |
|
| 查看次数: |
2998 次 |
| 最近记录: |