58

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.

1

8 Answers 8

57

>>> 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!

Sign up to request clarification or add additional context in comments.

9 Comments

I don have the .iml file
@shahanakareen after some searches I found that .iml is generated for Idea Intellij IDE. If you use other IDEs then you won't have it. I'll update the answer.
I am using Android studio and i just imported a flutter project from gitlab. Now I am not getting that option to edit android module. I can see a iml file under the root of the folder but not inside android folder
@shahanakareen The option is used to open the project from other IDEs by Android Studio. It's not the case you import it directly FROM the Android Studio. You've already done what it does. If you don't know how to edit android modules, you have to find other questions.
thanks, it works for me! I didn't have the .iml file at first, but when i File -> Open the android project the .iml file is automatically generated by android studio and then i rename the .iml file to YourProjectName_android.iml it's worked!
|
57

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>

Comments

22

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

Comments

16

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

Comments

6

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.

Comments

2

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

1 Comment

tried to open but it was closed immediately. resolved with this !!
0

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.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.