How to disable code inspection errors in README.md file in Android Studio - android-studio

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).

Related

Android Studio suppress warnings

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.

Android Studio setting the background color for Field requires API level xx

In Android Studio, there is a background color effect for some fields(e.g. View.SYSTEM_UI_FLAG_LAYOUT_STABLE, View.SYSTEM_UI_FLAG_FULLSCREEN).
Example:
When I put the mouse on it, the pop-up is displayed telling me that "Field requires API level xx (current min is xx)".
It's very usuful. So I can make some conditions for each Android OS version.
I've remove the effect by mistake. but I don't remember what item on setting is for it.
So, I really want to revive the background-color effect and the message pop-up for "Field requires API level xx (current min is xx).
Naturally, I can revive it by re-installing Android Stuido or resetting the IDE Setting to Default.
But I already made alot of changes on Android Studio Setting. and I don't want to lose it..
I've never found a item to revive it in Android Studio's setting.
please help me
If you press Alt+Enter you'll see that it suggests #SuppressLint("InlinedApi") to disable the warning.
Doing a search for "inline" in the IntelliJ/Android Studio settings leads to this:
Go to File > Settings > Editor > Inspections > Android > Lint > Correctness > Using inlined constants on older versions (you can also search to find it). Here you can disable it by unchecking it; remember to click apply or OK to save it.
For reference, it's in Android Studio as well under the same location.
For changing the background color, click the severity spinner and click "edit severities". Click warning or create a new severity and set the color (the settings should make it easy to see). Reenabling is in the same location by checking the box or changing the severity level to warning or error for that matter.
Checked in IntelliJ 2018.1 and Android Studio 3.1.2. It might not be present in older versions of either IDE, or it might be in different locations.
There are wasy to disable inspection. But Disabling inspection is not recommended, because
You will not get further important suggestion about some version requirements. (like if particular method require 21 and you are targeting API 15, then it does not sound good to have that method.)
If some user is running your app on 16 version then your code will crash, because it was not added in that API level.
Got that?
Solution:
1.You can check API level in your code. for that only press alt + enter on that suggestion you said, and accept changes. It will generate a code like this.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {}
2.You can increase your minimum sdk level from app level build.gradle
defaultConfig {
...
minSdkVersion 16
...
}

Android studio consecutive comments folding

I use code regions in Android Studio this way:
When collapsing all my code, Android Studio used to do this:
But with the latest update (3.1.1), it now does this:
Is there a way to revert to the previous behaviour?
EDIT: yes I've been to Preference > Editor > General > Code folding. I unchecked all the boxes, restarted, the problem is still there.

Android Studio Resetting Changes to Default Code Style

I'm here today because I'm having an issue with Android Studio. I don't know if it existed on previous versions (I don't remember this being an issue, so I doubt it was a problem on a previous version), but currently I am using the Android Studio V2.1 Stable release.
My issue is that if I launch Android Studio (I happen to be on Windows, 64-bit Android Studio) and at the Start Screen/Page, I click Configure>Settings>Editor>Code Styles, and change the default parameters on any of the languages (XML, Java, HTML, etc.), the Default profile is copied to a new profile (Default(1)) and the new settings get applied to each profile.
If I Apply these changes and exit Android Studio, and launch back up and follow the same method...the settings have completely gone back to what they were before I changed them, with the exception of the Default(1) copy profile. But from my experience, Android Studio doesn't build new projects based on this Default(1) copy profile, it builds them on the Default profile. Which means all of my adjustments to using indents and not spaces, keeping indents on empty lines, etc. all do not get carried through to the actual project files, leaving me to have to go back into the settings with the project loaded up and change all of these parameters again. That's just asinine. Please tell me I'm missing something here and that there's a simpler way of achieving the ability to keep a code style template that I can use on all of my projects!
Perhaps it would be better to report or consult on this using the Android Studio feedback site. If that's the better option, I'm willing to do that too.
Thanks everyone!
What I do in that case is
Go to Preferences
Code Style
Select scheme you want
Click Settings cog
Click copy to project
Some OKs and then it works.
After selecting the code style that i want, opened the gradle.properties file in root folder of the project and deleted the following line
kotlin.code.style=official
deleting the above line, prevents the code style resetting to default.
Go to Preferences
Code Style
Set Scheme to Default [IDE]
Click restore defaults
The simplest way I found to reset the default settings is as follows:
In Android Studio, click on File.
Settings (Ctrl + Alt + S)
Under Editor in settings
Select Code Style
Next to Scheme: select the three dots to access the scheme options ()
Select Restore Defaults
A Confirmation Dialog Box will be displayed to confirm if you want to revert back to
the default settings.

