Flutter-intellij: flutter plugin project is missing Android features

Created on 8 Nov 2017  路  9Comments  路  Source: flutter/flutter-intellij

Steps to Reproduce

  1. Install Flutter plugin into Android Studio 3.0
  2. File > New Flutter project
  3. Pick either 'application' or 'plugin' template, and complete creation wizard
  4. After creation is complete, expand the top-level android folder

=> android features are missing

  • no Gradle Scripts top-level folder
  • no res folder, so no way to add resources
  • code analysis fails, for example:
  1. Open src/main/java/<org id>/plugin.java
  2. Add the import import android.support.v4.app.NotificationCompat;
  3. Add a Builder variable:

    • In an app: Add a new line inside the MainActivity class containing NotificationCompat.Builder builder;

    • In a plugin: Add a new line above result.success... containing NotificationCompat.Builder builder;

=> still complains that it can't resolve the NotificationCompat symbol

If you try the same steps in a regular Android project, it works fine.

P1 flutter-plugins topic-ecosystem

Most helpful comment

Confirmed that the following now works:

  1. flutter create foobar
  2. Start Android Studio
  3. File > Open, select foobar/android (the android part is important!)
  4. Invoke Build > Make Project
  5. Open MainActivity.java and add import android.support.v4.app.NotificationCompat;

=> will now see the error mentioned at the top of this bug. That is by-design; we need to tell gradle where it's located

  1. Expand 'Gradle Scripts' in the file pane, and open build.gradle (Module: app)
  2. Add compile 'com.android.support:support-v4:+' under dependencies at the bottom
  3. Save file, and accept the request to do a gradle sync

=> import should resolve

All 9 comments

cc @jakobr-google you had some theory for the cause of this?

I thinks it's the same problem as issue #966. See my comment there, and the reply to it.

cc @stevemessick. This makes it very, very hard to implement android plugins.

For clarity: I'm using Android Studio 3.0. I don't recall it being this broken in Android 2.3, but not entirely sure.

When Android Studio generates a project (using default values for everything) it's build.gradle has a dependencies section that looks like this:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
}

The second entry is key here. If we add an entry for appcompat to the build.gradle of an Android module generated by Flutter, and open that module as a top-level project in Android Studio, then everything works as expected. All the menu entries are enabled because it is just an Android Studio project (more-or-less). More precisely, it is a JAVA-MODULE with a java-gradle facet, and it has a sub-module with an android-gradle facet.

Our top-level Flutter project is a WEB-MODULE and it has no facets. I'm investigating how to change the top-level project to look more like an Android Studio project, but so far all I get are lots of errors. In addition to many differences in the Build menu, a "real" Android Studio project has a hammer icon next to the run configuration list that triggers a Gradle build. We should have that, too.

The additional Build menu items and the tool bar icon show up after the top-level project is converted to a java-gradle project. We have to add two files:

  • .idea/gradle.xml
  • build.gradle

The module definition (project.iml) needs to be edited:

  • Change type to JAVA_MODULE
  • Add external.system.id="GRADLE" to the <module> tag
  • Add a java-gradle facet

That is not enough to make everything work, but the menu items will appear.

The Flutter project foo and its Android module foo/androd are completely separate IntelliJ/Android Studio projects. Each must be opened as top-level projects for full editing support. See:
https://github.com/flutter/flutter-intellij/blob/master/docs/android.md

Confirmed that the following now works:

  1. flutter create foobar
  2. Start Android Studio
  3. File > Open, select foobar/android (the android part is important!)
  4. Invoke Build > Make Project
  5. Open MainActivity.java and add import android.support.v4.app.NotificationCompat;

=> will now see the error mentioned at the top of this bug. That is by-design; we need to tell gradle where it's located

  1. Expand 'Gradle Scripts' in the file pane, and open build.gradle (Module: app)
  2. Add compile 'com.android.support:support-v4:+' under dependencies at the bottom
  3. Save file, and accept the request to do a gradle sync

=> import should resolve

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zoechi picture zoechi  路  3Comments

DaveShuckerow picture DaveShuckerow  路  3Comments

sethladd picture sethladd  路  4Comments

galeyang picture galeyang  路  4Comments

Rissmon picture Rissmon  路  4Comments