Android Studio no longer autocompletes certain imports - android-studio

After having updated Android Studio to Chipmunk | 2021.2.1 Patch 1, and migrated some of my projects to null safety and done lots of stuff, I suddenly noticed that when I start typing an import name, Android Studio no longer fills in the full file name, the way it used to! Like if I type:
import 'mat'
it used to suggest to fill in:
import 'package:flutter/material.dart';
but it no longer does! Instead, it suggests:
import 'dart:math';
so... it finds Dart packages but not Flutter packages? Even if I download a Flutter package by depending on it in the pubspec.yaml file and running flutter pub get, autocomplete does not seem to find it. I have to write the full file name.
I've also noticed that if I'm in a file in a sub folder of my lib folder, say in lib/screens/screen_a.dart, and there is also a screen_b.dart in that sub folder, I can start typing:
import 'scr';
and AS will suggest:
import 'screen_b.dart';
just as it used to. All very well. But if I want to import a file from a different sub folder, such as cool_widget.dart from lib/widgets/, I used to type:
import 'widgets';
and it would fill in:
import 'package:my_project_name/widgets/';
from which I could type:
import 'package:my_project_name/widgets/coo';
and get the whole file name:
import 'package:my_project_name/widgets/cool_widget.dart';
That no longer happens! Instead, I now have to type the entire path above before Android Studio seems to recognize it...
I also don't get any autocomplete suggestions for project files within the lib folder if I'm in the lib folder. It's only if I'm in a sub folder that I get any suggestions for project files, and only from within that same sub folder. This is very difficult, as it slows down the import process considerably.
The problem of not finding other project files is there in several of my projects, including those I haven't yet migrated to null safety, but not in all. The problem of not finding Flutter packages but finding Dart packages also seems to be there only in some projects, and not necessarily the same as above...
I really can't say what I did that triggered this... Please help?
Things I've tried
I've done flutter clean and Invalidate caches and restart. I've also deleted a number of build files and directories, including the entire .gradle directory (several GB), and restarted, but nothing helped.
I've also looked through all my settings to see if there's something there, but I didn't find anything obvious...

This problem is caused by regressions in the new completion protocol introduced in a recent Dart version.
The fix has been implemented in this commit, and will be included in Dart 2.18.
This fix, along with a slew of other autocompletion fixes, are also in the process of being cherry-picked into the stable channel here.

Related

How to fix grayed out import module in Android Studio?

I am trying to merge a few projects into one and therefore have to import either the projects or the modules. When i try "import project..." however, Android Studio will just open another instance of itself, not making any changes to the project. When i try import module, it will gray out the "Finish" button as soon as a module is checked for importing. If none is checked, it will let me continue... and do nothing as expected.
I am using Ubuntu and Android Studio Arctic Fox (newest version, freshly updated)
I already reinstalled and tried to fiddle around with project settings without any results.
I have not found a solution, but i found a workaround. It is possible to merge projects manually by copying the desired module folder "as is" into the new project folder and then copy the file ".idea/modules/modulename.iml" from the old project to the new one. Then one has to add "include ':modulename'" to the settings.gradle and add the path to the .iml file to .idea/modules.xml according to the format the other modules are saved in. Manually invoking gradle synch will update the project structure or show errors, if some were made.

Android Studio: import org.tensorflow.Operation does not seem to work

I am using the latest Android Studio to create an image recognition project. I am using a .pb file downloaded from Github.
I have added "implementation 'org.tensorflow:tensorflow-android:1.5.0'" in build.gradle file.
When I go to the java file, the following two import statements are "unused"
import org.tensorflow.Operation;
import org.tensorflow.contrib.android.TensorFlowInferenceInterface;
Could somebody help? I am new to TensorFlow. Thanks!
Please ignore this question. I misunderstood what "unused" means.
Usually you don't have to add your imports manually. Android Studio shows some variants for imports and adds it automatically.
If your imports are grey and you get "unused" that means you didn't use them in this class so you can simply delete them.
It happens sometimes when you decided to write all imports before you actually code anything using these classes.
If you leave this warning nothing bad will happen but you use more memory than you actually need.

Only partial syntax highlighting in Kotlin script file

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.

How To Restore Resharper Options from Computer

With the release version of ReSharper, I made lots of ReShaper option changes. In each case, I chose to save those changes to my computer, rather than the solution or source control.
Unfortunately, I incautiously installed the 2021.1 EAP 9 version, then made lots of changes to those options, also saving them to the computer. Don't think that was a very smart move. This version, I think, is causing me all kinds of fits with code hints/completions, to the point where it takes many tries to code a simple method.
I am going to downgrade to the latest release version, but want to restore all those options changes from the options XML file on my computer. However, I can't find a means to import the file.
How does one do this?
Thanks
If you're asking how to import an XML file with settings, then open the "Extensions | ReSharper | Manage Options" dialog and then "Import and Export | Import from File".

Rename Android Studio project causing a bunch of errors and java files missing

Following some links here I tried to rename a project. I went to c:\path\to\AndroidStudioProject and renamed the folder there, then found the .idea file and changed that. Now the project loads but java files are missing! However, on clicking java (in the bar at the top), then com I can see them each with a small red j.
I then looked in module Gradle build where there were 3 files, one with the new name and 2 older ones which stated that they did not belong so I deleted them, copying the compile info into the new one. Naturally on doing a Sync Now I get a bunch of errors.
Why does this have to be such a complex operation? Can anyone assist?
After you rename the folder, open the project in Android Studio. From there, right click something that needs to be renamed (e.g., module, package names, etc.) and use Refactor->Rename from the context menu. Keep doing this until everything that can be refactored is.
You will need to manually change the value of applicationId in the app-level build.gradle. Obviously, things like #string/app_name will also have to be changed manually. I recommend making these manual adjustments from inside Android Studio rather than directly editing the files. That way you'll know immediately if you break something.

Resources