Search code examples
javaandroidandroid-studioshared-librariesimporterror

Android Studio Cannot Find Imported Library (Using TarsosDSP java import error)


There is a package (TarsosDSP) that I wish to use in my app SongTracker. I am able to import 4 of 5 the libraries, but the 5th import statement has the error when trying to compile:

import be.tarsos.dsp.io.android.AudioDispatcherFactory;

Here is the error:

Cannot resolve symbol 'android'

What I Have Tried

Build -> Clean Project

Build -> Rebuild Project

Neither helped. I’m not sure whether to post the full build output, but here is a partial output:

FAILURE: Build completed with 8 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find be.tarsos:dsp:2.4.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/be/tarsos/dsp/2.4/dsp-2.4.pom
       - https://repo.maven.apache.org/maven2/be/tarsos/dsp/2.4/dsp-2.4.pom
       - https://jcenter.bintray.com/be/tarsos/dsp/2.4/dsp-2.4.pom
       - https://mvn.0110.be/releases/be/tarsos/dsp/2.4/dsp-2.4.pom

     Required by:
         project :app

Background

I already have my app built, which opens .txt files so that the words and chords to the songs being displayed are viewable (hence the need to scroll). I wish to use TarsosDSP so the app can 'listen' to the beats-per-minute using the device microphone and adjust the scrolling speed for the .txt file dynamically. However, I cannot begin to tweak TarsosDSP until I get all the relevant libraries to install and run.

The library is being used in this method setupTarasosDSP:

// Initialize TarsosDSP audio processing for BPM detection
AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0);

The AudioDispatcherFactory is highlighted in red, and Android Studio states: Cannot resolve symbol 'AudioDispatcherFactory'.

In my build.gradle file, I have these dependencies:

// TarsosDSP library
implementation 'be.tarsos.dsp:core:2.5'
implementation 'be.tarsos.dsp:jvm:2.5'
implementation 'be.tarsos:dsp:2.4'

I have four other related import statements, all of which seem to have no issue:

import be.tarsos.dsp.AudioDispatcher;
import be.tarsos.dsp.AudioProcessor;
import be.tarsos.dsp.pitch.PitchDetectionHandler;
import be.tarsos.dsp.pitch.PitchProcessor;

Below is my settings.gradle file:

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        //maven { url 'https://jitpack.io' }
        jcenter()
        maven {
            name = "TarsosDSP repository"
            url = "https://mvn.0110.be/releases"
        }
    }
}
rootProject.name = "Song Tracker"
include ':app'

Solution

  • Based on the comments from OP it would appear that

    import be.tarsos.dsp.io.android.AudioDispatcherFactory;

    Does not exist in the version of the libraries being imported, i.e. the main popular Tarsos DSP project: https://github.com/JorenSix/TarsosDSP

    and that on Android be.tarsos.dsp.io.jvm.AudioDispatcherFactory will not work directly.

    A general recommendation for adding a third-party library to a Android project is to check any documentation/issue tickets (open and closed) available to verify that Android support does exist for that project or if it some other fork of the base library being referenced. As Android has been evolving its APIs with some regularity (Android permissions, changes in function signature, etc.) checking what is and isn't supported should be considered.