Skip to content

Commit 29cd572

Browse files
authored
Support Android project (#2644)
1. Add experimental Android support 2. Add `auto` option to automatically enable the support in insiders Signed-off-by: Shi Chen <[email protected]>
1 parent 164619e commit 29cd572

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Features
2525

2626
* Supports code from Java 1.5 to Java 18
2727
* Maven pom.xml project support
28-
* Basic Gradle Java project support (Android not supported)
28+
* Gradle project support (with experimental Android project import support)
2929
* Standalone Java files support
3030
* As-you-type reporting of parsing and compilation errors
3131
* Code completion
@@ -48,8 +48,6 @@ Features
4848
* Call Hierarchy
4949
* Type Hierarchy
5050

51-
Please note that [Gradle-based Android projects are not supported](https://github.com/redhat-developer/vscode-java/issues/10#issuecomment-268834749).
52-
5351
To launch and debug your Java programs, it's recommended you install *[Java Debug Extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug)*.
5452

5553
See the [changelog](CHANGELOG.md) for the latest release. You might also find useful information in the project [Wiki](https://github.com/redhat-developer/vscode-java/wiki).
@@ -210,6 +208,7 @@ New in 1.10.0
210208
* `java.import.maven.offline.enabled`: Enable/disable the Maven offline mode. Defaults to `false`.
211209
* `java.codeAction.sortMembers.avoidVolatileChanges`: Reordering of fields, enum constants, and initializers can result in semantic and runtime changes due to different initialization and persistence order. This setting prevents this from occurring. Defaults to `true`.
212210
* `java.jdt.ls.protobufSupport.enabled`: Specify whether to automatically add Protobuf output source directories to the classpath. **Note:** Only works for Gradle `com.google.protobuf` plugin `0.8.4` or higher. Defaults to `true`.
211+
* `java.jdt.ls.androidSupport.enabled`: [Experimental] Specify whether to enable Android project importing. When set to `auto`, the Android support will be enabled in Visual Studio Code - Insiders. **Note:** Only works for Android Gradle Plugin `3.2.0` or higher. Defaults to `auto`.
213212

214213
Semantic Highlighting
215214
===============

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,17 @@
941941
"markdownDescription": "Specify whether to automatically add Protobuf output source directories to the classpath.\n\n**Note:** Only works for Gradle `com.google.protobuf` plugin `0.8.4` or higher.",
942942
"scope": "window"
943943
},
944+
"java.jdt.ls.androidSupport.enabled": {
945+
"type": "string",
946+
"enum": [
947+
"auto",
948+
"on",
949+
"off"
950+
],
951+
"default": "auto",
952+
"markdownDescription": "[Experimental] Specify whether to enable Android project importing. When set to `auto`, the Android support will be enabled in Visual Studio Code - Insiders.\n\n**Note:** Only works for Android Gradle Plugin `3.2.0` or higher.",
953+
"scope": "window"
954+
},
944955
"java.codeAction.sortMembers.avoidVolatileChanges": {
945956
"type": "boolean",
946957
"default": true,

src/extension.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'path';
44
import * as os from 'os';
55
import * as fs from 'fs';
66
import * as fse from 'fs-extra';
7-
import { workspace, extensions, ExtensionContext, window, commands, ViewColumn, Uri, languages, IndentAction, InputBoxOptions, EventEmitter, OutputChannel, TextDocument, RelativePattern, ConfigurationTarget, WorkspaceConfiguration, env, UIKind, CodeActionContext, Diagnostic, CodeActionTriggerKind } from 'vscode';
7+
import { workspace, extensions, ExtensionContext, window, commands, ViewColumn, Uri, languages, IndentAction, InputBoxOptions, EventEmitter, OutputChannel, TextDocument, RelativePattern, ConfigurationTarget, WorkspaceConfiguration, env, UIKind, CodeActionContext, Diagnostic, CodeActionTriggerKind, version } from 'vscode';
88
import { ExecuteCommandParams, ExecuteCommandRequest, LanguageClientOptions, RevealOutputChannelOn, ErrorHandler, Message, ErrorAction, CloseAction, DidChangeConfigurationNotification, CancellationToken, CodeActionRequest, CodeActionParams, Command } from 'vscode-languageclient';
99
import { LanguageClient } from 'vscode-languageclient/node';
1010
import { collectJavaExtensions, isContributedPartUpdated } from './plugin';
@@ -633,6 +633,21 @@ export function getJavaConfig(javaHome: string) {
633633
const editorConfig = workspace.getConfiguration('editor');
634634
javaConfig.format.insertSpaces = editorConfig.get('insertSpaces');
635635
javaConfig.format.tabSize = editorConfig.get('tabSize');
636+
const androidSupport = javaConfig.jdt.ls.androidSupport.enabled;
637+
switch (androidSupport) {
638+
case "auto":
639+
javaConfig.jdt.ls.androidSupport.enabled = version.includes("insider") ? true : false;
640+
break;
641+
case "on":
642+
javaConfig.jdt.ls.androidSupport.enabled = true;
643+
break;
644+
case "off":
645+
javaConfig.jdt.ls.androidSupport.enabled = false;
646+
break;
647+
default:
648+
javaConfig.jdt.ls.androidSupport.enabled = false;
649+
break;
650+
}
636651
return javaConfig;
637652
}
638653

0 commit comments

Comments
 (0)