-->

Using different versions of same library - More th

2020-04-10 00:37发布

问题:

The problem

i am trying to trim and compress a video using two libraries: Silicompressor and k4l-video-trimmer. the problem is both libraries use mp4parser but different versions of it. k4l-video-trimmer is using version 1.1.20 as a dependency in build.gradle and Silicompressor is using version 1.0.6 as a jar file. now the project builds fine but when i try to run it, i get the error:

More than one file was found with OS independent path 'builddef.lst'

The things i have already tried

Exclude builddef.lst in packaging options

i added these lines in app level build.gradle:

android {
    packagingOptions {
        exclude 'builddef.lst'
        exclude 'version.txt'
        exclude 'isoparser-default.properties'
    }
}

and then i got another error which i was unable to solve:

Program type already present: com.coremedia.iso.BoxParser Message{kind=ERROR, text=Program type already present: com.coremedia.iso.BoxParser, sources=[Unknown source file], tool name=Optional.of(D8)}

Exclude mp4parser from k4l-video-trimmer

i used

implementation ('life.knowledge4:k4l-video-trimmer:1.0') {
    exclude group: 'com.googlecode.mp4parser'
}

instead of

implementation 'life.knowledge4:k4l-video-trimmer:1.0'

and now the project runs and crashes when i try to trim a video.

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/googlecode/mp4parser/FileDataSourceViaHeapImpl; at life.knowledge4.videotrimmer.utils.TrimVideoUtils.genVideoUsingMp4Parser(TrimVideoUtils.java:72) at life.knowledge4.videotrimmer.utils.TrimVideoUtils.startTrim(TrimVideoUtils.java:65) at life.knowledge4.videotrimmer.K4LVideoTrimmer$5.execute(K4LVideoTrimmer.java:354) at life.knowledge4.videotrimmer.utils.BackgroundExecutor$Task.run(BackgroundExecutor.java:212) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761)

Exclude mp4parser from Silicompressor

i imported Silicompressor's module instead of using dependency line and removed mp4parser's jar file to force the library to use the version 1.1.20. now app runs again but the compressed video has no audio!

Use both versions of mp4parser

i used jarjar to repackage the jar file Silicompressor was using from com.googlecode.mp4parser to org.repackage.com.googlecode.mp4parser. still having the very same issue.

Build.gradle

here's my app level build.gradle file:

apply plugin: 'com.android.application'

configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
}

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "---"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    repositories {
        google()
        jcenter({url "http://jcenter.bintray.com/"})
        mavenLocal()
        jcenter()
        maven { url "http://jzaccone.github.io/SlidingMenu-aar" }
        maven { url "https://jitpack.io" }
        maven { url 'https://maven.google.com' }
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
    }

    /*packagingOptions {
        exclude 'builddef.lst'
        exclude 'version.txt'
        exclude 'isoparser-default.properties'
    }*/
}

dependencies {
    ...
    implementation ('life.knowledge4:k4l-video-trimmer:1.0') {
        exclude group: 'com.googlecode.mp4parser'
    }
    implementation 'com.iceteck.silicompressorr:silicompressor:2.1'
}

and THANK YOU FOR YOUR TIME!

回答1:

With the help of @MilanPansuriya I was finally able to solve the issue. Follow below steps to resolve above issue:-

  1. Create a new library combining both libraries (kl-trimmer and Silicompressor). In my case it was (kl-trimmer and VideoCompressor (https://github.com/fishwjy/VideoCompressor/)).
  2. Use isoparser-1.0.6.jar in your library.
  3. Now after building your new library you will get an error in class TrimVideoUtils of library kl-trimmer.
  4. Error will be for FileDataSourceViaHeapImpl not found. Actually particular class is available in higher version of isoparser. Change it to FileDataSourceImpl.
  5. Now library will build just fine in your project.

Note:- Both libraries will work fine now, but since we have changed FileDataSourceViaHeapImpl to FileDataSourceImpl sometimes I am getting Out Of Memory while trimming some large size videos (which is obviously supposed to happen & is also reported by users of older version of kl-trimmer).

As of now this is the only solution I am able to get. If someone have a better solution please update us too. Thanks.



回答2:

I was able to resolve this problem by doing just what the above answer says (combining both libraries) but in my case, i'm using SiliCompressor and AndroidDeveloperLB/VideoTrimmer, and i also created a library just for anyone who comes across this issue and wants a quick fix :) https://github.com/tobioyelekan/VideoTrimmerCompressor