psambit9791 / jdsp

A Java Library for Digital Signal Processing
https://jdsp.dev
MIT License
240 stars 45 forks source link

Dependency resolution error #5

Closed d-lowl closed 3 years ago

d-lowl commented 3 years ago

There seem to be a dependency issue in 0.4.0. I am trying to build with Gradle from Andoid Studio and get the following error, when adding jDSP as a dependency

Duplicate class org.apache.maven.surefire.report.SafeThrowable found in modules jetified-common-java5-2.19.1.jar (org.apache.maven.surefire:common-java5:2.19.1) and jetified-surefire-api-2.19.1.jar (org.apache.maven.surefire:surefire-api:2.19.1)
Duplicate class org.apache.maven.surefire.report.StackTraceWriter found in modules jetified-common-java5-2.19.1.jar (org.apache.maven.surefire:common-java5:2.19.1) and jetified-surefire-api-2.19.1.jar (org.apache.maven.surefire:surefire-api:2.19.1)
d-lowl commented 3 years ago

The issue seem to start with version 0.3.0 (with introduction of JUnit5). 0.2.1 builds and works for me.

Steps to reproduce

EDIT: The library works if I include the jar directly, but doesn't work if I install it with gradle from Maven repository

psambit9791 commented 3 years ago

Could you show me the build.gradle file for the module and the Application build.gradle file?

d-lowl commented 3 years ago

That's a bare bone, but sure, see below

project build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.3.72"
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

module build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.1'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
    implementation 'uk.me.berndporr:iirj:1.1'
    implementation 'com.github.psambit9791:jdsp:0.4.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

}
psambit9791 commented 3 years ago

For project build.gradle, you will need the repository from which the JDSP will be downloaded:

Add this to your repositories:

maven {
            url "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
        }

for both buildscript and allprojects.

In case that does not work, could you try and remove the following dependencies from the Module build.gradle, and try Syncing again.

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

Adding the repository allowed me to compile my project based on the reproduction instruction provided.

d-lowl commented 3 years ago

Hmm, didn't work for me (neither with maven url you provided, nor from mavenCentral()). Ended up excluding these transitive dependencies manually (I assume they are not needed in runtime?) like this

implementation ('com.github.psambit9791:jdsp:0.4.0') {
        exclude group: 'org.apache.maven.surefire', module: 'common-java'
        exclude group: 'org.apache.maven.surefire', module: 'surefire-api'
    }

EDIT: maybe it's the gradle version issue, or something like that. I will probably look at it more thoroughly again later.

psambit9791 commented 3 years ago

Excluding maven.surefire will NOT cause any problems because it is used only for Tests and Report Generation. Closing issue as Fixed by excluding transitive dependencies.

psambit9791 commented 3 years ago

@d-lowl If you find this project useful, starring the project would be phenomenal. :)

d-lowl commented 3 years ago

Definitely, was meaning to do that. jDSP will the core component for the upcoming/ongoing project we are doing.

wgrand commented 2 years ago

Excluding maven.surefire will NOT cause any problems because it is used only for Tests and Report Generation. Closing issue as Fixed by excluding transitive dependencies.

Hmm, didn't work for me (neither with maven url you provided, nor from mavenCentral()). Ended up excluding these transitive dependencies manually (I assume they are not needed in runtime?) like this

implementation ('com.github.psambit9791:jdsp:0.4.0') {
        exclude group: 'org.apache.maven.surefire', module: 'common-java'
        exclude group: 'org.apache.maven.surefire', module: 'surefire-api'
    }

EDIT: maybe it's the gradle version issue, or something like that. I will probably look at it more thoroughly again later.

I also had to add this to my gradle:

android {
    packagingOptions {
        // Exclude these files because they conflict with those imported from the jDSP package
        exclude 'META-INF/*'
    }
}