How to properly set -Xlint:deprecation to identify deprecated API usage in Gradle? (Developing with Flutter in VS Code)

Can someone help me correctly configure the setting for the following warning?

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
</code>
<code>Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. </code>
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

I’m developing a Flutter app using VS Code, and I’ve tried several options but can’t seem to configure it properly to see which part of the code is causing the “deprecated API” warning.

Here is my current build.gradle:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> plugins {
id "com.android.application"
id "kotlin-android"
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id "dev.flutter.flutter-gradle-plugin"
id 'com.google.gms.google-services'
}
android {
namespace = "testxxxx"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
// options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
options.compilerArgs += ["-Xlint:deprecation"]
}
}
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.test.testxxx"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdkVersion = 23
// minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.debug
}
}
}
flutter {
source = "../.."
}
dependencies {
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:33.2.0')
// TODO: Add the dependencies for Firebase products you want to use
// When using the BoM, don't specify versions in Firebase dependencies
implementation 'com.google.firebase:firebase-analytics'
// Add the dependencies for any other desired Firebase products
// https://firebase.google.com/docs/android/setup#available-libraries
}
</code>
<code> plugins { id "com.android.application" id "kotlin-android" // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. id "dev.flutter.flutter-gradle-plugin" id 'com.google.gms.google-services' } android { namespace = "testxxxx" compileSdk = flutter.compileSdkVersion ndkVersion = flutter.ndkVersion compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } allprojects { gradle.projectsEvaluated { tasks.withType(JavaCompile) { // options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" options.compilerArgs += ["-Xlint:deprecation"] } } } kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8 } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId = "com.test.testxxx" // You can update the following values to match your application needs. // For more information, see: https://flutter.dev/to/review-gradle-config. minSdkVersion = 23 // minSdk = flutter.minSdkVersion targetSdk = flutter.targetSdkVersion versionCode = flutter.versionCode versionName = flutter.versionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig = signingConfigs.debug } } } flutter { source = "../.." } dependencies { // Import the Firebase BoM implementation platform('com.google.firebase:firebase-bom:33.2.0') // TODO: Add the dependencies for Firebase products you want to use // When using the BoM, don't specify versions in Firebase dependencies implementation 'com.google.firebase:firebase-analytics' // Add the dependencies for any other desired Firebase products // https://firebase.google.com/docs/android/setup#available-libraries } </code>
    plugins {
    id "com.android.application"
    id "kotlin-android"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"

    
    id 'com.google.gms.google-services'    
    
}

android {
    namespace = "testxxxx"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8

        
    }    
    
    allprojects {
        gradle.projectsEvaluated {
            tasks.withType(JavaCompile) {
                // options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
                options.compilerArgs += ["-Xlint:deprecation"]
            }
        }
    }


    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.test.testxxx"
        // You can update the following values to match your application needs.
        // For more information, see: https://flutter.dev/to/review-gradle-config.
        minSdkVersion = 23
        // minSdk = flutter.minSdkVersion

        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig = signingConfigs.debug
        }
    }
}


flutter {
    source = "../.."
}

dependencies {
  // Import the Firebase BoM
  implementation platform('com.google.firebase:firebase-bom:33.2.0')


  // TODO: Add the dependencies for Firebase products you want to use
  // When using the BoM, don't specify versions in Firebase dependencies
  implementation 'com.google.firebase:firebase-analytics'


  // Add the dependencies for any other desired Firebase products
  // https://firebase.google.com/docs/android/setup#available-libraries
}

How can I properly configure the -Xlint:deprecation flag to show details about deprecated API usage?

The solution I found, with tips from Sameri11, was:

