I'm working on building an android library and I want to include a dependency of the library as a transitive dependency into my app. Here's my library's build.gradle
file:
plugins {
id 'com.android.library'
id 'com.github.dcendents.android-maven'
}
group='com.github.rohg007.xxx'
android {
compileSdkVersion 30
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//SDK level dependencies
implementation 'org.protoojs.droid:protoo-client:4.0.3'
api 'org.webrtc:google-webrtc:1.0.32006'
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
implementation("com.squareup.okhttp3:logging-interceptor:4.9.1")
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.6'
implementation 'com.jakewharton.timber:timber:4.7.1'
}
repositories {
mavenCentral()
}
It works fine and all transitive dependencies are resolved when I include the library as a module:
implementation project(path: ':huddle01-android-sdk')
But when I release on Jitpack and include it as a dependency:
implementation 'com.rohg007.xxx:0.1.0'
or
implementation ('com.rohg007.xxx:0.1.0'){transitive=true}
It fails to resolve the webrtc dependency. How to include the transitive dependency on release as well?
Jitpack uses ./gradlew install
for generating the artifacts.
Adding an install block and manually appending the dependencies to the pom file worked for me.
Here's the install
block that I added to the module level build.gradle
file:
android {
...
}
dependencies {
...
}
install{
repositories{
mavenInstaller{
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.implementation.allDependencies.each { dependency ->
if (dependency.name != 'unspecified') {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dependency.group)
dependencyNode.appendNode('artifactId', dependency.name)
dependencyNode.appendNode('version', dependency.version)
}
}
}
}
}
}
I'm not sure if it's a clean solution to the problem. If there are cleaner alternatives, do let me know.