如何正确设置 -Xlint:deprecation 来识别 Gradle 中已弃用的 API 使用情况? (在 VS Code 中使用 Flutter 进行开发)

问题描述 投票:0回答:1

有人可以帮助我正确配置以下警告的设置吗?

Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

我正在使用 VS Code 开发 Flutter 应用程序,我尝试了多种选项,但似乎无法正确配置它以查看代码的哪一部分导致了“已弃用的 API”警告。

这是我当前的build.gradle:

    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
}

如何正确配置 -Xlint:deprecation 标志以显示有关已弃用 API 使用情况的详细信息?

flutter gradle
1个回答
0
投票

您可能还需要将

-Xlint:deprecation
与 java.lang 一起添加到 Kotlin 编译任务中。像这样:

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
            kotlinOptions {
                freeCompilerArgs += ["-Xlint:deprecation"]
            }
        }

还有一个很好的选项可以将所有警告升级为错误。可能很难引起人们对实际弃用的关注。

对于 Java:

options.compilerArgs += ["-Xlint:deprecation", "-Werror"]

对于科特林:

kotlinOptions {
    allWarningsAsErrors = true
}
© www.soinside.com 2019 - 2024. All rights reserved.