In the Flutter project’s android/build.gradle file,

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>allprojects {
repositories {
google()
mavenCentral()
}
// Add compiler parameters
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
// "-Werror" treats any warning (such as those generated by -Xlint:deprecation or -Xlint:unchecked)
// as an error, causing the build to fail.
options.compilerArgs += ["-Xlint:deprecation", "-Xlint:unchecked"]
}
// Not entirely sure if this is working, but for now, I’m keeping it this way
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
kotlinOptions {
freeCompilerArgs += ["-Xlint:deprecation"]
}
}
}
}
</code>
<code>allprojects { repositories { google() mavenCentral() } // Add compiler parameters gradle.projectsEvaluated { tasks.withType(JavaCompile) { // "-Werror" treats any warning (such as those generated by -Xlint:deprecation or -Xlint:unchecked) // as an error, causing the build to fail. options.compilerArgs += ["-Xlint:deprecation", "-Xlint:unchecked"] } // Not entirely sure if this is working, but for now, I’m keeping it this way tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) { kotlinOptions { freeCompilerArgs += ["-Xlint:deprecation"] } } } } </code>
allprojects {
    repositories {
        google()
        mavenCentral()
    }

    // Add compiler parameters
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {                        
            // "-Werror" treats any warning (such as those generated by -Xlint:deprecation or -Xlint:unchecked) 
            // as an error, causing the build to fail.
            options.compilerArgs += ["-Xlint:deprecation", "-Xlint:unchecked"]             
        }

        // Not entirely sure if this is working, but for now, I’m keeping it this way
        tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
            kotlinOptions {
                freeCompilerArgs += ["-Xlint:deprecation"]
            }
        }
    }
}

You may also need to add -Xlint:deprecation to Kotlin compile tasks, along with java. Like this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
kotlinOptions {
freeCompilerArgs += ["-Xlint:deprecation"]
}
}
</code>
<code>tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) { kotlinOptions { freeCompilerArgs += ["-Xlint:deprecation"] } } </code>
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
            kotlinOptions {
                freeCompilerArgs += ["-Xlint:deprecation"]
            }
        }

There is also one great option to escalate all warnings to errors. May be handful to get attention to actual deprecations.

For Java:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>options.compilerArgs += ["-Xlint:deprecation", "-Werror"]
</code>
<code>options.compilerArgs += ["-Xlint:deprecation", "-Werror"] </code>
options.compilerArgs += ["-Xlint:deprecation", "-Werror"]

For Kotlin:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>kotlinOptions {
allWarningsAsErrors = true
}
</code>
<code>kotlinOptions { allWarningsAsErrors = true } </code>
kotlinOptions {
    allWarningsAsErrors = true
}

In android/build.gradle, set the values as follows

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>// Add compiler parameters
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
// "-Werror" treats any warning (such as those generated by -Xlint:deprecation or -Xlint:unchecked)
// as an error, causing the build to fail.
options.compilerArgs += ["-Xlint:deprecation", "-Xlint:unchecked"]
}
// Not entirely sure if this is working, but for now, I’m keeping it this way
// ,"-no-shrink"
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
kotlinOptions {
freeCompilerArgs += ["-Xlint:deprecation"]
}
}
}
</code>
<code>// Add compiler parameters gradle.projectsEvaluated { tasks.withType(JavaCompile) { // "-Werror" treats any warning (such as those generated by -Xlint:deprecation or -Xlint:unchecked) // as an error, causing the build to fail. options.compilerArgs += ["-Xlint:deprecation", "-Xlint:unchecked"] } // Not entirely sure if this is working, but for now, I’m keeping it this way // ,"-no-shrink" tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) { kotlinOptions { freeCompilerArgs += ["-Xlint:deprecation"] } } } </code>
// Add compiler parameters
gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {                        
        // "-Werror" treats any warning (such as those generated by -Xlint:deprecation or -Xlint:unchecked) 
        // as an error, causing the build to fail.
        options.compilerArgs += ["-Xlint:deprecation", "-Xlint:unchecked"]             
    }
    // Not entirely sure if this is working, but for now, I’m keeping it this way
    // ,"-no-shrink"
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
        kotlinOptions {
            freeCompilerArgs += ["-Xlint:deprecation"]
        }
    }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật