Trying to get vscode to detect Android Project but it does not seem to work. With java.jdt.ls.androidSupport.enabled set to on it should automatically detect Android Project, add necessary files and classpath in Project and External Dependencies automatically but after many attempts none of the solutions seem to work.
Android support should be available from here (eclipse-jdtls/eclipse.jdt.ls#2197) . This introduces a init.gradle file that should automatically add the Android Sourcesets, add classpath, all other android dependencies but I do not think that ever runs.
Here are my steps and partial temporary solution I came up with.
Steps:
- Create a new Android Project using Android Studio using Java and Groovy Gradle.
- Move over to vscode. Install the plugin pack, enable vscode setting
java.jdt.ls.androidSupport.enabled to on. (I have all other necessary setups such as having jdk installed.)
- After that by default vscode setting
java.import.gradle.enabled is set to enable so it detects the gradle projects. So far the error in MainActivity.java is not on the classpath of project app.
- Using
Add Folder to Java Source Path do not work as it says Unsupported operation. Please use build.gradle file to manage the source directories of gradle project. To resolve it I added this to app/build.gradle file:
apply plugin: 'eclipse'
eclipse {
classpath {
containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
file.whenMerged { cp ->
def entries = cp.entries
def src = new org.gradle.plugins.ide.eclipse.model.SourceFolder('src/main/java', null)
entries.add(src)
}
}
}
- Now it fails to get definitions for
android and androidx. Errors: The import android cannot be resolved and The import androidx cannot be resolved. Still nothing inside Project and External Dependencies even after running gradle build.
- Add android definions manually inside eclipse build.gradle file
def jarfile = new org.gradle.plugins.ide.eclipse.model.Library(fileReferenceFactory.fromPath("${android.sdkDirectory}/platforms/" + android.compileSdkVersion + "/android.jar"))
jarfile.sourcePath = fileReferenceFactory.fromPath("${android.sdkDirectory}/sources/" + android.compileSdkVersion)
entries.add(jarfile)
It gives definions for android imports such as import android.os.Bundle; but now the problem is The import androidx.appcompat cannot be resolved .
I am looking for a solution that either gives me type definions for androidx.appcompat and other necessary dependencies. Or ways to get the plugin to detect and configure Android Project automatically. Or way to manually run the init.gradle file.
Trying to get vscode to detect Android Project but it does not seem to work. With
java.jdt.ls.androidSupport.enabledset toonit should automatically detect Android Project, add necessary files and classpath inProject and External Dependenciesautomatically but after many attempts none of the solutions seem to work.Android support should be available from here (eclipse-jdtls/eclipse.jdt.ls#2197) . This introduces a init.gradle file that should automatically add the Android Sourcesets, add classpath, all other android dependencies but I do not think that ever runs.
Here are my steps and partial temporary solution I came up with.
Steps:
java.jdt.ls.androidSupport.enabledtoon. (I have all other necessary setups such as having jdk installed.)java.import.gradle.enabledis set to enable so it detects the gradle projects. So far the error inMainActivity.java is not on the classpath of project app.Add Folder to Java Source Pathdo not work as it saysUnsupported operation. Please use build.gradle file to manage the source directories of gradle project.To resolve it I added this toapp/build.gradlefile:androidandandroidx. Errors:The import android cannot be resolvedandThe import androidx cannot be resolved. Still nothing insideProject and External Dependencieseven after running gradle build.It gives definions for android imports such as
import android.os.Bundle;but now the problem isThe import androidx.appcompat cannot be resolved.I am looking for a solution that either gives me type definions for
androidx.appcompatand other necessary dependencies. Or ways to get the plugin to detect and configure Android Project automatically. Or way to manually run the init.gradle file.