Search code examples
javaandroidc++latencyoboe

Android Studio cannot find Oboe headers, but app still runs


I am trying to incorporate the Oboe native library into a DAW that i am making. It seems to be working, the app runs seemingly with no trouble. The problem is, that Android Studio doesn't seem to be able to find the headers from the Oboe directory. This results in me not being able to use many of the features in Android Studio such as predictions and so. It looks like this (couldn't upload an image):

#include <jni.h>
#include <string>
#include <android/log.h>
#include <oboe/Oboe.h>

using namespace std;

extern "C" JNIEXPORT void JNICALL
Java_com_ralleq_nsynth_MainActivity_buildAudioStream(JNIEnv *env, jclass /* this */) {

    oboe::AudioStreamBuilder builder;
    oboe::AudioStream *stream = nullptr;
    oboe::Result result = builder.openStream(&stream);

    __android_log_print(ANDROID_LOG_VERBOSE, "NATIVE", "Didn't crash", 0);
}

Except every time i reference "oboe", the text gets red.

Hovering the mouse over the red text reveals a popup saying: " Cannot find 'oboe' ". Which is weird, because the project has no trouble compiling and running with the written code. I think it might have something to do with a path in Android Studio that is not defined correctly. I have tried creating a shared library mimicking the sample code given in the oboe repository and tried to implement it as a library instead of a subdirectory in the CMakeList file, but have in the end returned to referencing a git-imported project in my projects folder as a subdirectory.

The implementation of Oboe in the makefile:

set(OBOE_DIR /AndroidStudioProjects/oboe)
add_subdirectory(${OBOE_DIR} ./oboe)
include_directories(${OBOE_DIR} ./include)

target_link_libraries( # Specifies the target library.
        native-lib
        oboe
        log
        # Links the target library to the log library
        # included in the NDK.
        ${log-lib})

I have noticed, that references to the library have been added as i refreshed the c++ projects, but i don't seem to be able to reach them. I simply do not understand, how Android Studio cannot find the headers.

I have been looking around for other people with the same problem, but it has always been about a crash rather than a problem with the Android Studio software itself.

Thanks in advance for any help.

  • Rasmus

Solution

  • This happens to me often. It's frustrating and I can never figure out exactly what the cause is (other than the obvious "the indexer is borked"), however, a few things usually fix it. Here's what I try, in order of time impact on my working day:

    1. Build -> Refresh Linked C++ Project
    2. Close project, reopen it
    3. File -> Invalidate caches and restart
    4. Close Android Studio. Delete the "hidden" cache folder in ~/Library/Caches/AndroidStudio. Reopen Android Studio.
    5. Check for a new version of Android Studio, if available update current version.