Search code examples
androidcustomizationexoplayeraarexoplayer2.x

How to Customise Open source aar code files?


Tehnology : Android

AAR which I need to customize : Exoplayer2

What I did : included the aar dependency in build.gradle, and the files in which I want to customize, took them out from the source code, and put them into exact same folder structure as their AAR, and made required changes in those files.

Where I stuck : when I run debug build, then it worked fine but when I tried to make release build it give me below error.

(Can't read [com] (Can't read [google] (Can't read [android] (Can't read [exoplayer2] (Can't read [ext] (Can't read [ima] (Can't read [ImaAdsLoader$Builder.class] (Duplicate jar entry [com/google/android/exoplayer2/ext/ima/ImaAdsLoader$Builder.class])))))))))

Below is my debug and release build configuration :

release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), '../proguard-rules.txt'
            release {
                signingConfig signingConfigs.release
            }
        }
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), '../proguard-rules.txt'
            signingConfig signingConfigs.debug
        }

What I tried to resolve this : As I took a complete single folder from that particular exoplayer module source, let's say xyz So I tried to exclude this folder from the aar dependecy but unable to do so.

Further I am assuming that including the complete source of that module instead of including that aar then issue would be resolved, but I am concerned with gradle dependecies of that module, should I include that too in my build.gradle manually ?

Please let me know the best way to achieve this !!


Solution

  • To customize Exoplayer2

    A: New own aar

    You should fork the repository, make your changes as new commit and build + publish to an maven repo.

    B: Include as code

    Or remove the aar dependency, add forked Exoplayer2 repo as git submodule to your repo. Make your changes and commit to fork and update pointer to submodule in your main repos

    Example

    You can look at a running example https://github.com/hannesa2/cwac-saferoom?organization=hannesa2&organization=hannesa2 Here I did exactly option #1 and published changed lib to https://jitpack.io/#hannesa2/cwac-saferoom Here you can see, how to include your new library