Specify Java / Kotlin compile-time options for Android apps

A note that specifies compile options such as -Xlint: deprecation and -Xlint: unchecked when building an Android app with Gradle. Note that the specification method differs between Java and Kotlin.

build.gradle


allprojects {
    gradle.projectsEvaluated {
        
        //Java compile time
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
        }

        //Kotlin at compile time
        tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
            kotlinOptions {
                freeCompilerArgs = [
                        "-Xjavac-arguments='-Xlint:unchecked -Xlint:deprecation'"
                ]
            }
        }
    }
}

Recommended Posts

Specify Java / Kotlin compile-time options for Android apps
Convert all Android apps (Java) to Kotlin
Links for creating Android apps (for beginners)
Generics of Kotlin for Java developers
[Android] Convert Android Java code to Kotlin
Memory measurement for Java apps using jstat
[For beginners] Difference between Java and Kotlin
Interoperability tips with Kotlin for Java developers
Kotlin vs. Java: Which Programming Language to Choose for Your Android App
Memo for migration from java to kotlin
Check the options set for the running Java process
Initial settings for rewriting Java projects to Kotlin
Create your own Android app for Java learning
For Java engineers starting Kotlin from now on
For JAVA learning (2018-03-16-01)
2017 IDE for Java
Technical causes and countermeasures for points addicted to Android apps & Kotlin (3. Processing related to Android images)
Java for statement
How to use Truth (assertion library for Java / Android)
Consideration of options for implementing native apps (in writing)
Technical causes and countermeasures for points addicted to Android apps & Kotlin (1. Android screen transition (fragment) processing)