在Android studio中使用-Xlint重新编译

Lee*_*eem 47 android android-studio

当我在Android Studio中构建我的Android项目时,我收到消息:

Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Run Code Online (Sandbox Code Playgroud)

Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Run Code Online (Sandbox Code Playgroud)

我想做消息建议的内容,但是如何做?-Xlint如上所述,如何配置我的Android工作室重新编译我的项目?(我使用的是Android Studio 3.0.1)

1st*_*ell 88

该消息建议您使用args -Xlint重新编译以获取更多警告详细信息,将这些代码添加到build.gradle:

allprojects {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
    }
}
Run Code Online (Sandbox Code Playgroud)

然后,您可以通过详细消息修复警告.
例如,您可以使用新方法替换已弃用的方法(由于旧方法已被弃用,因此始终存在新方法).

但是,有时我们不希望因某些原因更改我们的代码,我们只想摆脱编译警告,可以@SuppressWarnings("deprecation")在不推荐使用的方法前面添加.


Vah*_*yan 9

您需要在应用程序级别的buld.graddle文件中添加以下内容

allprojects {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
    }
}
Run Code Online (Sandbox Code Playgroud)

如果由于某些原因您需要继续使用已弃用的 API,您可以取消警告。您可以使用

@SuppressWarnings("deprecation")
Run Code Online (Sandbox Code Playgroud)

注解。

发布链接


Cop*_*oad 6

如果您在生成签名的 apk 时遇到问题,您可以尝试在您的 build.gradle(app)

android {
    lintOptions {
        checkReleaseBuilds false
    }
}
Run Code Online (Sandbox Code Playgroud)