Android resource IDs suddenly not final, switch()'es broken Android resource IDs suddenly not final, switch()'es broken android android

Android resource IDs suddenly not final, switch()'es broken


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.


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);        } 


You should use view binding!

android {    ...    viewBinding {        enabled = true    }}