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
Comments
Thanks @hotznplotz, this is something we are investigating. |
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.) |
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) |
To paraphrase:
|
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). |
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. |
@jakobr-google is familiar with the gradle work, and the project format that |
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 The base of the class hierarchy is named The entrypoint for creating a new project (or module) is 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. |
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. |
A header shoulds reasonable. We also control the project creation here: https://github.com/flutter/flutter/tree/master/packages/flutter_tools/templates/create and here: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/commands/create.dart. |
Status: this is looking good in terms of the implementation (we'd like to do a bit more testing before landing). |
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: |
We'll want to do some testing and consider some docs. |
@skybrian, safe to close? |
from #782 (comment)
@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. |
@gazialankus, you should be able to find the flutter.jar file at |
@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. |
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? |
Not to my knowledge, but we should. Preferably, we should have a
quadruple on relevant Maven repos. Cf flutter/flutter#11439 |
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
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?
The text was updated successfully, but these errors were encountered: