Android Studio Jetpack compose Auto imports are not working anymore - android-studio

I've started today with Android Jetpack Compose. At the beginning it worked all fine. On some classes you just have to watch that you get the right package. But on some Point I've messed something up an I don't know what. I've just wanted to Import a package and then some context menu popped up, I accidentally pressed 'Ok' and since then the "Import" doesn't show up anymore when I write a class from a compose package.
There is surely an option I've turned off but I don't know what. Can anyone help me with this?

Go to file > Settings in Android Studio then search in the settings for "imports".
Under editor click Auto Import and scroll down to the bottom.
The check the two boxes for Kotlin as shown here:
.

Related

visual layout editor does not allow drag&drop

I'am a newby in android studio and learning a lot, but now have a problem where i cannot seem to find the answer to.
In android studio you can visualy drag&drop your screen.
I have seen it can do al lot (although you sometimes need the xml) but for me it is not working at all.
I mean i cannot drag&drop any widgets on the screen at all.
Tried changing the theme: no help (really tried a lot of them)
Tried a complete new project: same story
Tried other APK verion: same story
Tried Invalidatd caches / restart: no help
Even with a new project (EmptyActivity) it add's a android.support.v4.widget.NestedScrollView and then gives error's on that
(Failed to find style 'coordinatorLayoutStyle' in current theme).
It also gives an error on layout_height/layout_with not being there. But they are there for each widget.
Please do not missunderstand: when i execute the project i runs just fine (both on phone and emulator) but the visual builder for the screen.....:-(
Does somebody knows how to solve this.
If more info is needed please ask.
Any help is more than welcome.
There are several things that could be causing this:
Your caches could be messed up. Try going to
File > Invalidate Caches / Restart ... (I know that you already tried this, but posting for future views.)
Also, make sure that you don't have Drag-n-Drop with ALT pressed only checked in your Settings (Appearance & Behavior - Appearance).
Finally, in a default project created in Android Studio, there are two XML files created for each layout. For example, content_main.xml is embedded within activity_main.xml. Make sure that you are using content_main.xml for your design work.
In the end i fixed it by changing the SDK version in de gradle file.
still do not understand why it was wrong as studio genereded it that way but now it works so.... for me: case closed.

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

How to show Android Studio's Messages Window?

When I build a project and there are errors, the Messages window that shows all the errors does not always show. I have to build the project (i.e. Ctrl + F9 ) twice or more in order to see the window.
When the window is not shown, View > Tool > Messages Alt + 0 is grayed out as shown by the following screenshot. How can I show the window when there are build errors?
I am running the latest Android Studio on Windows 8.
[Edit] 2018-04-02
Android Studio 3.1 seems to have this window removed, many people may come here because of missing the Messages Window due to a different reason, and yuval's answer may be the right one in this case.
I got here after upgrading to Android Studio 3.1, in which they removed the Messages window, replacing it with the Build window. After some poking around, I found this button on the left side of the Build window:
Clicking this button toggles the view between the new "Build" view and the old "Messages" view.
UPDATE: per suggestions in the comments, since this doesn't really answer the asked question, I opened it up as its own question: Where is the Messages Window in Android Studio 3.1
UPDATE 2: In Android Studio 3.3 the button now looks like this:
UPDATE 3: In Android Studio 3.6 the button is gone. Instead, the build window is permanently split between text output and visual output. If you can't find the text output, it might be fully collapsed, so look on the top right of the build window for something like this:
And try to drag it left to reveal the build window, like this:
It was a bit different in my case. I just closed the Message Tool Window with this red cross on the left and then this window completely disappeared and would not show again even after several rebuilds, View > Tool > Messages Alt+0 was also grayed out. The only thing that helped to bring the Window back is to break the build, so it would be some compiler errors. After that the window has reappeared showing those errors. Now the window is still there, does not vanish. Hope this helps somebody.
Just to have the whole picture. Go to the Build and then on the left side of the window you will find your Messages icon.
Build -> Make Project
(Ctrl+F9 or ⇧⌘F9)
Can't find the button #yuval provided, but here it is to toggle to show it

Can't add modules on project structure in Android Studio

The structure project window does not show all the options and I can not add libraries or modules.
Check the image:
And this is how it should look with all the options:
I try to fix that reinstalling androidstudio, but it didn't work.
I'm using Android Studio 2.9 and i already have working ABS, but i can't make work HoloEverywhere
Is there any solution for this problem?
Beforehand, thanks
Do Right Mouse Click on visible package, then select 'Open Module Settings' - it will give you ability to add Module.
I added a screenshot to show exacly what I mean.
It's a workaround but it give you ability to add module to project

Where is the warnings screen option in Android Studio?

I want to see warnings of my code in Android Studio, But i am unable to find the option to display warnings view. In case of eclipse we can see the warnings in the "Problems" view.
Can anyone suggest me, how to view warnings in android studio?
If, on the toolbar, you click Analyze -> Inspect Code; then in the window that pops up select how much of your project you want to inspect (I usually do Whole Project, but you might want to select a specific module), then click okay.
Android Studio will work for a bit, then the inspection window will pop up from the bottom with a list of results, subdivided by inspection.
Build -> Make Project (Ctrl + F9) gives what we can get equivalent of Eclipse's “Problems” view on Android Studio
you can use F2 to next problems, see more here: Navigating to Next/Previous Error
GO to View-->Tool Windows-->Messages to view the warnings
Even i searched all the settings in Android Studio, but couldn't find a separate window for it.
The warnings are actually visible to the right end of a particular line as a small yellow marker and clicking on that show the warnings in the status bar below. The colors of them can be editted in the inspection options.
Hope this helps you.
The closest thing Android Studio/IntelliJ has to the Problems view in Eclipse is to use the Problems section of the Project tool window. With that open, navigate down to any classes that appear there and open them in the editor. Once in the editor, you can use F2 to jump between errors in the open file.
Unfortunately, IntelliJ's Problems tool window shows classes with errors nested by folder/package, so you have to expand several levels and it takes up a lot of screen real estate to see even one error. It also doesn't list the errors individually, forcing you to first open the problematic file and then use F2 to navigate to each one. I also had the problem that errors in files that weren't open, didn't show up there.
[opening warning screen in android studio
Click the warning icon as marked in the image.
Warning screen will open.
][click to see image] here

Resources