Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support editing a Flutter project's Android java code in IntelliJ IDEA #782

Closed
fbrueck opened this issue Mar 3, 2017 · 20 comments
Closed

Comments

@fbrueck
Copy link

fbrueck commented Mar 3, 2017

Currently I don't get language specific IDE support for Java code. Some features like auto complete identifiers does work. Others like detecting wrong syntax and type checks doesn't. Tried it on Linux and OSX.

Steps to Reproduce

  1. follow Intellij setup instructions: https://flutter.io/intellij-setup/
  2. run 'flutter create newApp'
  3. open newApp with Intellij
  4. check IDE support for Java code in android/app/src/...

Version info

[✓] Flutter (on Mac OS, channel master)
• Flutter at /Users/*****/.flutter/flutter
• Framework revision c9644a49f2 (31 hours ago), 2017-03-02 09:21:40
• Engine revision 74de13c0bd
• Tools Dart version 1.23.0-dev.2.0

[✓] Android toolchain - develop for Android devices (Android SDK 25.0.2)
• Android SDK at /Users/*****/Library/Android/sdk
• Platform android-25, build-tools 25.0.2
• Java(TM) SE Runtime Environment (build 1.8.0_102-b14)

[-] iOS toolchain - develop for iOS devices (Xcode 8.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 8.1, Build version 8B62
✗ ideviceinstaller not available; this is used to discover connected iOS devices.
Install via 'brew install ideviceinstaller'.
✗ ios-deploy not installed: install via 'brew install ios-deploy'.

[✓] Android Studio (version 2.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Gradle version 2.14.1

[✓] IntelliJ IDEA Ultimate Edition (version 2016.3)
• Dart plugin version 163.8651
• Flutter plugin version 0.1.11.1

[-] WebStorm (version 2016.2.4)
• Flutter plugin not installed; this adds Flutter specific functionality.
• For information about managing plugins, see
https://www.jetbrains.com/help/idea/managing-plugins.html

[✓] Connected devices
• None

I am aware that IDE support for the native languages maybe isn't high priority, but would be handy when using host message passing. How do you do this when implementing libraries?

@mit-mit
Copy link
Member

mit-mit commented Mar 8, 2017

Thanks @hotznplotz, this is something we are investigating.

@devoncarew devoncarew modified the milestone: M13 Mar 29, 2017
@mit-mit mit-mit changed the title missing IDE support for java code Support editing a Flutter project's Android java code in IntelliJ IDEA Mar 30, 2017
@mit-mit mit-mit added the okr label Mar 30, 2017
@devoncarew devoncarew mentioned this issue Apr 3, 2017
28 tasks
@skybrian
Copy link
Contributor

skybrian commented Apr 3, 2017

Any thoughts on our strategy here? IDEA of course has Java support and has Android support too, which I haven't investigated yet. It probably requires additional setup. Do we want to encourage people to use that? It will likely make an already long installation procedure even longer, and/or could be another plugin integration point that will have version skew issues.

(And by the way, WebStorm has no Java support.)

@devoncarew
Copy link
Member

This issue is to investigate what we'd need to do to better support editing the project's Java code in IDEA. If we can get the Java code working w/o requiring users install the Android plugins, great (and in fact, preferred). We could also determine that we do have to require the Android plugin be installed to support working on the Java side in IDEA. If so, we should make whatever changes are required to the project structure to support that, and document the workflow.

(we have a separate item to tackle support for Android Studio itself)

@devoncarew
Copy link
Member

To paraphrase:

  • what level of support could we get in IDEA now w/o the android plugins being installed?
  • should we recommend that the android plugins be installed? (or document the work for the users and the benefits they get)
  • android studio support tracked elsewhere :)

@devoncarew
Copy link
Member

And from some further discussions, getting to a place where we get code completion and analysis errors would be fantastic (as in, good Java support, not necessarily Android support).

@skybrian
Copy link
Contributor

skybrian commented Apr 7, 2017

I looked into how to manually set this up for a simple project (basically hello world). This is using IDEA CE without the Android plugin.

Which JDK should we use for Android?

I got this out of "flutter doctor". It looks like it picks it up from Android Studio? Presumably flutter-tools will need to choose this.

Where do we get android.jar?

Again, got it out of "flutter doctor". It's $ANDROID_HOME/android-25/android.jar. Again, flutter tools should tell us where it is.

Where do we get javadoc for Android API's?

Assuming it's installed, $ANDROID_HOME/sources/android-25 should contain all the Java source files. In IDEA, this should be attached to android.jar.

How should IDEA refer to android.jar?

I put Java configuration in a separate module for the "android" subdirectory. I think it's a hack, though; it should be part of the Android SDK. I suspect you need to enable Android support to create an Android SDK, though.

Where do we get flutter.jar?

This seems to be defined by source code in a gradle file:

$FLUTTER_HOME/packages/flutter_tools/gradle/flutter.gradle

For a debug compile, its location is apparently:

$FLUTTER_HOME/bin/cache/artifacts/engine/android-arm/flutter.jar

Where do we get javadoc for flutter.jar?

I haven't found it yet. But it appears that Android Studio doesn't set this up properly either.

Adding these two jars is good enough to get rid of the errors in MainActivity, except for a warning that MainActivity is never used. Presumably using Android integration would fix that.

So it looks like setting this up isn't too hard for the simple case, but making sure it stays up to date as the user modifies the Android/Flutter settings might be tricky. When ANDROID_HOME changes or the platform version changes (according to flutter doctor) we need to use a different android.jar, and when FLUTTER_HOME changes (or is updated) then we might need to change the location of flutter.jar.

@devoncarew
Copy link
Member

devoncarew commented Apr 7, 2017

@jakobr-google is familiar with the gradle work, and the project format that flutter create builds. Sounds like we'll want some maintainable way to reference flutter.jar (and perhaps build flutter.jar with source code in it, or in a flutter-src.zip or some other well known location?)

@skybrian
Copy link
Contributor

skybrian commented Apr 8, 2017

How can we create a project with multiple modules?

It makes sense for there to be two modules: the outer module has type=Flutter, and an inner module (for the android directory) with type=Java (or perhaps Android).

But currently, project creation is done using FlutterModuleBuilder. As the name implies, this creates a single module. There are some hooks allowing it to also create a new project with a single module.

The base of the class hierarchy is named ProjectBuilder and it has a commit method that can return multiple modules. However, there are no examples other than ProjectImportBuilder (and subclasses) that actually do this; it appears we're on our own.

The entrypoint for creating a new project (or module) is FlutterModuleType, which implements createModuleBuilder(), whose return type is "T extends ModuleBuilder". This suggests we're not really supposed to create multi-module projects this way. Perhaps there's some other way to register it?

Looking in LangExtensionPoints.xml, I don't see an obvious alternative to the moduleType hook.

An alternative might be to stick with a single module and a single module type (Flutter) and enable Java support somehow, but that seems messy.

@skybrian
Copy link
Contributor

skybrian commented Apr 8, 2017

Another approach might be to show a header at the top of Java files within the android directory with a button: "set up Java support". This could create a new Java module for the android directory without going through the project creation wizard, and it wouldn't force the user to make any decisions before they're ready to work on Java code.

@devoncarew
Copy link
Member

@devoncarew
Copy link
Member

Status: this is looking good in terms of the implementation (we'd like to do a bit more testing before landing).

@skybrian
Copy link
Contributor

Status: at HEAD, creating a new Flutter Project sets up a module for the "android" directory. It's up to the user to enable Android integration and add the Android SDK to the IDEA project. (But this is optional if you don't want to edit the Java code.)

Unfortunately, there is sometimes a long pause while running "flutter create", and it's unclear how best to tell the user to be patient. For more, see:
https://youtrack.jetbrains.com/issue/IDEA-171569

Still to do, but maybe not for this release: #917 #918

@pq
Copy link
Contributor

pq commented Apr 18, 2017

We'll want to do some testing and consider some docs.

@pq pq modified the milestones: On Deck, M13 Apr 18, 2017
@devoncarew
Copy link
Member

@skybrian, safe to close?

@skybrian
Copy link
Contributor

Yes, there's more work but it's in #917 and #918.

@gazialankus
Copy link

gazialankus commented May 1, 2018

from #782 (comment)

Where do we get javadoc for flutter.jar?
I haven't found it yet. But it appears that Android Studio doesn't set this up properly either.

@skybrian sorry If I missed it above. How do we get the javadoc/sources of flutter.jar? I would love to ctrl+click in AS and see actual sources of flutter.jar.

Edit: sorry for resurrecting a year-old closed bug, but I thought relevant information could also help others. I checked out the https://github.com/flutter/engine/ source and pointed IntelliJ to shell/platform/android in it. Probably the version would not match the actual source version used for flutter.jar, though.

@devoncarew
Copy link
Member

@gazialankus, you should be able to find the flutter.jar file at flutter/bin/cache/artifacts/engine/android-arm/flutter.jar.

@gazialankus
Copy link

@devoncarew but that doesn't have the sources. Sometimes I need to go into the sources to see what really is going on under the hood.

@devoncarew
Copy link
Member

Ah, gotcha. @mravn-google, do we ship the flutter.jar sources, and if no, could we? I assume this would be a source jar, or include sources in the flutter.jar file, in a src/ dir?

@mravn-google
Copy link

Not to my knowledge, but we should. Preferably, we should have a

flutter-x.y.z.pom
flutter-x.y.z.jar
flutter-x.y.z-javadoc.jar
flutter-x.y.z-sources.jar

quadruple on relevant Maven repos. Cf flutter/flutter#11439

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants