Ammy Kang
Ammy Kang

Reputation: 12602

Flutter: Open android module in Android Studio is disabled

I am trying to open my flutter project separately in android studio with "Open android module in Android Studio" but when I left click on my flutter project window to open it this is disabled for me while "Open iOS module in Xcode" is there. Please let me know I can I enable it and can open my flutter project for android in another module.

Upvotes: 56

Views: 33064

Answers (8)

Jobin
Jobin

Reputation: 496

deleting .idea folder under your_project/android/ worked for me.

Upvotes: 2

RIYAS PULLUR
RIYAS PULLUR

Reputation: 89

Here I got this issue i make a file in project-> android-> projectname_android.iml

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android" name="Android">
<configuration>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="GEN_FOLDER_RELATIVE_PATH_APT" value="/gen" />
<option name="GEN_FOLDER_RELATIVE_PATH_AIDL" value="/gen" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/app/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/app/src/main/res" />
 <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/app/src/main/assets" />
  <option name="LIBS_FOLDER_RELATIVE_PATH" value="/app/src/main/libs" />
    <option name="PROGUARD_LOGS_FOLDER_RELATIVE_PATH" value="/app/src/main/proguard_logs" />
</configuration>
</facet>
</component>
 <component name="NewModuleRootManager" inherit-compiler-output="true">

<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/app/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/app/src/main/kotlin" isTestSource="false" />
  <sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
</content>
 <orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Flutter for Android" level="project" />
 <orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
enter code here

Upvotes: 0

thanhbinh84
thanhbinh84

Reputation: 18454

My plugin is a pure package having no example app that also caused the same issue. I fixed at following:

  1. Generate new plugin flutter create --template=plugin --platforms=android -a java YourPluginName

  2. Copy example app into my plugin

  3. Go to example/android, right click on your_plugin_example.iml, Flutter/Open for Editing on Android Studio

  4. The flutter module is loaded so there will be no error.

Upvotes: 0

Cương Nguyễn
Cương Nguyễn

Reputation: 1035

The easiest way is to use this command in the root directory of your project, it will create some missing files and it will definitely work.

flutter create --platforms=android .

Now just right click to Android folder

enter image description here

Upvotes: 15

Osama Remlawi
Osama Remlawi

Reputation: 2990

Simply do the following:

  1. Right click on android folder > New > File
  2. Rename the new file myproject_android.iml (change myproject to your project name)
  3. Paste the bellow xml code and save it
  4. Right click on android folder > Flutter > Open Android Module in Android Studio
  5. Voila

Xml code:

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
      <excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
      <excludeFolder url="file://$MODULE_DIR$/.idea" />
      <excludeFolder url="file://$MODULE_DIR$/.pub" />
      <excludeFolder url="file://$MODULE_DIR$/build" />
    </content>
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" name="Dart SDK" level="project" />
    <orderEntry type="library" name="Flutter Plugins" level="project" />
    <orderEntry type="library" name="Dart Packages" level="project" />
  </component>
</module>

Upvotes: 57

heqingbao
heqingbao

Reputation: 326

Because you lost the xxx_android.iml file in android directory, it cannot be recognized as an android project.

So you only need to copy a xxx_android.iml file from other projects to the android directory.

Note, replace xxx with your project name

Upvotes: 22

Rahul Malhotra
Rahul Malhotra

Reputation: 71

Go to

tools -> flutter -> open in exisiting android studio.

If it is not showing, then create a Dummy project in flutter, after that dummyFil.iml is generating with new Flutter Plugins.

Paste the dummyFil.iml file in your project.

You will see a option as open in existing android studio option.

Upvotes: 6

RockingDice
RockingDice

Reputation: 2120

>>> Only applies for Idea Intellij IDE

Okay, I finally figured out why the option is not available (greyed out).

It should be the inconsistency problem between the old version of the flutter plugin and a new one.

You might experience this issue if you created the project with a relatively old version flutter engine, and open it with a new version flutter plugin.

To know what happens and how to resolve it:

The old project contains a file: android.iml

which is not the same as in a latest created project: $projectname_android.iml

So you know how to fix the issue:

Rename the iml file to (YourProjectName_android.iml) That would instantly make the menu highlight again!

Upvotes: 57

Related Questions