Android Studio highlights all Java classes with JNI functions

651 views Asked by At

Since the update to Android Studio 4.1.0 stable, all of my classes with JNI implemented functions are colored as red with code highlight.

Red example

Below you can see my project structure. There are several library projects and the main ck-learn project. All the classes with the native code are placed in jni-wrappers project, while CMakeLists.txt is in a top library project peshka which uses jni-wrappers (see screenshot).

The syntax was colored as usual in Android Studio 4.0.2. All the classes were visible in the peshka project. But now they are highlighted with red, as they were not found. But the projects compiles as usual. It is only a visual problem.

If I open someof the files colored in red, there is a warning:

This .java file is outside of Java source roots and won't be added to the classpath.

The source roots are standard (src\main\java) and it all was fine in AS 4.0.2.

Can someone help with this problem?

Project structure

2

There are 2 answers

0
tgeng On BEST ANSWER

As confirmed by the OP from the comment, this is caused by a bug in Android Studio 4.1.0, which gets partially fixed in Android Studio 4.1.1. The full fix is still in progress. More details on the symptoms and workaround can be found from this bug.

0
Iwo Banas On

Double check your sourceSets configuration. We had similar issue and it turned out to be caused main module pointing to sources inside the other module. Android Studio 4.0 accepted such config but Android Studio 4.1 doesn't.