Please refer to aTalk, an open source project for more info.
aTalk is an xmpp-client app for android. It relies on many third parties libraries e.g. smack, and ice4j etc for its features implementation. Currently aTalk uses jarjar-gradle tool to expand these libraries features support as well as to fix errors. Below is one of the android build.gradle files used in aTalk for smack libraries to achieve the results. jarjar-gradle tool is also being used in the project main build.gradle file.
However "org.anarres.jarjar:jarjar-gradle:1.0.1" is not compatible and cannot support android gradle v7.0. aTalk has been trying to use shadow as a replacement tool for jarjar-gradle so as to upgrade to use gradle v7.0, but has not been successful to achieve the same result as the jarjar-gradle tools. Note: some commented out shadow codes are included in the file.
Appreciate if anyone can offer some help on how to use shadow to achieve the same result as jarjar-gradle. Or are there other equivalent tools that offer the same jarjar-gradle functionalities and compatible with android gradle v7.0.
// import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
buildscript {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
dependencies {
classpath "org.anarres.jarjar:jarjar-gradle:1.0.1"
// classpath 'com.github.shevek.jarjar:jarjar-gradle:9a7eca72f9'
// classpath "com.github.jengelman.gradle.plugins:shadow:6.1.0"
}
}
plugins {
id 'base'
}
apply plugin: 'org.anarres.jarjar'
// apply plugin: "com.github.johnrengelman.shadow"
repositories {
google()
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
//configurations {
// // define a separate configuration for shadow
// internalize
//}
def smackVersion = '4.4.6'
/* a task to create the relocated libs, must be defined before used below in dependencies */
//task internalizeJar(type: ShadowJar) {
// archiveClassifier.set("m2/org/igniterealtime/smack/smack-intern/${smackVersion}/smack")
// configurations = [project.configurations.internalize] // our configuration from above
//
// // i.e. transitive = false
// dependencies {
// exclude(dependency('org.hsluv:hsluv:'))
// exclude(dependency('org.igniterealtime.smack:smack-core:'))
// exclude(dependency('org.igniterealtime.smack:smack-im:'))
// exclude(dependency('org.igniterealtime.smack:smack-xmlparser:'))
// exclude(dependency('org.jxmpp:jxmpp-core:'))
// exclude(dependency('org.jxmpp:jxmpp-jid:'))
// exclude(dependency('org.jxmpp:jxmpp-util-cache:'))
// exclude(dependency('org.minidns:minidns-core:'))
// }
//
// // ===== smack - 4.4.3 =====
// exclude 'org.jivesoftware.smackx.httpfileupload.HttpFileUploadManager**'
// exclude 'org.jivesoftware.smackx.chatstates.ChatStateManager**'
//}
//
//// These libs are the dependency of the internalizeJar configuration
//dependencies {
// internalize "org.igniterealtime.smack:smack-experimental:$smackVersion"
// internalize "org.igniterealtime.smack:smack-extensions:$smackVersion"
//
// implementation tasks.internalizeJar.outputs.files // our real project uses the relocated jar as dependency
//}
def jarJarDeps = task("jarJarDeps") {
doFirst {
println "Fixed smack dependencies"
}
}
/*
* jarjar.repackage with generated dir/filename specified - default in build/jarjar/jarjar-xxx.jar
* destinationDir may use relative i.e. "../../libs to $buildDir/jarjar or as per below
* filename must not contains colon i.e. ":" colon, treated as URL and will failed missing classes
* classDelete must check actual jar to see if end ** is required - due to multiple components
* May use className and className$** to delete only the related, but excluding classes with same prefix
*/
jarJarDeps.dependsOn(
// smack-core
jarjar.repackage {
from("org.igniterealtime.smack:smack-core:$smackVersion") {
transitive = false
}
destinationDir new File("${projectDir}/../aTalk/third_party/m2/org/igniterealtime/smack/smack-core-jarjar/${smackVersion}")
destinationName "smack-core-jarjar-${smackVersion}.jar"
classDelete 'org.jivesoftware.smack.packet.AbstractIqBuilder'
classDelete 'org.jivesoftware.smack.packet.EmptyResultIQ'
classDelete 'org.jivesoftware.smack.packet.ErrorIQ'
classDelete 'org.jivesoftware.smack.packet.IqView'
classDelete 'org.jivesoftware.smack.packet.IQ**'
classDelete 'org.jivesoftware.smack.util.InternetAddress**'
classDelete 'org.jivesoftware.smack.util.PacketParserUtils**'
classDelete 'org.jivesoftware.smack.util.ParserUtils**'
},
// smack-experimental
jarjar.repackage {
from("org.igniterealtime.smack:smack-experimental:$smackVersion") {
transitive = false
}
destinationDir new File("${projectDir}/../aTalk/third_party/m2/org/igniterealtime/smack/smack-experimental-jarjar/${smackVersion}")
destinationName "smack-experimental-jarjar-${smackVersion}.jar"
// Add support for media file sharing
classDelete 'org.jivesoftware.smackx.httpfileupload.HttpFileUploadManager**'
classDelete 'org.jivesoftware.smackx.jingle_filetransfer.JingleFileTransferManager**'
},
// smack-extensions
jarjar.repackage {
from("org.igniterealtime.smack:smack-extensions:$smackVersion") {
transitive = false
}
destinationDir new File("${projectDir}/../aTalk/third_party/m2/org/igniterealtime/smack/smack-extensions-jarjar/${smackVersion}")
destinationName "smack-extensions-jarjar-${smackVersion}.jar"
// Do not send <close/> on an already closed InBandBytestream session
classDelete 'org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamSession**'
// Add support for chatStat in conference room
classDelete 'org.jivesoftware.smackx.chatstates.ChatStateManager**'
classDelete 'org.jivesoftware.smackx.jingle.JingleManager**'
classDelete 'org.jivesoftware.smackx.jingle.JingleUtil**'
classDelete 'org.jivesoftware.smackx.jingle.element.Jingle'
classDelete 'org.jivesoftware.smackx.jingle.element.Jingle$**'
classDelete 'org.jivesoftware.smackx.jingle.element.JingleAction**'
classDelete 'org.jivesoftware.smackx.jingle.element.JingleContent'
classDelete 'org.jivesoftware.smackx.jingle.element.JingleContent$**'
classDelete 'org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement'
classDelete 'org.jivesoftware.smackx.jingle.element.JingleContentDescription'
classDelete 'org.jivesoftware.smackx.jingle.element.JingleContentTransport'
classDelete 'org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidate'
classDelete 'org.jivesoftware.smackx.jingle.element.JingleContentTransportInfo'
classDelete 'org.jivesoftware.smackx.jingle.element.JingleReason**'
classDelete 'org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager**'
classDelete 'org.jivesoftware.smackx.jingle.provider.JingleProvider**'
classDelete 'org.jivesoftware.smackx.jingle.transports.JingleTransportManager**'
classDelete 'org.jivesoftware.smackx.jingle.transports.jingle_ibb.element.JingleIBBTransport**'
classDelete 'org.jivesoftware.smackx.jingle.transports.jingle_ibb.JingleIBBTransportManager**'
classDelete 'org.jivesoftware.smackx.jingle.transports.jingle_s5b.JingleS5BTransportManager**'
classDelete 'org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport'
classDelete 'org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport$**'
classDelete 'org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportInfo**'
// Must do local compilation as case CandidateActivated.ELEMENT (candidate-activated): has changed to case 'activated'
classDelete 'org.jivesoftware.smackx.jingle.transports.jingle_s5b.provider.JingleS5BTransportProvider**'
},
// smack-omemo
jarjar.repackage {
from("org.igniterealtime.smack:smack-omemo:$smackVersion") {
transitive = false
}
destinationDir new File("${projectDir}/../aTalk/third_party/m2/org/igniterealtime/smack/smack-omemo-jarjar/${smackVersion}")
destinationName "smack-omemo-jarjar-${smackVersion}.jar"
classDelete 'org.jivesoftware.smackx.omemo.OmemoManager**'
}
)
tasks.getByName("build").dependsOn(jarJarDeps)
Use shadow tool but cannot achieve the same results as jarjar-gradle