Ettore
Ettore

Reputation: 1

Configure Classpath in VSCode for Android with Gradle

I'm trying to use VSCode to create an android application using gradle 8.12.1 and jdk 23.0.1 but I got the following problem: MainActivity.java is not on the classpath of project app, only syntax errors are reported

The Gradle for Java Plugin says:

Class References There are cases where Gradle tasks will generate Java classes. To ensure these Java classes > are indexed correctly by the Java language server, you need to ensure the paths are added to > the .classpath, and this is typically achieved using Gradle sourceSets.

Once you've configured your sourceSets correctly, follow these steps:

Generate your classes by running the relevant Gradle Task Force the Language Server to index the generated classes by right-clicking on build.gradle and selecting Update project configuration. At this point the Gradle sourceSet paths will be added to the .classpath and the Language Server will automatically update references when those classes change.

sourceSetsare configurated on build.gradle inside android{} in app dir.

sourceSets {
        // Código principal
        main {
            // Códigos em java
            java {
                srcDir 'src/main/java' // declaração explicita do diretório java
            }
            // Recursos do código
            res {
                srcDir 'src/main/resources' // androidx entende "res", porém o gradle cria "resources"
            }
        }
        // Códigos de teste
        test {
             // Códigos em java dos testes
            java {
                srcDir 'src/test/java' // declaração explicita do diretório java
            }
            // Recursos dod códigos de teste
            res {
                srcDir 'src/test/resources' // androidx entende "res", porém o gradle cria "resoures"
            }
        }
    }

There is no "Update project configuration" when I righ-click build.gradle in app dir.

optionsBuildGradle

Upvotes: 0

Views: 50

Answers (0)

Related Questions