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

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.

Related

Android Studio no longer autocompletes certain imports

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.

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.

Android Studio doesn't show import suggestion

After trying adding the GSON library with "compile 'com.google...' ",I get a situation that when I try to import modules the IDE suggest me nothing except static and *. So I have to type everything. How can I fix it? I created new projects and still get this problem.
We're in 21 century and using modern IDE Android Studio. Why do you want to import packages manually just like we import when writing code in simple Notepad or any other text editor?
Just type the name of class which you want to use in your code. And the IDE is smart enough to show the suggestions which relates to your typed keyword.
I get a situation that when i try to import modules the IDE suggest me nothing except static and *.
Yes, it's indeed. Here is my screenshot
How can I fix it?
Very simple. Just type class name whatever you want and select it from suggestions. Android Studio automatically imports it.
For example (as per your requirement) you want to import #SerializedName() annotation. Type #Ser and hit Ctrl + Space and see the magic.
Now the Android Studio showing me the suggestions which matches with keyword Ser and I'll select SerializedName (com.google.gson.annotations.SerializedName). That's it.
Hope it'll be helpful.

Android Studio auto importing wrong Context class

Android studio has been auto importing io.realm.internal.Context instead of android.content.Context and its getting very annoying. I have to highlight and manually type the import statement because Android Studio continues to auto import the wrong class. Is there any way to tell the IDE to not auto import certain packages? I never use the Realm context class, and whenever I reference Context for the first time it always erroneously imports that class.
It is possible to tell the IDE to not auto import certain packages. Please refer following steps:
In Android Studio go to
Settings>Editor>General>Auto Import
In the dialog box that opens, type the name of the class or a whole package to be excluded, and click OK.
Use new (Alt+Insert) and delete (Alt+Delete) to manage the list of classes and packages that IntelliJ IDEA shouldn't place to the suggestion list.
Apply changes and close Settings/Preferences dialog.
This will surely help :-)

Android Studio Not Recognizing Imports in TextView

I want to watch android sources code, but Android Studio has so many errors in base Android code. How do I fix these?
Since no one has jumped in here to help with this...
The longer answer here is that the imports (in red) are failing because Android Studio can't find them. So all the calls made to those libraries are failing. So ALL your code after that is full of errors.
For instance, the android.annotation.ColorInt seems to be broken. A quick Google search provides THIS: https://developer.android.com/reference/android/support/annotation/ColorInt.html
Which tells me that the reason that dependency is broken is because whatever you have there is deprecated and should now use a new reference.
Continue with this sort of research and your problem is solved.

Resources