简体   繁体   中英

Error while using Github library in Java in Android Studio

I want to create a Speaker Recognition Android app using android studio.

I came accross https://github.com/amaurycrickx/recognito Library in java. But I am having difficulty in implementing it in Android.

First, I saved the recognito folder by copying it in libs folder (creating it manually) in my main directory of my android app.

Then, in settings.gradle file -- include ':recognito'

build.gradle app file --     compile project(':recognito')

After sync. getting the error -

Error:Project :app declares a dependency from configuration 'compile' to configuration 'default' which is not declared in the descriptor for project :recognito.

I researched, Gradle error: configuration declares dependency which is not declared It says that since build.gradle file doesn`t exists for the Recognito project. But how will it? Cos it contains only java files.

Please help ..

Build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.0'

    defaultConfig {
        applicationId "com.urvi.android.abc"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile project(':recognito')

}

settings.gradle

include ':app'
include ':recognito'

and the folder Recognito I copied has https://github.com/amaurycrickx/recognito/tree/master/recognito files. I did not copy from the initial path

It seems that this library has not been made to be used for Android app but Java application. It uses parts of the Java API not available for Android (like javax.sound.sampled.*). Plus I'd not recommend to use any library not being updated in the last 3 years.

The way you try to add the library it needs to have gradle build-files. I see 2 ways to solve the problem:

  • create a jar from the library and include it this way
  • use a service like jitpack to include the library

For generating the jar: * clone the repo * cd recognito * mvn package

then you get:

Results :

Tests run: 53, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ recognito ---
[INFO] Building jar: /home/ligi/git/3rd/recognito/recognito/target/recognito-0.1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.318 s
[INFO] Finished at: 2017-06-07T11:58:23+02:00
[INFO] Final Memory: 21M/302M
[INFO] --

there is your jar - now include it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM