While converting the build.gradle
to build.gradle.kts
is a manual process, I'm struggling in conversion in the below piece of code.
I tried with invalidating the cache and restarting the studio many times. However, android.varinatFilter is not recognized.
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)
}
}
Properties class of Java.util.Properties
dependency doesn't get resolved in .kts
file also the FileInputStream class of Java.io
is not recognized.
def getProps(path) {
Properties props = new Properties()
props.load(new FileInputStream(file(path)))
return props
}
Also while applying the kotlin annotation processor
kapt 'androidx.lifecycle:lifecycle-common-java8:2.1.0' To
kapt {'androidx.lifecycle:lifecycle-common-java8:2.1.0'}
doesn't work and returns compile-time error.
Any help would be appreciated.
UPDATE
Properties class of
Java.util.Properties
dependency doesn't get resolved in.kts
file also the FileInputStream class ofJava.io
is not recognized.
This will get resolved with Invalidate cache and Restart.(Start refactoring project level gradle then settings.gradle and then app.gradle file in sequence)
For kapt {'androidx.lifecycle:lifecycle-common-java8:2.1.0'}
- please use double quotes, e.g. kapt {"androidx.lifecycle:lifecycle-common-java8:2.1.0"}
, please check details here.
Please also use the following syntax for method:
import java.io.FileInputStream
import java.util.Properties
/***/
fun getProps(path: String): Properties {
val props = Properties()
props.load(FileInputStream(file(path)))
return props
}
Changes:
fun
instead of def
path: String
new
keyword is not neededval
, e.g. if compiler is able to understand the type, you don't need to enter it manually.Unit
.For filter - I didn't worked with this. However please consider:
variant.getFlavors().get(0).name
to variant.flavors[0].name
variant.setIgnore(true)
to variant.ignore=true