Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter intellij plugin: java language support?

In my setup the Intellij Flutter plugin doesn't support Java code. It treats Java classes like text files.

Is there any way I could get Intellij to support me with the Android specific Java code? (type checks, completion suggestion, imports, refactoring...)

Here is my flutter doctor output:

[✓] Flutter (on Linux, channel master)
    • Flutter at /home/*****/flutter/flutter
    • Framework revision 99ca38e988 (4 days ago), 2017-03-01 13:15:48
    • 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 /home/*****/Android/Sdk
    • Platform android-25, build-tools 25.0.2
    • ANDROID_HOME = /home/*****/Android/Sdk
    • OpenJDK Runtime Environment (build 1.8.0_121-b13)

[✓] Android Studio (version 2.2)
    • Android Studio at /opt/android-studio
    • Gradle version 2.14.1

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

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

[✓] Connected devices
    • None
like image 631
hotzenplotz Avatar asked Mar 05 '17 20:03

hotzenplotz


People also ask

Can we use Java language in flutter?

Flutter uses a flexible system that allows you to call platform-specific APIs in a language that works directly with those APIs: Kotlin or Java on Android. Swift or Objective-C on iOS. C++ on Windows.

Which Java is required for flutter?

Requirements to create Flutter project Java 11 JDK installed and set in system environment variables. Flutter and Dart extension installed. Connected Device with laptop for run and test flutter applications.

Which Java version works with flutter?

Make sure that you have a version of Java 8 installed and that your JAVA_HOME environment variable is set to the JDK's folder. Android Studio versions 2.2 and higher come with a JDK, so this should already be done.

Can I use flutter with IntelliJ?

An IntelliJ plugin for Flutter development. Flutter is a multi-platform app SDK to help developers and designers build modern apps for iOS, Android and the web.


2 Answers

It's possible by opening the Android app folder within your Flutter app directory in a second IntelliJ window: So one window for your Dart/Flutter code, another one for the Android Java code.

Here is how it works: Make sure Android support is installed: File -> Settings -> Plugins -> Android Support.

Now do the following steps (tested on Linux):

  1. Open the android folder of your Flutter app into a new project window. IntelliJ will detect that there is Android support, click on configure to use the existing manifest file.
  2. You might get a warning: "Failed to sync Gradle project 'android'. Click "Migrate to Gradle wrapper and sync project".
  3. If you get a Gradle error like: "Flutter SDK not found". Open the local.properties file in your Android project folder, and add the following configuration to it: flutter.sdk=/home/user/dev/flutter (using the correct folder on your system).

There should be 3 entries in the local.properties file:

sdk.dir=/home/raju/Android/Sdk
flutter.sdk=/home/raju/dev/flutter
flutter.buildMode=debug

Now the Gradle build should run through.

Flutter app Gradle build in Android project

When you open the MainActivity.java in folder android/app/src/main/java/com.yourcompany.hello there should be full Java/Android support with autocomplete, etc.

Flutter Android app Java code in IntelliJ

You can launch the Flutter app out of the Android project window, but then you will not have hot reload support active. So always use the project window with the Flutter project to launch. Or flutter run from the command line, if you prefer that.

like image 103
raju-bitter Avatar answered Oct 02 '22 23:10

raju-bitter


Found a way to have it all running in a single window, just make sure you close your project and start from the first step (I found that skipping steps does not help or work):

Android Studio Flutter Plugin project setup

1. Import project

a) from Git repository

  • open File -> New -> Project from version control -> Git
  • paste your git project link and confirm

b) from local existing project

  • open File -> New -> Import project
  • find your project and confirm

2. Import options

  • If asked to "Create Android Studio project?" -> click Yes
  • Select "Import project from external model" -> select "Gradle"

4. Fetch Flutter dependencies

  • Run "flutter pub get" in terminal or click on "Get dependencies" in Android Studio as many times as it requires

5. Setup Android SDK and dependencies

  • Go to folder "/example/android/" -> right click on "build.gradle" -> select "Import Gradle project"

6. Run project

  • green arrow
  • or run configuration with "example/lib/main.dart" as entry point
like image 21
rexxar Avatar answered Oct 02 '22 22:10

rexxar