2

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
ccxi11
  • 73
  • 7
  • "Except every time i reference "oboe", the text gets red." - Don't mistake your IDEs (flawed) attempts to help you with what is *actually* valid and what the *actual* compiler says. Just because your IDEs (limited) C++ parser doesn't understand something and marks it with red (or whatever), does *not* mean that it's not valid C++. It just means your IDE is flawed (which happens *a lot*). – Jesper Juhl Aug 27 '19 at 19:58
  • Thank you for your answer! So there is no apparent way to fix this problem? – ccxi11 Aug 27 '19 at 20:05
  • Also, when opening the sample code from the library there is no error in the header – ccxi11 Aug 27 '19 at 20:07
  • IDEs are not perfect and don't implement full C++ parsers. So they are sometimes wrong. Deal with it. Compile your code and get the messages from the *real* compiler if you want something you can trust (more). – Jesper Juhl Aug 27 '19 at 20:09
  • That i will do then. Thanks! – ccxi11 Aug 27 '19 at 20:13
  • @JesperJuhl One of the primary benefits of using an IDE compared to the command line is to get all the helpful stuff like autocompletion, linter errors, compiler warnings, linker errors ahead of time, without needing to go through a full build. If Android Studio is showing errors when the build is successful this is a bug, and not something which should be just put up with. You can easily file a bug by going to `Help->Submit Feedback` – donturner Sep 04 '19 at 13:52
  • @donturner I don't disagree, but it's just a fact of life that most (all?) IDEs do *not* use full C++ parsers for their UI warnings etc (which makes sense, since that would slow them down to the speed of a full build). So, to get the true picture you *must* run the real compiler. – Jesper Juhl Sep 04 '19 at 14:22
  • Thank you for all the comments. It gave me some insight to what the problem could be. I solved it by creating new projects in which i wrote to the makefile in varying orders, building the project for every line i wrote. This resulted in it suddenly not showing any errors. During this process i also tried the answer from donturner. – ccxi11 Oct 06 '19 at 19:48

2 Answers2

4

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.
donturner
  • 17,867
  • 8
  • 59
  • 81
0

Likely missing the prefab declaration in your gradle script

buildFeatures {
        viewBinding true
        prefab true
    }

Or Gradle properties

android.useAndroidX=true
android.enableJetifier=true
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
kotlin.code.style=official
android.prefabVersion=1.0.+
# Workaround bug in AGP where the prefab dependency is being resolved from a
# non-Gradle thread when enableParallelJsonGen is enabled.
# https://issuetracker.google.com/149575364
android.enableParallelJsonGen=false
android.buildFeatures.prefab = true
Danoli3
  • 3,203
  • 3
  • 24
  • 35