Kotlin Multipplatform - can't see Greeting.kt in Android Studio folder tree - android-studio

I am just starting to learn KMM (I'm an Android java guy right now) and going through the default Greeting version of Hello World that is automatically put into a new application. My environment seems to be working as I was able to run the default app on both Android and iOS emulators.
However I can't see the file Greeting.kt in the Project tree. I can certainly search for it and open it from Find, but when I drill down the tree shared/commonMain/kotlin/com.myapp... it only shows Platform.
I have a screen cap that shows the path of the open Greeting.kt at the top, but not visible in the tree:
(screen cap)
Unfortunately I can't post an image (not enough reputation), but when I open the file Greeting.kt by doing a Find In Project, it shows the path at the top of the screen (My Application > shared > src > commonMain > kotlin > com > example > myapplication > Greeting), but when I manually drill down the Project tree on the left side of Android Studio Greeting.kt does not show up.
I can also find the file in the Mac Finder. My guess a preference in Android Studio is incorrect?
Any ideas on what might be wrong?
Thanks in advance

Turns out it was an official bug. Solution is to upgrade to Beta version of Android Studio (Chipmunk)
I submitted a bug report to Google and they looked into it:
The root cause is that before [Android Studio]Chipmunk the source set
setup was incorrect, so even though it says commonMain in your
screenshot (from #2), if you open the Platform.kt under that source
set, you'll see that it is in fact
shared/src/androidMain/kotlin/com/example/myapplication/Platform.kt.
[Android Studio] Chipmunk fixes this issue.

Related

How to open an existing Flutter Project in Android Studio

I might sound noob here but I can't see a clear way of opening existing Flutter Project in Android Studio 3.1.2.
I checked this but it didn't work. So I want to know if there is a standard IDE way of doing this? I also can't find any docs clearly mentioning it. Do I need to install a 3rd party plugin?
After opening it as an Existing Android Studio Project, I get the following error:
The error is solved by running Get Dependencies. Is it a normal behavior?
Install Flutter plugin for Android studio: https://flutter.io/get-started/editor/
Open Android Studio
Open existing Android Studio project by using one of below methods:
EASIEST WAY: Drag your project folder and drop to Android Studio.
Other ways:
What works for me was to open existing Android Studio project like mentioned above, and then go to menu
Tools -> Flutter -> Flutter Clean
Then configuration window will open and ask you to locate flutter sdk. After locating the sdk, click OK and then the flutter functions will be available (Pub buttons, runs menu). After that you can proceed to get the dependencies (pub get).
It's basically cleaning the project folder of previous setting(s) which might conflicting with the system (android studio). But that won't happen if you get the project from source repository because all of the junk files wont be in the project folder.
The quickest way on macOS is
open -a Android\ Studio android when you are in the root project directory.
Alternatively, if you use the jetbrains toolbox, you can enable "Shell Scripts" in its settings. This will create a binary in the folder of your choice, so you have to add this folder to your PATH. Then, you can use studio . inside the Android folder, or studio android in the flutter project. The benefit of this, is it also works with other Jetbrains products (e.g. charm project_dir or clion project_dir. Unfortunately this method glitches out (for pycharm at least).
Looks like Android Studio can't load Android Application module from Flutter project automatically. I also have same problem, so in my situation Gradle can't be found, because of lack of Android project.
There's important note from official site:
Important: Do not use the New > Project from existing sources option for Flutter projects
I suggest, same is for Open option.
Just Open your project as normal, and then in [Android Studio > Preferences > Languages&Frameworks > Flutter > Flutter SDK path] select the path where you downloaded & unpacked Flutter SDK.
I know it's already late, but you can open an existing Flutter project in Android Studio by following these steps (make sure you have already installed Flutter & Dart plugin and Flutter SDK):
Click Open from File menu in Android Studio,
Go to the path of the project,
Click Open from the dialog,
When the project opens in Android studio, it will show an error of packages and dependencies. So, click on Get Dependencies on the top. Android Studio will automatically add all the required dependencies and packages.
There is a simple way of doing this in android:
Just Open your project as normal, and on the top right corner, click on Flutter Attach option, and voila!
See Attached screen grab!
Usually you can open your Flutter project in Android Studio simply when you right click on the android folder > Flutter > Open Android module in Android Studio but sometimes this option could be disabled, check this answer to enable..

Android Studio - Error: Failed to resolve: com.android.support.constraint:constraint-layout:1.0.0-alpha1

Screen Shot #1 - Android Studio Project Gradle Build View
Screen Shot #2 - Android Studio Project Gradle Sync View
Going through the "Android Studio 2.2 Development Essentials book" and following along with the tutorial in chapter 3. Everything was OK until I completed a task in the Development Essentials book (chapter 3, page 24 in book) that said,
As we can see from the component tree hierarchy, the user interface
layout consists of a layout parent with a single child in the form of
a TextView object. If Android Studio has used a RelativeLayout manager
for the project, the first step is to convert it to a
ConstraintLayout. ConstraintLayout is a new and flexible layout
manager that is used in most projects in this book. To achieve this
conversion, right-click on the content_android_sample entry in the
Component Tree and select the Convert RelativeLayout to
ConstraintLayout menu option as shown below:
Upon completion of the above quoted tutorial task (in chapt. 3 of the Development Essentials book), an error was presented that said:
Error: Failed to resolve: com.android.support.constraint:constraint-layout:1.0.0-alpha1
Also, a rendering error was listed as well that said:
Rendering Problems The following classes could not be found:
- android.support.constraint.ConstraintLayout (    Add constraint-layout library dependency to the project, Fix Build Path, Edit XML, Create Class)
Any thoughts on how to fix this? Please see screen shots attached (above). I'm new to Android Studio.
Thank you very much for your time.
I am using the following OS and Android Studio version below:
Win7 professional 64 bit OS
Android Studio 2.2
Build# AI-145,3330264, Built on October 6, 2016
You need add check in..
exist a icon with name "SDK Manager" just click
open Settings -> Appearance & Behavior -> System Settings -> Android SDK -> SDK Tools
And in this dialog add:
ConstraintLayout for Android
Solver for ConstrainLayout
Then, here only you need close and open Android Studio.
Maybe only you can update to:
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
Or update your dependency to:
compile 'com.android.support.constraint:constraint-layout:latest_version'
This should solve your error. Go to your build.gradle and change your implementation 'com.android.support.constraint:constraint-layout:1.0.0-beta7' to implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta7' or to any latest

Android Studio Clicking on "Project Structure " not working

I have met a strange question about Android Studio and I have tried to find a solution on the Internet but it failed.
Here is my question:
I open the Android Studio and the project can be installed to my device correctly. However, when I tried to open the Project Structure, it failed without any response. I just clicked on the button below but the Project Structure dialog didn't show up:
I have SDK installed below:
Please help me how to open the Project Structure dialog.
I have found a method to avoid my problem. My way is that uninstalling my sdk which version is Android 4.4. After doing that my project structure shows up. try deleting your current sdk for an attempt.

In android studio,cannot load 2 facets-unknown facet type:android and android-gradle

When I open android studio I am getting an error- "Error loading project: Cannot load 2 facets. When I clicked to see the error the following appeared
"2 facets cannot be loaded. You can mark them them as ignored to suppress this error notification.
Unknown facet type:'android', Unknown facet type:'android-gradle'
I tried to add facets ( In Project Structure > Project settings > Modules > clicked project name, then clicked Android as well as Android-Gradle) But both showed as "cannot load facet, unknown facet type." Under Project settings > Facets > both Android and Android-Gradle are displayed as 'Invalid facets'.
My project was running smoothly. This problem occured when I force-closed my laptop before exiting android studio as everything got stuck. After that whenever I open the android studio this problem occurs. I am not able to run my project. Can anyone please help me to solve this?
Just enable Android Support plugin.
Click Ctrl+Alt+S in Windows or Meta+Comma in Mac.
In top search bar type "plugin".
On right side it will show a list of plugins, find Android Support plugin, check it and click OK at the bottom of screen.
This is how it looks:
In Android Studio go to
File -> Settings - > Plugins -> Enable "Android Support" Plugin.
File, Then Settings->Plugin->Enable/Renable Plugin --> Apply --> Restart
This problem occured when i'd updated Android Studio.
In case nothing from other answers works, you don't have another option, except removing broken settings and making clean setup.
So what i am suggesting:
Use Settings Repository Feature to store personal IDE settings
close studio
remove .AndroidStudioX folder from user folder
re-launch studio, do not copy settings from previous version (because settings probably broken and auto-import couldn't import it well)
import personal settings from Settings Repository
For me I went to Settings -> Plugins and de-selected Gradle then immediately re-selected it. Android Studio then asked if I wanted to enable Groovy so I said yes and let it restart and now everything is happy again! (it was checked, but clearly somewhere deep down not truly enabled, so toggling the check-box sorted it)
Not sure if my cause was installing Flutter, but I did have to disable the Flutter plugin before I could build again.
I had the same problem with an ever-increasing number of facets - first 2, then 4, then 5 - and none of the above solutions worked. My solution (Android Studio 3.3, OS X) was to delete ~/Library/Preferences/AndroidStudio3.3/disabled_plugins.txt, which contained org.jetbrains.android and org.jetbrains.maven
I imagine if you have deliberately disabled plugins then you'll have to disable them again manually, but I was able to load all facets again.
Go To ->File->Settings->Plugins->disable/enable Android Support Plugins->Press Ok
Just re-enable Android Support plugin. Then it will ask to restart.
Restart them thats it
I faced this issue in Android Studio 3.2.1 I had to re-import my project after that it works.
I was facing this problem, I tried everything but nothing worked but then I remembered that I updated Android Studio just few hours back and then I enabled the plugins in the Android Studio and restarted it and it worked.
File -> Settings -> Plugin and then just press ok. It will ask to restart the android studio and please restart it.
For me I had to uncheck the plugin Android APK Support. I clicked Apply and then Ok to close the window. Android Studio prompted me to restart the program, and the program restarted. I checked the Android APK Support plugin again and restarted the program. And then I selected File -> Sync Project with Gradle Files
Then it worked just fine.

Android Studio - How to Change Android SDK Path

When I open Android SDK Manager from Android Studio, the SDK Path displayed is:
\android-studio\sdk
I want to change this path. How do I do it?
From Android Studio 1.0.1
Go to
File -> project Structure into Project Structure
Left -> SDK Location
SDK location select Android SDK location (old version use Press +, add another sdk)
For projects default:
Close current Project (File->Close project)
You'll get a Welcome to Android Studio Dialog. In that:
Click on Configure -> Project Defaults -> Project Structure
Click on SDK Location in the left column
Put the path to the Android SDK in "Android SDK location" field.
(Example SDK location: C:\android-sdk; I have sub-folders like
add-ons, platforms etc under C:\android-sdk)
Click OK to save changes
Have fun!
Following steps were for older versions(<1.0) of Android Studio
In the middle column Click on Android SDK (with Android icon) OR click + on the top if you don't see an entry with Android icon.
Change SDK Home Path and select valid Target.
From the quick start window, choose Configure, then choose Project Defaults, and then choose Project Structure. Then on the left under Platform Settings choose SDKs. Then to the right of that choose the current android platform, mine was Android 4.2.2 Platform, and delete it using the red minus button at the top, then add a new android platform using the green plus button at the top and point it to your current SDK folder and that is it.
I Configured in this way
on
Welcome to Android Studio Screen
Click Configure Then
Project Defaults and then Project Structure
Then
Android SDK and Selected the path to my current location of Android SDK
Changing the sdk location in Project Settings will solve the problem partially. When Android Studio is used to download a new SDK, it will place the new SDK in the internal SDK folder (inside Android Studio).
Existing android developers will already have a large sdks folder (hereinafter referred to as external SDK folder) containing all the SDKs downloaded before Android Studio came around.
For Mac/Linux users though there is a good way out. Soft links!
Exit Android Studio and perform the following steps:
cp -r <Android Studio>/sdk/ <external SDK folder>/
cd <Android Studio>/
mv <Android Studio>/sdk/ mv <Android Studio>/sdk.orig
ln -s <external SDK folder>/ sdk
And we're good to go. Launch SDK Manager after starting Android Studio, watch as it discovers all your existing SDKs like a charm :).
EUREKA I found it!
With the current Studio 1.3 each project has a local.properties file where you can edit the SDK!
Here's how you can change the android sdk path in Android studio:
Open your required android project in Android studio
Click on the main project folder and press F4
Now click on "SDKs" under Platform Settings (Left hand side of the dialog box)
You should now see a plus sign on the top, click it and choose "Android SDK"
Now you would be asked to choose the required SDK folder
Select the required build target(if necessary) and click "ok"
Now you should see the new entry in the list of SDKs
Click "Modules" under Project Settings
Select your project folder and in the Dropdown for "Module SDK", select the new SDK entry and click "apply"
Now click "OK" and your done.
Note: If changes do not take effect, restarting android studio should fix the problem.
Make your life easy with shortcut keys ctrl+shift+alt+S
or
by going to file->project structure:
it will open this window, where you can select your SDK
Try this way i try in Android Studio 2.0
Step 1: File->Settings
Step 2: Settings->SDK options
Step 3: Click Edit option in Sdk Location
Step 4: Show "SDK Components Setup"
Step 5: Click on Three "..." in "SDK Components Wizad"
Step 6: Select your new SDK Path
I noticed that the latest version of Android Studio doesn't seem to have the option "SDKs" path that's mentioned in many of the answers. I'm guessing that disappeared in one of the updates, somewhere down the line?
The way i solved this issue (osx) was:
Go to Project Settings (Cmd + ;)
In SDK Location make sure you're pointing to the correct SDK location (typically /Applications/Android Studio.app/sdk) then hit Apply
Most important step - hit "Sync Project with Gradle files"
I wasn't doing Step 3 and that was throwing me off. After a sync all your source r belong to us....
goto menu File->Project Strucurt or key Ctrl + Alt + Shift + S
and example http://how-to-android-studio.blogspot.com/2014/11/set-sdk-location.html
You can also create the environment variable (in Windows) ANDROID_HOME to the location of the Android SDK and Android Studio will use that.
Above answers are pretty correct, but some times Android Studio, does not like to refresh after SDK path change, a quick solution is to make some change in you Build file, and click on Sync. It will refresh you project.
Happy coding... :)
While first installation There are two situations either you have pre-installed Android SDK if you had used it in past or you have nothing at all, At a time of installation Installer always ask user how you want to configure SDK with your studio.
You can simply give a path here or browse folder where sdk is available in local system. If you already have SDK, Another option as shown in below picture at Left down corner there is a nice option for download SDK, by clicking it you can download SDK with latest release right from there,You can also use third option see in right down corner setup Android SDK for me by clicking it you can step by step set your sdk.
Although you can also set it up when Android shows you list of available projects, a starting prompt window shown below
That's pretty easy, and also sometime if you want to change your SDK you can always change it right in your Android Studio from
On windows system
File --> Project Structure and then you will see SDK Location Option and from there you can set it up by providing a path or by browse it.
Or if you are on MAC system then from Platform settings.
In Android Studio 2.2.3 I think you can change default SDK location for all projects from the top menu:
File -> Project Structure...
A window like below shows up:
in windows press ctrl+shift+alt+s which will open project properties where you can find first option named SDK Location click on it and there you can change SDK path, JDK path and NDK path also
This may not be what you want, but being an eclipse user I had the same problem having duplicate sdk folders which were eating all my ssd space. Currently you can only change sdk path inside android studio project wide which is annoying. What I did instead was I copied all the previous android sdk files that I was using with eclipse to /Android Studio/sdk/ and then just changed the sdk path inside eclipse.
Now both android studio and eclipse are happy.
Here is some ways, as far as I know now.
Android Studio 3.3.2 (testing is OK)
method: 1
just following steps of the official docs, as bellow link shows
https://developer.android.com/studio/intro/studio-config#jdk
method: 2
following steps of the screen shortcuts, as bellow shows
method: 3
following steps of the screen shortcut, as bellow shows
Tap --> file --> close current project.
You'll Android Studio home page
Click on Configure -> Project Defaults -> Project Structure
Click on SDK Location in the left column and copy the path.
Paste the path in My computer --> Right Click -> Properties -> click on Advanced system settings -> Environment variables and change the android home path.
click on 'OK' to save the session.
Add tools and platforms tools in path and save the changes.
Open command prompt[window+R] and type adb + enter.
In Android Studio you can set the general Android SDK path in the file: %Home%.AndroidStudio2.1\config\options\jdk.table.xml
Click on File menu.
Select Project Structure.
Edit the path in SDK Location text box.
From the next time Android Studio will use this location for all your projects.
N.B.: Avoid having spaces in the path as it may sometimes lead to issues.
This is how its done,in Android Studio for windows
Done
For Android Studio 3.1.2:
Tools>> SDK Manager>> Edit "Android SDK Location" to new location
After that, Set environment variable $ANDROID_HOME to your new SDK location
I had the same problem, but with the sdk path pointing to a mounted drive. I found, that simply quit Android Studio, unmount the device and restart Android Studio made it ask for the sdk location, because it had none (Android Studio Beta 0.8.7).
Therefore I guess if you just quit Android Studio, delete \android-studio\sdk or move it somewhere else and start Android Studio again, it should ask for the sdk location aswell.
Though many of the above answers serve the purpose, there is one straight forward thing we can do in project itself.
In Eclipse, go to Window->Preferences, select "Android" from left side menu. On the right panel you will see "SDK Location". Provide the path here.
Good luck.
In Android studio 1.2.2 you can simply changes project based SDK,
Steps:
Right click on Module and select Open module setting or press F12
Select SDK location from left hand side
Now you can change SDK location as well as JDK location from this page
When I ran into trouble with this on Android Studio 3.1.4 the solution was to go into the app dropdown on my project, then Edit Configurations > Defaults > JAR Application where there is a JRE box on the initial Configuration tab. Setting that to my JRE path solved the problem for me.
Simple Answer Work For Sure...
Step 1: Right Click On The Project>> Select Open Module Setting -->
Step 2: Select SDK Location From the Right Side below image
Step 3: Now browse the SDK location from your computer as show below...
Step 4: Click on OK.
I'm guessing from the responses that people aren't understanding your question... If I'm right in that you want to have ~\Desktop\github\ then changing the SDK location isn't what you're after.
From Android Studio 3.2.1:
From the new project dialog, choose
Configure -> Preferences -> Tools -> Terminal -> Start Directory
Put the folder you want as your project default in the field.
e.g. Mine is set to
~/Desktop/github/
since all my work is in
~/Desktop/github/
Just go to
(Main Menu) File > "Sync Project With Gradle Files"
click ok on the popup, it will change your sdk directory.

Resources