Repository navigation
Android gradle project do not work - Eclipse build.gradle script #3682
Description
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.enabledtoon. (I have all other necessary setups such as having jdk installed.) - After that by default vscode setting
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. - Using
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:
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
androidandandroidx. Errors:The import android cannot be resolvedandThe import androidx cannot be resolved. Still nothing insideProject and External Dependencieseven 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.
Activity
Fix AndroidSupport with recent AGP versions
Fix AndroidSupport with recent AGP versions
Fix Android Support with recent AGP versions
Fix Android Support with recent AGP versions
Fix Android Support with recent AGP versions
Fix Android Support with recent AGP versions
Fix Android Support with recent AGP versions
Fix Android Support with recent AGP versions
Fix Android Support with recent AGP versions
Fix Android Support with recent AGP versions
Fix Android Support with recent AGP versions
Fix Android Support with recent AGP versions
Fix Android Support with recent AGP versions
nwrkbiz commentedon Sep 20, 2025
fyi: fix got merged upstream.
@hitabi
rgrunber commentedon Oct 1, 2025
Closing this for now as it appears it was merged in JDT-LS.
Holbormon commentedon Oct 21, 2025
Hi, is this supposed to be fixed in the latest release
1.46.0? The release notes state that the fix was merged, but I can still reproduce with a fresh install from here, as well as by switching to the latest prerelease .fbricon commentedon Oct 21, 2025
@Holbormon can you provide a sample project reproducing the issue?
Holbormon commentedon Oct 22, 2025
Sure, here is
settings.gradle:and in a subfolder named
mainproject,build.gradleis as follows (with the fix from @hitabi included at the top):The rest of the project hierarchy is pretty standard, just as Android Studio would generate it (code in
mainproject/src/main/java/com/project/). I should probably mention that CLIgradleworks just fine with this config. The vscode extension however (after applying the workaround from @hitabi) complains specifically aboutandroidximports, and also local imports from sub-folders of the main sourcemainproject/src/main/java/com/projectfolder. Not sure whether this matters but I have tried importing in the vscode workspace both the parent (root/settings.gradle) and the child project (root/project/build.gradle), but also only one of them at a time, always yielding the same result.Apologies if there is something obvious I missed, as I am self-learning gradle at the moment.