Android Studio - Auto complete and other features not working

I installed android studio.. it was working fine. Now all the sudden, none of the auto complete features are working.. I can type anything anywhere no variable checking, no help with functions or checking anything. I can still compile the project and I get errors when that happens.
Can anyone please help me out with this issue.
#1 From Build menu (of your Android Studio), click Rebuild Project option.
#2 Then once rebuild completes, go to File > Invalidate Caches / Restart... and Click on Invalidate an Restart button.
This really works for me.
Source: https://code.google.com/p/android/issues/detail?id=61844#c4
#1 Rebuild is required, because Android-Studio does simply rely solely on Gradle's build-result (without static-analysis support, at least at time of writing, 2022).
#2 Clearing cache is required, because the previous build-result (before above rebuild) may be indexed, which makes Android Studio ignore latest Gradle build-result
(this is a very good speed optimization, but a very bad Developer-experience as well).
There can sometimes be other reasons too, which is why there are many other answers posted here.
You can also check if Power Save Mode on File menu is disabled.
Close Android Studio
Go to C:\Users\UserName\.android and rename the folder:
build-cache to build-cache_old
Go to C:\Users\UserName\.AndroidStudio3.x\system
OR (for Android studio 4 and Higher) go to C:\Users\UserName\AppData\Local\Google\AndroidStudio4.x
and rename these folders:
caches to caches_old
compiler to compiler_old
compile-server to compile-server_old
conversion to conversion_old
external_build_system to external_build_system_old
frameworks to frameworks_old
gradle to gradle_old
resource_folder_cache to resource_folder_cache_old
Open Android Studio and open your project again.
Originally use:
compileSdkVersion 32
targetSdkVersion 32
And an update to 33 appeared, I updated it and the suggestions in the XML no longer appeared, I went back to 32 and now the suggestions appeared.
Close Android Studio
Go to c_users_path_on_windows/.AndroidStudio3.5/system/
Delete the cache folder
Start Android Studio
This works for me.
Most of the times i have seen that the problem is that Power Save Mode is enabled, to disable go to Current inspection profile (lower right corner in Android Studio).
I have not run into this problem personally, but try checking the following settings (File -> Settings or Alt+F7):
Project Settings [name]
Inspections - ensure that Android and Android Lint is checked, or alternately just set it back to default using the dropdown box at the top.
IDE Settings
Editor -> Code Completion - ensure the Autopopup code completion is checked (and check the rest of the settings based on your preference.
Uncheck "Power Save Mode" in "File" tab
If nothing works (like happened with me ) go to your user profile in windows at %userprofile% . You will find folders there (hidden) named with the version of the android studio you are using and prefixed with a dot.
like .AndroidStudio3.1. Just delete that .
Solution: Try disabling "File -> Power Save Mode" in Android Studio (Beta) 0.8.14 - Mac OS X
On windows, the option can be at some other place.
I had the same problem then I recalled that while exploring the new android studio, I switched on the "File -> Power Save Mode" to see what it does?
I disabled the power save mode and all those intelligent features were back.
It turned out that in Power Save Mode, Android Studio switches off the modules responsible for features like Smart Code Completion and Code Analysis.
I had a similar problem where none of the other solutions worked.
Closing Android Studio and then deleting the .idea and build folders resolved the issue.
Disable Power Save Mode and Invalidate Cache and Restart.
For Artic Fox 2020|3.1 Version: Auto Complete Suggestion Problem.
Please Follow the Following Steps:
Close Android Studio
Locate caches folder in C:\Users{username}\AppData\Local\Google\AndroidStudio2020.3
and Delete it.
Open Android Studio Again.
Check your Android studio version and Target that version folder at below location
C:\Users{username}\AppData\Local\Google
Note : AppData folder is Hidden in Windows
This Solution also works if android studio mess up with xml files and java code. Don't! modify your code otherwise IDE won't able to change it to default. If you see such messy code just follow above steps and your code will be fine again.
It's Working
Disable Power Save Mode
Untick Power Save Mode Option ::
File -> Power Save Mode
There is a power saver mode in android studio if accidentally you click on that it will disable code analysis which will reduce the battery consumption and performance will also increase but it will not detect any errors and do auto complete operations.
To disable power saver mode
- Go to File Menu of Studio
- Uncheck The Power Saver Mode
In your IDE code analysis will be shown using an eye symbol at the right corner of your android studio.
If Green means it is enabled and there is no error in your code.
If Red Means It is enabled but there are few errors in your code.
If It is white or blur then code analysis is disabled
Just remove all the folders named AndroidStudioPreview
On Windows:
Go to your User Folder - on Windows 7/8 this would be:
[SYSDRIVE]:\Users[your username] (ex. C:\Users\JohnDoe)
In this folder there should be a folder called .AndroidStudioPreview
On Mac OS X
Remove these files:
~/Library/Application Support/AndroidStudioPreview
~/Library/Caches/AndroidStudioPreview
~/Library/Logs/AndroidStudioPreview
~/Library/Preferences/AndroidStudioPreview
There can be several things which cause this.
Make sure you've write the correct version in targetSdkVersion and compileSdkVersion.
Make sure targetSdkVersion and compileSdkVersion are same.
Other solutions can be:
Invalidate caches & restart Android Studio from File → Invalidate Caches / Restarts...
Clean your project from Build → Clean Project
Rebuild project from Build → Rebuild Project
Make project from Build → Make Project [this process may take some time]
Be sure to check for IDE errors by clicking the button at the bottom right of android studio.
In my case, there was a bad plugin, and the IDE Fatal Errors window prompted me to uninstall the plugin. (I wish I'd known about this feature before spending half a day invalidating caches, deleting folders, and reinstalling android studio with no luck.)
It worked for me.
From menu select:
File -> Power Save Mode
and make sure it's disabled
Go TO Left Side Top File Option
Then Click To Power Save Mode
Disable Power Save Mode That Fix This Issue
In my case, when I switch keyboard language to English, the auto complete works again.
if the autocomplete isn't working for you in Android Studio, just press File and uncheck the Power save mode, it should work fine after that.
if power save mode is already unchecked then first check then uncheck them.
If you have a library project included, make sure the library has the dependencies in build.gradle listed using the api configuration, not the implementation configuration.
Also make sure that the project that includes the library has all the dependencies listed (using the implementation configuration is fine here).
'The file size (2561270 bytes) exceeds configured limit (2560000 bytes). Code insight features are not available.'
Had this issue for days with none of these proposed solutions working before eventually getting this message in yellow under the tabs after adding a line of code. Removing the line of code eliminated the message but not the issue. There appears to be a code size window where you lose insight features but don't get this message, at least for me. Once you go over a certain point the message finally pops up. The suggested solution in a different thread for this issue was to edit 'Help/Edit Custom Properties' to increase the configured limit, but just opening this brought up a dialogue asking if I wanted to create an 'idea.properties' folder so I decided not to risk that approach over eventually cutting the file size.
If sometimes this problem can occur if you misspelled a file extension or make a file without adding an extension.
Check you have added the file extension correctly.
I think that answer may help you.
I'm using mac and suddenly the code completion (^space) not working. There are no errors. Turned out the android studio's shortcut was conflicted with system's shortcut. I don't know why it suddenly happen because it was fine before, maybe there was an update on my Mac.
See below setting for the conflicting shortcut
In my case, C:\Users\UserName\AppData\Local\Google\AndroidStudio2020.3\ just delete caches folder and restart android studio. after deleting this caches folder my problem was solved :)
I encounter with this problem while adding a kotlin library into my project on mac. Changing macbook language to english solved this problem. I also had some weird problems with auto-generated databinding codes, those are also solved.
Try Invalidate caches/Restart from File in Menu Bar from android studio.
Close Android Studio
Go to
C:\Users\YOUR_USERNAME\.android
and rename the following folder to:
build-cache to build-cache_old
then Go to (Android studio lower then version 4)
C:\Users\UserName.AndroidStudio3.x\system
OR (Android studio 4 and Higher) Go to
C:\Users\UserName\AppData\Local\Google\AndroidStudio4.x
or
C:\Users\UserName\AppData\Local\Google\AndroidStudio2021.2
depending on your version and rename these folders:
caches to caches_old
compiler to compiler_old
compile-server to compile-server_old
conversion to conversion_old
external_build_system to external_build_system_old
frameworks to frameworks_old
gradle to gradle_old (if exists)
resource_folder_cache to resource_folder_cache_old (if exists)
Open Android Studio again and the autosuggsion will be fixed.
and You can also check if Power Save Mode is disabled or not from the File menu.

Resources