score:40
This happened about yesterday, when the SDK/ADT 14 got released:
As of ADT 14, resource constants in library projects are no longer final. This is explained in greater detail in http://tools.android.com/tips/non-constant-fields
There's a quickfix available from ADT 14: http://tools.android.com/recent/switchstatementconversion
To quote from the rationale:
When multiple library projects are combined, the actual values of the fields (which must be unique) could collide. Before ADT 14, all fields were final, so as a result, all libraries had to have all their resources and associated Java code recompiled along with the main project whenever they were used. This was bad for performance, since it made builds very slow. It also prevented distributing library projects that didn't include the source code, limiting the usage scope of library projects.
The reason the fields are no longer final is that it means that the library jars can be compiled once and reused directly in other projects. As well as allowing distributing binary version of library projects (coming in r15), this makes for much faster builds.
score:0
Just add this snipped in your module-level build.gradle
file:
android {
...
lintOptions {
disable 'NonConstantResourceId'
}
}
More: https://developer.android.com/studio/write/lint#gradle
score:2
You should use view binding!
android {
...
viewBinding {
enabled = true
}
}
score:2
Just add parentheses:
switch (view.getId()) {
case (R.id.view1):
break;
case (R.id.view2):
break;
}
score:5
Google recommends you use if/else conditions
http://tools.android.com/tips/non-constant-fields
To change them automatically you can place the caret on the switch
keyword and press Alt + Enter on Windows (Option + Enter on Mac) and select Replace 'switch' with 'if'
score:12
You could switch over to using If/Else statements and the warning will go away.
Sample:
@Override
public void onClick(final View v) {
//finds which button was pressed
final int buttonView = v.getId();
String current = fromEditText.getText().toString();
if (buttonView == R.id.bA) {
current += getString(R.string.a);
}
Source: stackoverflow.com
Related Query
- Android resource IDs suddenly not final, switch()'es broken
- Android Resource not found exception when trying to add a datepicker to layout
- Android Lint: Unused Resource Warning Not Going Away
- How to Find All Resource IDs in Android
- could not resolve resource android eclipse
- Updating an Eclipse Android project via Git - image resource not updating
- Android not recognizing string resource
- android eclipse resource image not found in drawable
- Google app engine endpoints for android suddenly not working when trying to launch in eclipse
- Android Eclipse compiler do not see the layouts and ids
- Updated support library, now resource files are not recognized by an Activity - Android
- Physical android device suddenly not found by Eclipse
- resource ids in eclipse not shown
- Cant figure out suddenly im getting error in Eclipse Android " Source not found " why?
- Developing for Android in Eclipse: R.java not regenerating
- Android Eclipse - Could not find *.apk
- Android app in Eclipse: Edit text not showing on Graphical layout
- Android Device Chooser -- device not showing up
- Android xml error: "No resource found that matches the given name" with RelativeLayout (@id/LinearLayout_acc, @id/ProgressBar_statusScreen)
- Why is Eclipse's Android Device Chooser not showing my Android device?
- Eclipse: The resource is not on the build path of a Java project
- eclipse not showing Avd manager window and android project
- Eclipse shortcut keys are not working suddenly in Windows
- Android ADT error, dx.jar was not loaded from the SDK folder
- Android Eclipse Plugin: Instrumentation Test Runner not specified
- android debugger does not stop at breakpoints
- HTTP Status 404 - The requested resource (/) is not available
- Just upgraded my OS X to Yosemite, Android Device Chooser not showing device - what to do?
- Android Maven Could not find tool 'aapt'
- ADT will not allow creation of Android Activity
More Query from same tag
- Eclipse c++ how to reinclude excluded file from build
- IFile from String in java
- How can I hide long class paths in stack traces to make them readable?
- onLocationChange() not getting called? Calculate Distance Travelled -Android
- Eclipse birt can't establish connection to derby database
- Program works on Eclipse but not PuTTy
- The connection to adb is down, and a severe error has occurred
- Eclipse Errors/Warnings ignore assert in unused variable analysis
- Eclipse Package Structure messed up when importing gradle project
- Eclipse: Project cannot reference itself
- Eclipse JDT static field modifiers
- Maven install succeeds, but jar doesn't work correctly from bash (CLI)
- Eclipse EMF - Is there a way to reference a class that is part of a model in a different eclipse plugin without having to store the tostring()?
- What code should i use to make the font-size adjust to the size of any device, in eclipse using Libgdx?
- How do I combine projects in eclipse?
- python: How to debug multiprocess? (using eclipse+pydev)
- How to display huge variables in eclipse IDE
- Testing performance of Java project in Eclipse using VisualJVM
- Eclipse + PDT performance tips?
- project yyyx is associated to an unknown sonarqube server(). please fix project association or add server in sonarqube plugin perfrences
- File-->New-->Wizard doesn't show up the Android project post installation
- How to create files in New Project Creation Wizards
- Warning after importing Python library into Eclipe
- Trying to re-direct path of a file from c drive to tomcat apache server
- How to add copyright to Eclipse Helios?
- Spring 4, Mockito 2, Junit 4 in Eclipse Oxygen - DAO not mocked
- Eclipse Helios 3.6.2 won't create generated java files in android project
- Process finished with exit code -1073741819 (0xC0000005) of java application because of below pom file
- Missing output when Generating JavaDoc on Eclipse Mars.1
- Subclipse ignores "Accept Permanently" when "Accept Digital Certificate" dialog is shown