微信已全额退款没到账退款星期六要多久

Android Studio(JAVA) 编译警告:使用了未经检查或不安全的操作 – 默默的点滴
2017年七月
111213141516
17181920212223
24252627282930
在编译Android Studio(JAVA)程序时发生了如下的警告:
使用了未经检查或不安全的操作
要了解详细信息,请使用 "-Xlint:unchecked" 重新编译。
如何设置Android Stuido开启 "-Xlint:unchecked"
修改build.gradle
原始的没有修改的 build.gradle 点击展开
apply plugin: 'com.android.application'
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.a.b.c"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
buildTypes {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
minifyEnabled false
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
12345678910111213141516171819202122232425262728293031
apply plugin: 'com.android.application'&android {&&&&compileSdkVersion 23&&&&buildToolsVersion "23.0.1"&&&&&defaultConfig {&&&&&&&&applicationId "com.a.b.c"&&&&&&&&minSdkVersion 15&&&&&&&&targetSdkVersion 23&&&&&&&&versionCode 1&&&&&&&&versionName "1.0"&&&&}&&&&&buildTypes {&&&&&&&&release {&&&&&&&&&&&&minifyEnabled false&&&&&&&&&&&&proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'&&&&&&&&}&&&&&&&&debug {&&&&&&&&&&&&minifyEnabled false&&&&&&&&}&&&&}}&dependencies {&&&&compile fileTree(dir: 'libs', include: ['*.jar'])&&&&testCompile 'junit:junit:4.12'&&&&compile 'com.android.support:appcompat-v7:23.0.1'&&&&compile 'com.android.support:design:23.0.1'}
tasks.withType(JavaCompile) {
pilerArgs && "-Xlint:unchecked"
tasks.withType(JavaCompile) {&& options.compilerArgs && "-Xlint:unchecked"}
修改后的如下:
修改后增加了 -Xlint:unchecked 的build.gradle 点击展开
apply plugin: 'com.android.application'
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.a.b.c"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
buildTypes {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
minifyEnabled false
tasks.withType(JavaCompile) {
pilerArgs && "-Xlint:unchecked"
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
1234567891011121314151617181920212223242526272829303132333435
apply plugin: 'com.android.application'&android {&&&&compileSdkVersion 23&&&&buildToolsVersion "23.0.1"&&&&&defaultConfig {&&&&&&&&applicationId "com.a.b.c"&&&&&&&&minSdkVersion 15&&&&&&&&targetSdkVersion 23&&&&&&&&versionCode 1&&&&&&&&versionName "1.0"&&&&}&&&&&buildTypes {&&&&&&&&release {&&&&&&&&&&&&minifyEnabled false&&&&&&&&&&&&proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'&&&&&&&&}&&&&&&&&debug {&&&&&&&&&&&&minifyEnabled false&&&&&&&&}&&&&}&&&&&tasks.withType(JavaCompile) {&&&&&& options.compilerArgs && "-Xlint:unchecked"&&&&}}&dependencies {&&&&compile fileTree(dir: 'libs', include: ['*.jar'])&&&&testCompile 'junit:junit:4.12'&&&&compile 'com.android.support:appcompat-v7:23.0.1'&&&&compile 'com.android.support:design:23.0.1'}
警告信息的处理例子
包含-Xlint:unchecked警告的代码
包含-Xlint:unchecked警告的代码
final LinkedHashMap&WeakReference&Object&,WeakReference&Object&& aWeakArray = new LinkedHashMap&&();
for (Iterator iter = aWeakArray.entrySet().iterator(); iter.hasNext(); ) {
LinkedHashMap.Entry element = (LinkedHashMap.Entry)iter.next();
WeakReference&Object& aWeakObj = (WeakReference&Object&)element.getKey();
WeakReference&Object& aWeakTag = (WeakReference&Object&)element.getValue();
final LinkedHashMap&WeakReference&Object&,WeakReference&Object&& aWeakArray = new LinkedHashMap&&();for (Iterator iter = aWeakArray.entrySet().iterator(); iter.hasNext(); ) { LinkedHashMap.Entry element = (LinkedHashMap.Entry)iter.next(); WeakReference&Object& aWeakObj = (WeakReference&Object&)element.getKey(); WeakReference&Object& aWeakTag = (WeakReference&Object&)element.getValue();}
消除警告后的代码如下:
消除警告后的代码
final LinkedHashMap&WeakReference&Object&,WeakReference&Object&& aWeakArray = new LinkedHashMap&&();
for (Iterator&LinkedHashMap.Entry&WeakReference&Object&,WeakReference&Object&& & iter = aWeakArray.entrySet().iterator(); iter.hasNext(); ) {
LinkedHashMap.Entry&WeakReference&Object&,WeakReference&Object&& element = iter.next();
WeakReference&Object& aWeakObj = element.getKey();
WeakReference&Object& aWeakTag = element.getValue();
final LinkedHashMap&WeakReference&Object&,WeakReference&Object&& aWeakArray = new LinkedHashMap&&();for (Iterator&LinkedHashMap.Entry&WeakReference&Object&,WeakReference&Object&& & iter = aWeakArray.entrySet().iterator(); iter.hasNext(); ) { LinkedHashMap.Entry&WeakReference&Object&,WeakReference&Object&& element = iter.next(); WeakReference&Object& aWeakObj = element.getKey(); WeakReference&Object& aWeakTag = element.getValue();}
同样的方法适用于"-Xlint:deprecation"。输入关键字进行搜索
导入一个项目,修改错误出现很多过时错误,不知道怎么处理了--
Information:Gradle tasks [clean, :androidcli:generateDebugSources, :androidcli:prepareDebugUnitTestDependencies, :androidcli:mockableAndroidJar, :androidcli:generateDebugAndroidTestSources, :androidcli:compileDebugSources, :androidcli:compileDebugUnitTestSources, :androidcli:compileDebugAndroidTestSources]
:androidcli:clean
:androidcli:preBuild UP-TO-DATE
:androidcli:preDebugBuild UP-TO-DATE
:androidcli:checkDebugManifest
:androidcli:preReleaseBuild UP-TO-DATE
:androidcli:prepareComAndroidSupportAnimatedVectorDrawable2340Library
:androidcli:prepareComAndroidSupportAppcompatV72340Library
:androidcli:prepareComAndroidSupportSupportV42340Library
:androidcli:prepareComAndroidSupportSupportVectorDrawable2340Library
:androidcli:prepareDebugDependencies
:androidcli:compileDebugAidl
:androidcli:compileDebugRenderscript
:androidcli:generateDebugBuildConfig
:androidcli:mergeDebugShaders
:androidcli:compileDebugShaders
:androidcli:generateDebugAssets
:androidcli:mergeDebugAssets
:androidcli:generateDebugResValues UP-TO-DATE
:androidcli:generateDebugResources
:androidcli:mergeDebugResources
:androidcli:processDebugManifest
:androidcli:processDebugResources
:androidcli:generateDebugSources
:androidcli:preDebugUnitTestBuild UP-TO-DATE
:androidcli:prepareDebugUnitTestDependencies
:androidcli:mockableAndroidJar UP-TO-DATE
:androidcli:preDebugAndroidTestBuild UP-TO-DATE
:androidcli:prepareDebugAndroidTestDependencies
:androidcli:compileDebugAndroidTestAidl
:androidcli:processDebugAndroidTestManifest
:androidcli:compileDebugAndroidTestRenderscript
:androidcli:generateDebugAndroidTestBuildConfig
:androidcli:mergeDebugAndroidTestShaders
:androidcli:compileDebugAndroidTestShaders
:androidcli:generateDebugAndroidTestAssets
:androidcli:mergeDebugAndroidTestAssets
:androidcli:generateDebugAndroidTestResValues UP-TO-DATE
:androidcli:generateDebugAndroidTestResources
:androidcli:mergeDebugAndroidTestResources
:androidcli:processDebugAndroidTestResources
:androidcli:generateDebugAndroidTestSources
:androidcli:incrementalDebugJavaCompilationSafeguard
:androidcli:compileDebugJavaWithJavac
:androidcli:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/com/google/zxing/camera/PreviewCallback.java
Error:(20, 24) 警告: [deprecation] android.hardware中的Camera已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/com/google/zxing/camera/OpenCameraInterface.java
Error:(19, 24) 警告: [deprecation] android.hardware中的Camera已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/com/yuantu/huiyi/ContentActivity.java
Error:(41, 22) 警告: [deprecation] android.widget中的Gallery已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/com/yuantu/huiyi/fragment/DisplayFragment.java
Error:(21, 22) 警告: [deprecation] android.webkit中的CookieSyncManager已过时
Error:(27, 22) 警告: [deprecation] android.widget中的Gallery已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/com/yuantu/huiyi/view/YTWebChromeClient.java
Error:(19, 33) 警告: [deprecation] WebStorage中的QuotaUpdater已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/me/leolin/shortcutbadger/impl/AdwHomeBadger.java
Error:(7, 32) 警告: [deprecation] me.leolin.shortcutbadger中的ShortcutBadgeException已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/me/leolin/shortcutbadger/impl/ApexHomeBadger.java
Error:(7, 32) 警告: [deprecation] me.leolin.shortcutbadger中的ShortcutBadgeException已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/me/leolin/shortcutbadger/impl/AsusHomeLauncher.java
Error:(7, 32) 警告: [deprecation] me.leolin.shortcutbadger中的ShortcutBadgeException已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/me/leolin/shortcutbadger/impl/DefaultBadger.java
Error:(7, 32) 警告: [deprecation] me.leolin.shortcutbadger中的ShortcutBadgeException已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/me/leolin/shortcutbadger/impl/LGHomeBadger.java
Error:(7, 32) 警告: [deprecation] me.leolin.shortcutbadger中的ShortcutBadgeException已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/me/leolin/shortcutbadger/impl/NewHtcHomeBadger.java
Error:(7, 32) 警告: [deprecation] me.leolin.shortcutbadger中的ShortcutBadgeException已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/me/leolin/shortcutbadger/impl/NovaHomeBadger.java
Error:(7, 32) 警告: [deprecation] me.leolin.shortcutbadger中的ShortcutBadgeException已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/me/leolin/shortcutbadger/impl/SamsungHomeBadger.java
Error:(7, 32) 警告: [deprecation] me.leolin.shortcutbadger中的ShortcutBadgeException已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/me/leolin/shortcutbadger/impl/SolidHomeBadger.java
Error:(7, 32) 警告: [deprecation] me.leolin.shortcutbadger中的ShortcutBadgeException已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/me/leolin/shortcutbadger/impl/SonyHomeBadger.java
Error:(7, 32) 警告: [deprecation] me.leolin.shortcutbadger中的ShortcutBadgeException已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/me/leolin/shortcutbadger/impl/XiaomiHomeBadger.java
Error:(8, 32) 警告: [deprecation] me.leolin.shortcutbadger中的ShortcutBadgeException已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/com/google/zxing/camera/AutoFocusManager.java
Error:(27, 24) 警告: [deprecation] android.hardware中的Camera已过时
Error:(36, 41) 警告: [deprecation] android.hardware中的Camera已过时
Error:(36, 47) 警告: [deprecation] Camera中的AutoFocusCallback已过时
Error:(44, 30) 警告: [deprecation] android.hardware中的Camera已过时
Error:(44, 36) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(45, 30) 警告: [deprecation] android.hardware中的Camera已过时
Error:(45, 36) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(50, 16) 警告: [deprecation] android.hardware中的Camera已过时
Error:(53, 36) 警告: [deprecation] android.hardware中的Camera已过时
Error:(66, 56) 警告: [deprecation] android.hardware中的Camera已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/com/google/zxing/camera/CameraConfigurationManager.java
Error:(32, 24) 警告: [deprecation] android.hardware中的Camera已过时
Error:(79, 32) 警告: [deprecation] android.hardware中的Camera已过时
Error:(80, 3) 警告: [deprecation] android.hardware中的Camera已过时
Error:(80, 9) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(118, 21) 警告: [deprecation] Display中的getWidth()已过时
Error:(119, 21) 警告: [deprecation] Display中的getHeight()已过时
Error:(124, 34) 警告: [deprecation] android.hardware中的Camera已过时
Error:(125, 3) 警告: [deprecation] android.hardware中的Camera已过时
Error:(125, 9) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(149, 5) 警告: [deprecation] android.hardware中的Camera已过时
Error:(149, 11) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(154, 6) 警告: [deprecation] android.hardware中的Camera已过时
Error:(154, 12) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(155, 6) 警告: [deprecation] android.hardware中的Camera已过时
Error:(155, 12) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(164, 6) 警告: [deprecation] android.hardware中的Camera已过时
Error:(164, 12) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(173, 3) 警告: [deprecation] android.hardware中的Camera已过时
Error:(173, 9) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(174, 3) 警告: [deprecation] android.hardware中的Camera已过时
Error:(174, 9) 警告: [deprecation] Camera中的Camera.Size已过时
Error:(196, 24) 警告: [deprecation] android.hardware中的Camera已过时
Error:(198, 4) 警告: [deprecation] android.hardware中的Camera已过时
Error:(198, 10) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(202, 11) 警告: [deprecation] android.hardware中的Camera已过时
Error:(202, 17) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(202, 64) 警告: [deprecation] android.hardware中的Camera已过时
Error:(202, 70) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(209, 16) 警告: [deprecation] android.hardware中的Camera已过时
Error:(210, 3) 警告: [deprecation] android.hardware中的Camera已过时
Error:(210, 9) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(215, 31) 警告: [deprecation] android.hardware中的Camera已过时
Error:(215, 37) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(221, 26) 警告: [deprecation] android.hardware中的Camera已过时
Error:(221, 32) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(226, 6) 警告: [deprecation] android.hardware中的Camera已过时
Error:(226, 12) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(227, 6) 警告: [deprecation] android.hardware中的Camera已过时
Error:(227, 12) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(231, 6) 警告: [deprecation] android.hardware中的Camera已过时
Error:(231, 12) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(245, 41) 警告: [deprecation] android.hardware中的Camera已过时
Error:(245, 47) 警告: [deprecation] Camera中的Camera.Parameters已过时
Error:(247, 8) 警告: [deprecation] android.hardware中的Camera已过时
Error:(247, 14) 警告: [deprecation] Camera中的Camera.Size已过时
Error:(252, 4) 警告: [deprecation] android.hardware中的Camera已过时
Error:(252, 10) 警告: [deprecation] Camera中的Camera.Size已过时
Error:(257, 8) 警告: [deprecation] android.hardware中的Camera已过时
Error:(257, 14) 警告: [deprecation] Camera中的Camera.Size已过时
Error:(257, 59) 警告: [deprecation] android.hardware中的Camera已过时
Error:(257, 65) 警告: [deprecation] Camera中的Camera.Size已过时
Error:(259, 58) 警告: [deprecation] android.hardware中的Camera已过时
Error:(259, 64) 警告: [deprecation] Camera中的Camera.Size已过时
Error:(261, 23) 警告: [deprecation] android.hardware中的Camera已过时
Error:(261, 29) 警告: [deprecation] Camera中的Camera.Size已过时
Error:(261, 38) 警告: [deprecation] android.hardware中的Camera已过时
Error:(261, 44) 警告: [deprecation] Camera中的Camera.Size已过时
Error:(276, 9) 警告: [deprecation] android.hardware中的Camera已过时
Error:(276, 15) 警告: [deprecation] Camera中的Camera.Size已过时
Error:(288, 12) 警告: [deprecation] android.hardware中的Camera已过时
Error:(288, 18) 警告: [deprecation] Camera中的Camera.Size已过时
Error:(290, 4) 警告: [deprecation] android.hardware中的Camera已过时
Error:(290, 10) 警告: [deprecation] Camera中的Camera.Size已过时
Error:(327, 4) 警告: [deprecation] android.hardware中的Camera已过时
Error:(327, 10) 警告: [deprecation] Camera中的Camera.Size已过时
Error:(335, 3) 警告: [deprecation] android.hardware中的Camera已过时
Error:(335, 9) 警告: [deprecation] Camera中的Camera.Size已过时
/Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/com/google/zxing/camera/CameraManager.java
Error:(24, 24) 警告: [deprecation] android.hardware中的Camera已过时
Error:(53, 10) 警告: [deprecation] android.hardware中的Camera已过时
Error:(93, 3) 警告: [deprecation] android.hardware中的Camera已过时
Error:(117, 3) 警告: [deprecation] android.hardware中的Camera已过时
注: 某些输入文件还使用或覆盖了已过时的 API。
注: /Users/litianyuan/Downloads/android-cli3/androidcli/src/main/java/loopviews/LoopView.java使用了未经检查或不安全的操作。
100 个警告
:androidcli:compileDebugNdk UP-TO-DATE
:androidcli:compileDebugSources
:androidcli:incrementalDebugUnitTestJavaCompilationSafeguard UP-TO-DATE
:androidcli:compileDebugUnitTestJavaWithJavac UP-TO-DATE
:androidcli:processDebugJavaRes UP-TO-DATE
:androidcli:processDebugUnitTestJavaRes UP-TO-DATE
:androidcli:compileDebugUnitTestSources UP-TO-DATE
:androidcli:incrementalDebugAndroidTestJavaCompilationSafeguard
:androidcli:compileDebugAndroidTestJavaWithJavac
:androidcli:compileDebugAndroidTestNdk UP-TO-DATE
:androidcli:compileDebugAndroidTestSources
Information:BUILD SUCCESSFUL
Information:Total time: 4.706 secs
Information:98 errors
Information:0 warnings
Information:See complete output in console
同问,楼主和楼上的大神有人解决了吗?
已经解决了
警告: [deprecation] android.hardware中的Camera已过时
lintOptions {
checkReleaseBuilds false
abortOnError false
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
pilerArgs && &-Xlint:unchecked& && &-Xlint:deprecation&
还是打包不了!!!!!!
要回复问题请先或
浏览: 5099
关注: 4 人Android studio & lint 代码检查设置 - 简书
Android studio & lint 代码检查设置
Android stuido作为google官方推荐的Android开发IDE,提供了一整套强大的静态代码分析工具,使用它们可以很好地帮助我们进行更加规范的开发。从一个常见的场景入手吧。几乎所有的开发团队的代码规范里面都有这么一条:不允许在布局文件中进行hardcode,原因参加见:
为了达到上面的目的,我们可以通过设置AS的code inspections来设置静态代码检查的规则,找到hardcode的配置:
Paste_Image.png
可以看到默认的hardcode配置的severity是警告,所以我们在xml中直接写字符串时,将光标放到去可以看到警告提示:
Paste_Image.png
但是这个提示也太弱了吧,我们将'severity'提升到error试试:
Paste_Image.png
注意,提升这个地方的等级不会对代码和其他静态分析工具如lint产生影响,也不会对运行产生影响,它的作用域仅仅是IDE展示
同样的,我们还可以设置很多其他的IDE静态代码检查,通过改变其severity达到更直观提示的作用,可以让开发者有一个直观的认识,哪些代码是合法但不合规的。如果有人不按照这个约束进行开发,那么代码中到处都是红色的错误(额,希望他不是个处女座..)。如果说通过IDE的code inspections是进行自律的话(实际上这个配置也是个人的行为),那么Android提供的另外一个静态代码工具lint就是一种对别人的约束了。
lint是Android提供的一个静态代码检查的工具,我们可以在gradle的构建task中加入link检查。具体的使用请移步到goole文档。link能够检查的东西很多,参考 。还是上面的场景,如果我的需求是代码中存在hardcode,那么所有人的代码都编译不通过(现实中不可能这么变态)。
lint工具可以通过一个xml文件来配置,它可以用来修改某些check issue是否忽略(典型的例子是第三方库里面存在问题),同时可以修改某些issue的默认等级。HardcodedText的默认等级是警告,我们升级成error,并在配置文件中增加lintOptions {
lintConfig file("lint.xml")
abortOnError true},这样在我们构建项目的时候如果发生错误,将直接中断构建。
Paste_Image.png
需要注意的是,点击AS上面的绿色的运行按钮是不会触发lint检查的,如果你想每次点击运行都进行lint检查,可以如下设置:
Paste_Image.png
Paste_Image.png
添加 run gradle task
Paste_Image.png
task填lint即可,这样在点击AS上的运行时,会自动执行lint,不过这样会导致每次运行时都会变慢。
热爱生活 热爱技术 热爱美食
计算机科学|互联网|美食
Stay hungry, stay foolish如何消除间接呼叫 Method 在 Android Studio 中的编译警告 - 简书
如何消除间接呼叫 Method 在 Android Studio 中的编译警告
如果有使用过 DI (Dependency Injection) Framework 像是 butterknife,或是 Bus 一类的 Framework 像是 Otto 或 EventBus,一定会撰写出 Method 是没有被自己开发的源代码直接呼叫的。这时在 Android Studio 的即时编译检查就会出现警告:
Method ‘...’ is never used
就像这篇里提到,警告的出现会形成一定程度上的困扰,最好是能够消除掉,毕竟这是一个无法避免的写法,但又不应该被看成是个问题。
照“”中的方法把检查规则整个取消掉,是个一劳永逸的方法。但是也把其可能的错误也抑制掉了,徒增程序质量上的风险,并非上策。
另外一个可行的选项是在方法上宣告 SuppressWarnings 的 Annotation,像是 @SuppressWarnings("unused")、@SuppressWarnings({"UnusedDeclaration"})、@SuppressWarnings({"UnusedParameters”})。跟前一个方案一样,应该显示的警告也同时被遮蔽掉了,不是最佳的方式。
所幸 Android Studio 也不是没有提供对策,在有问题的源代码上按下“alt+enter”,会跳出 Menu 并可以选择 Suppress for methods annotated by ‘...’ 项目。以
为例,所有以 org.greenrobot.eventbus.Subscribe 为 Annotation 的 Method 都不会再显示警告,所以问题顺利地解决了。
以上的解决方法应该已经很多人都知道了,只是还有一个衍生的问题。如果使用的 Framework 提供的 Annotation 不只一个,还是得要一个一个地重覆相同的动作,不能一次搞定吗?
这时可以开启“”中提到的 Inspections 选项画面,切换到“Java-&Declaration redundancy-&Unused declaration”项目。画面右方的 Options Frame 最下方有一个【Configure annotations...】的按钮,点下去之后会再跳出另一个小视窗。接着就可以在视窗的最下方新增【Add Annotation Class】或【Add Annotations Pattern】,前一个是新增单一个 Class,另一个则是使用万用字元来增加一整组的 Class。
以上说明的这些资讯都被存在 .idea/misc.xml 的文件中,打开后会看到类似以下的内容:
&component name="EntryPointsManager"&
&entry_points version="2.0" /&
&list size="1"&
&item index="0" class="java.lang.String" itemvalue="org.greenrobot.eventbus.Subscribe" /&
&/component&
如果你有莫名的控制欲,想要凡事都掌握在手中,可以直接修改文件的内容,也会达到一样的效果。
Bugs will find a way.

我要回帖

更多关于 微信已全额退款没到账 的文章

 

随机推荐