Recently updated to Android Studio 3.5 and now my code is full of annoying yellow lines with warning that I would like to suppress.
However, when trying clicking on the yellow bulb and use the solution proposed, it does not work, it just adds a comment-like line that has no effect, example:
When getting this warning:
"Use => for short members whose body is a single return statement"
Yellow bulb just adds a line above like this:
// ignore: prefer_expression_function_bodies
Any permanent solution to these annoying warnings in Android Studio?
The Dart analyzer does this and the ignore comment should suppress the warnings. By the way, this should not have anything to do with your Android Studio version.
There are two main ways to suppress specific lints "globally":
Use ignore_for_file comments. This is analogous to ignore, but works for the whole file.
Simply add the following somewhere:
// ingore_for_file: prefer_expression_function_bodies
Specify exclusions in your analysis_options.yaml file. You can always view documentation for all the lints, e.g. for prefer_expression_function_bodies, and any lint can be excluded in your analysis_options.yaml file (it should be placed in the same directory as your pubspec.yaml):
linter:
rules:
prefer_expression_function_bodies: false
Learn more.
Related
I opened a folder in Android Studio which contains a Kotlin script file (.kts). I configured a JDK as SDK in Project Structure (but I added no gradle files), and running the file as Kotlin script works fine. However the syntax highlighting is only PARTIALLY working, see below example (Linux Mint 19.3 and AS 4.1.3):
Some of the stuff missing:
unused variable should be gray (val unused)
to/forEach keyword should be yellow and italic
misspelled variable names should be red
bad style such as extra spaces should be underlined
etc.
What's even going on here? Is this some sort of "fallback" mode?
Any way to use the "full" syntax highlighting from normal Android projects, so I can spot mistakes earlier?
For reference, this is what it "should" look like (pasted into a random Android project):
Renaming the file to end in *.main.kts (scriptname.main.kts) enabled full highlighting for me!
I get this type of issues from time to time with IntelliJ IDEA. I haven't found the reason why it happens, neither do I know the 100% working solution. But here are the options that usually help me solve it:
Restart IDE
Invalidating caches: File > Invalidate Caches...
Re-import the project. Remove the .idea folder and the project.iml file and try to import the project again.
Update the IDE. Last time I had this issue, nothing helped but updating IDEA to 2021.1.
I hope some of these options will help.
In my GitHub README.md file, which is in the root of my Android project, I have code snippets like the following ones:
```xml
android:windowSoftInputMode="stateHidden"
```
```java
MongolToast.makeText(getApplicationContext(), "ᠰᠠᠢᠨ ᠪᠠᠢᠨᠠ ᠤᠤ︖", MongolToast.LENGTH_LONG).show();
```
However, in Android Studio these code snippets give errors
I don't want to be warned of supposed code errors in the README file. How do I disable all errors here?
Notes:
I know how to suppress inspections normally in code with #SuppressLint or going into settings and unchecking the lint inspection. I don't want these errors to be suppressed in other areas of my project, though.
Somewhat similar question (without an answer): Android Studio - disable errors highlighting for excluded files
After doing some further research I come to conclusion that these errors are not from Android Studio itself but there are plugins for markdown format like Markdown Navigator and Markdown Support if any of them is installed and enabled then you will see above errors in README.md file.
I think this spell check is built in feature of these plugins and can not be controlled from Android Studio.
One option what I think is to disable these plugins and you are good to go.
You can disable these plugins from (Android Studio 3.1.4 MacOS) Preferences > Plugins (or File > Settings > Plugins in Linux) by unchecking them and restart (don't forget it) your Android Studio:
First you need to create a scope (Settings->Scope)
and add the files you want to keep out of scope for the Lints you wanna suppress.
Then go to Settings->Inspections, chose the inspection you wanna remove,
and then on the right choose from the drop down your scope to define the wanted behavior.
In this case, my scope is called AVOID_LINTS, and won't show any typo warnings.
EDIT
In the first step, when you create the scope, you need to add your README to the new scope.
EDIT2
Where to find the scopes:
You may search for the files you want to add, select and click include.
Remove code type annotation, change from:
```xml
android:windowSoftInputMode="stateHidden"
```
```java
MongolToast.makeText(getApplicationContext(), "ᠰᠠᠢᠨ ᠪᠠᠢᠨᠠ ᠤᠤ︖", MongolToast.LENGTH_LONG).show();
```
change to:
```
android:windowSoftInputMode="stateHidden"
```
```
MongolToast.makeText(getApplicationContext(), "ᠰᠠᠢᠨ ᠪᠠᠢᠨᠠ ᠤᠤ︖", MongolToast.LENGTH_LONG).show();
```
Newer versions of Android Studio starting with 2022.2.1 Flamingo (at least from Beta 1) have an option to toggle "Show problems in code fences" under Preferences > Languages & Frameworks > Markdown.
Note that this toggles all problem types at the same time (typos, warnings and errors).
Is it not possible to comment out lines in the top-level Android.mk file of an Android Studio NDK project?
If I remove the Hello.mk line shown below, I get no errors. If I add a # then I get the error "This file is not part of the project."
How can I temporarily remove this line (i.e. comment it out) ?
For some weird reason Android Studio tries to treat your Android.mk as a C++ source. You can safely ignore this and many other warnings that AS displays.
OTOH, you can safely delete the line, instead of adding # in front: Android Studio keeps local history of the files that you edit thorough it; so, you can easily restore any changes to this file when you need that.
I'm using Android Studio 1.1.0 in Mac OS X 10.10. I noticed that when I wrote code like:
public void;
or even:
+ (bad) thisObjectiveCCodeShouleNeverCompileInJava:(ButSomehow *)itsNotComplaining
Android Studio didn't complain. Once I built it, Gradle showed the error, but the editor pane still did not. I attempted to use Navigate > Next Highlighted Error, I got the following balloon over my text cursor:
I let it sit for up to half an hour and still, no errors or warnings were ever highlighted. Similarly, placing the text cursor in/on a variable name does not highlight its usages in the file (but Edit > Find > Highlight Usages in File works fine).
I tried updating to 1.2.x, but I get this:
At one point, when attempting to Make Project, I got the following:
What's going on, and is there any way to fix this without reinstalling Android Studio from scratch?
Most of this is because I had Power Save Mode enabled. Unchecking this re-enabled error highlighting and other such features.
The Android Studio lint spell checker flags hex codes that look to it like words in certain files that would be better off unchecked, such as values/colors.xml and build/intermediates/dex-cache/cache.xml.
How do I tell lint to not spell check certain folders or files?
This can be done by using IDE scopes. In Android Studio (at least 3.4) you can configure each inspection per scope. The idea is that you create a scope that contains all files you don't want to be spellchecked, and then switch Spelling inspection off for this scope, but keep it on for everything else.
Add a new scope in Settings / Appearance & Behavior / Scopes that contains all files which you want to exclude from spell checking. For example, this pattern covers all svg files: file:*.svg. In your case it could be like file:*/colors.xml||file:*/cache.xml. IDE will highlight all affected files by green, so you can check if you entered correct pattern.
Then set up Spelling inspection, so that it is OFF for your new scope and ON everywhere else.
Had the same problem with colors.xml
I couldn't find a way to disable the check for a certain file, but I could get rid of the spellcheck on the hex codes.
Click Analyze->Inspect Code.
Choose Whole Project and click OK.
The inspection tool window will open with the results.
You should be able to see the problematic hex codes under Spelling->typo.
Right click any one of them and choose Exclude.
Did the trick for me. HTH