How to find a specific warning in the whole project - android

Is there a way to search a specific warning in the whole project?
e.g. I have this warning in one of my LinearLayouts:
Set android:baselineAligned="false" on this element for better
performance
and I want to check if there are any similar warnings in other LinearLayouts in my XMLs. I know about Analyze -> Inspect Code but it doesn't help me in this situation and in this kind of problem.
How can I find them?

There is no filters but you can select custom scope in your case is xml folder as
file[app]:src/main/res/layout/*
Or you can Run Inspection by Name ... and this should be -> Missing baselineAligned attribute

Related

Proguard/R8 do not rename classes used in XML layouts

I need to obfuscate the whole code of an Android library except some classes/methods which will be used by developers.
I succeed except that some classes invoked in my XML layouts have not been renamed and I struggle to find an option in R8/Proguard or a trick to force it, even if I have to update manually or with a script these classes in my XML layouts (I know that R8/Proguard do not edit them itself) thanks to the generated mapping.txt file.
The closer question I found is Proguard (R8) obfuscate custom view names but it did not solve the issue I face, R8/Proguard is still ignoring the rename for these classes :/
If anyone has an idea, you're welcome :)
Thanks for your time and knowledge ;)
[EDIT]
I finally gave up and put placeholders in my XML layouts for my custom views and inflated them at runtime.
It's a shame that Proguard/R8 can not handle custom classes renaming in XML layouts with aapt :/
For info, I ran into issues also with the use of fragment items in my XML layouts where the name property is not renamed while the corresponding class is...
So for these too, I had to put placeholders and inflate them at runtime...
I let the question opened in case someone find a trick one day ;)
There is currently no support for renaming inside XML layouts. As part of the compilation process the aapt2 tool will generate -keep rules for the names present in the XML layouts, so the Android runtime will be able to perform the required reflection for layout inflation.
By adding the following option to the configuration (proguard-rules.pro)
-printconfiguration <somefile>
the full configuration can be inspected including the rules generated by aapt2.

Assign a view ID programmatically in Android

I'm trying to create a RelativeLayout with several children programmatically. To make the rules like RelativeLayout.RIGHT_OF work, the child views must have proper IDs.
However, when I try to assign an ID, Android Studio flags it as an error:
view.setId(123);
ERROR: Expected resource of type id
Found it:
view.setId(View.generateViewId());
You have two options:
This is not a compiler error. It is just editor validation error as this is not a common way to deal with Ids. So compile and run with no problems
Use pre-defined list of Ids with type "id" as this accepted answer https://stackoverflow.com/a/8937477/1657333 so the editor will be happy.
In Android Studio click on lightbulb on line with this 'error'. And select 'Disable inspection' in first submenu.
As others have said, you shouldn't be using Integers directly in this case. There are some very rare cases where you might need to do this or in general suppress validation warnings. If so then you need to look into Lint.
In Android Studio you can click on the red light bulb at the left side of the line of code. This will show a context menu with a list of methods of suppression.

Annoying default formatting

I am working on a simple android application in eclipse IDE and I got a little yellow icon on the left hand side of a line of xml code that looks like a light bulb with an exclamation mark beside it. When I hovered over, it says "[I18N] Hardcoded string "input..., should use #string resource input". The running and debug was successful but I just want to get rid of it as I find it annoying. What should I do?
If it's annoying, there is a reason. You totally should use #string resources instead of your hardcoded strings. All you have to do is to put your string in res/values/strings.xml and reference it in your layout via #string/my_string_id_here.
This is extremely useful for multi language support, or for plurals strings.
You can learn more here.
Hope this will help you.
The right way:
Move all your strings into resource files, as suggested, and reference them in your views like so: #string/mystringname
The "other" way:
Turn off Lint warnings in Eclipse in Window/Preferences/Android/Lint Error Checking
Both ways will remove that annoying triangle :)
This warning is there because hardcoding strings into the android app's Java source code is not recommended. It will compile fine - but Android Lint will complain about it, so that's why it's a "warning" and not an "error". Generally, it is preferable to define them in the separate "string.xml" file.
If you want to know why, check this answer.
For an example, check this answer.
You should also take a look at the official documentation for string resources.

Hide warnings in layout files

I updated Eclipse and SDK and now in every xml file the TextViews have the warning "Consider making the text value selectable by specifying android:textIsSelectable="true"".
Is it possible to hide the warnings, I hate to have my project with a lot of yellow exclamation marks.
Go to the propeties of your project. Go to Android Lint Preferences. Search for SelectableText and change the severity to ignore.
You can also do this in Eclipse preferences for all projects.
There is a good reason for this warning. By just disabling it, you are basically ignoring user interface guidelines of Android and you are not using the full potential of the user interface of your app. Therefore looking at each text view and explicitly setting this attribute to either false or true will increase the quality of your app.

How to rename widget ID's in Eclipse?

I am working on an app built upon an example from a tutorial. Now the different widget IDs no longer reflect their purpose so I would like to rename them. However, this seems quite a task as the IDs are used in multiple files.
Is it possible somehow to rename the IDs so the changes are migrated into the other files in the project? That is pretty much similar to refactor source code names, but for widget IDs.
I don't think a tool like that exists in Eclipse. The easiest way to do it manually is to rename an item in the XML layout and then track down the errors in the Java classes. If you do it one-by-one then you should have it cleaned up in a minute or two.
You can try to use the Find/Replace function is Eclipse. I have found this useful several times when changing ID's or something to that effect. Let us know what you end up doing.
In eclipse:
Go to the xml layout -> Graphical Layout -> Properties then click the ... button near the desired field:
In case anyone stumbles across this problem now, you can rename the ID from the visual layout editor and it will do all the hard work automatically.

Categories

Resources