our project is a monolithic android application-- is currently relies on 2 different libraries to stream different video content, hls/dash and regular video content. the problem we're facing is that one of these libraries is actually just a wrapper around the other one, which led us down the path of hardcoding a dependency resolution strategy in the gradle to avoid duplicate library errors.
configurations.all { config ->
resolutionStrategy {
dependencySubstitution {
substitute module("com.google.android.exoplayer:exoplayer-core:$exoplayerVersion") with module("com.axinom.sdk:exoplayer-library-core:$axinomVersion")
}
cacheChangingModulesFor 0, 'seconds' // only affects snapshots
}
}
the problem with this approach is that this will apply globally, even in the package that contains the hls/dash feature, say this package is located at "org.example.project.features.livetv". I want to conditionally apply the statement resolution strategy above everywhere except for this package.
How can I do this without modularizing the app into separate feature with their own gradle config?
I've tried adding a simple if-statement but that doesn't work as the substitution statement in itself will still apply globally, since there are no restrictions on it once the if-statement if met.
I've tried creating a separate configuration tied to the "livetv" package which will contain all the core dependencies as the app does but will not apply the substitution clause but I was getting all sorts of build errors from that-- probably because I'm not doing it correctly. See below:
// Define a custom configuration for the livetv package
configurations {
livetvCompile
}
// Global substitution rule
configurations.all {
if (name != 'livetvCompile') { // Apply substitution to all configurations except 'livetvCompile'
resolutionStrategy.dependencySubstitution {
substitute module("com.google.android.exoplayer:exoplayer-core:$exoplayerVersion") with module("com.axinom.sdk:exoplayer-library-core:$axinomVersion")
}
}
}
// Dependencies for 'livetvCompile' configuration
configurations.livetvCompile {
// Define dependencies specific to the 'livetv' package
implementation("com.google.android.exoplayer:exoplayer-core:$exoplayerVersion")
}
// Apply 'livetvCompile' configuration to the 'livetv' package
sourceSets {
main {
java {
srcDir 'src/main/java'
exclude '**/livetv/**'
}
}
livetv {
java {
srcDir 'src/main/java'
include '**/livetv/**'
}
compileClasspath += configurations.livetvCompile
}
}