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

Not sure how to set up for flutter #145

Closed
bradyt opened this issue Jul 4, 2019 · 3 comments
Closed

Not sure how to set up for flutter #145

bradyt opened this issue Jul 4, 2019 · 3 comments

Comments

@bradyt
Copy link

bradyt commented Jul 4, 2019

Describe the bug

When writing a Flutter app, we may have to edit the Java source, like MainActivity.java, for example, to write a Platform Channel. Being new to Android and Java, it is not obvious how to properly configure things, especially to get lsp-java working in the Java files.

When I tried on my system, I got

LSP :: MainActivity.java isn't on the classpath. Only syntax errors will be reported

I selected android/ as the project root. Some files and directories, such as .project, were added to android/ and android/app/.

I tried to create a Dockerfile for a recipe to reproduce, but I got instead some errors about gradle, perhaps revealing how little I understand about the Android toolchain.

Here is my Dockerfile:

FROM silex/emacs

RUN apt-get update && apt-get install -y \
        openjdk-8-jdk-headless \
        && rm -rf /var/lib/apt/lists/*

ADD .emacs.d /root/.emacs.d
RUN emacs -batch -l ~/.emacs.d/install.el -f lsp-java-update-server

WORKDIR /root/

RUN curl -L https://github.com/flutter/flutter/archive/v1.7.8+hotfix.2.tar.gz \
        --output flutter-1.7.8-hotfix.2.tar.gz \
        && tar xvzf flutter-1.7.8-hotfix.2.tar.gz \
        && rm flutter-1.7.8-hotfix.2.tar.gz

WORKDIR /root/flutter-1.7.8-hotfix.2/examples/hello_world/android/app/src/main/java/io/flutter/examples/hello_world/

CMD "emacs" "MainActivity.java"

Here is an install.el file.

(setq package-archives
      '(("gnu" . "https://elpa.gnu.org/packages/")
        ("melpa" . "https://melpa.org/packages/")))
(package-initialize)

(package-refresh-contents)

(mapc 'package-install '(spinner lsp-java))

And here is an init.el file.

(setq package-archives
      '(("gnu" . "https://elpa.gnu.org/packages/")
        ("melpa" . "https://melpa.org/packages/")))
(package-initialize)

(unless package-archive-contents
  (package-refresh-contents))

(add-hook 'java-mode-hook (defun my-set-java-tab-width () (setq tab-width 2)))
(setq lsp-java-format-settings-url "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml")
(setq lsp-java-format-settings-profile "GoogleStyle")
(setq lsp-enable-snippet nil)

(require 'lsp-java)
(add-hook 'java-mode-hook 'lsp)

(require 'cc-mode)

(setcdr (assoc 'java-mode c-default-style) "java-google-style-indentation")

(c-add-style "java-google-style-indentation"
             '((c-basic-offset . 2)
               (c-offsets-alist
                (inexpr-class . 0)
                (case-label . +)
                (statement-cont . ++))))

That was my attempt at describing my environment, but I'm afraid I don't know yet how to get it working as well in Docker.

I got errors like,

Jul 4, 2019 5:05:40 AM Synchronize project android failed due to an error in the referenced Gradle build.                                                    
Could not run phased build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-5.4-bin.zip'.                                  
org.gradle.tooling.BuildException: Could not run phased build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-5.4-bin.zip'.
@bradyt
Copy link
Author

bradyt commented Jul 4, 2019

Possible related: #132, similar classpath issue, but not flutter related.

@yyoncho
Copy link
Member

yyoncho commented Jul 4, 2019

AFAIK the language server does not support Android projects - refer to their readme - https://github.com/eclipse/eclipse.jdt.ls and eclipse-jdtls/eclipse.jdt.ls#923

@yyoncho yyoncho closed this as completed Jul 4, 2019
@bradyt
Copy link
Author

bradyt commented Jul 4, 2019

Ah okay, thank you for clarification.

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

No branches or pull requests

2 participants