From e4746efb224354cabb1eb42a2b197eda46f763b0 Mon Sep 17 00:00:00 2001 From: davidliu Date: Wed, 27 Dec 2023 16:19:01 +0900 Subject: [PATCH] Support dual publishing of standard and prefixed webrtc build (#18) * Support dual publishing of standard and prefixed webrtc build * Prefix so files to avoid collison --- .github/workflows/publish.yml | 10 ++- .gitignore | 3 +- .idea/.gitignore | 3 + .idea/compiler.xml | 6 ++ .idea/gradle.xml | 22 +++++ .idea/misc.xml | 9 ++ .idea/vcs.xml | 6 ++ README.md | 11 ++- android-prefixed/.gitignore | 1 + android-prefixed/build.gradle | 118 +++++++++++++++++++++++++++ android-prefixed/deploy/README | 1 + android-prefixed/deploy/javadoc.jar | Bin 0 -> 206 bytes android-prefixed/deploy/sources.jar | Bin 0 -> 206 bytes android-prefixed/shadow/.gitignore | 1 + android-prefixed/shadow/build.gradle | 24 ++++++ android/.gitignore | 1 + android/build.gradle | 83 +++++++++++++++++++ android/deploy/README | 1 + android/deploy/javadoc.jar | Bin 0 -> 206 bytes android/deploy/sources.jar | Bin 0 -> 206 bytes build.gradle | 80 +----------------- downloadAar.sh | 1 + downloadAar_prefixed.sh | 32 ++++++++ gradle.properties | 8 +- prefixmove.sh | 26 ++++++ settings.gradle | 14 +++- 26 files changed, 372 insertions(+), 89 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 android-prefixed/.gitignore create mode 100644 android-prefixed/build.gradle create mode 100644 android-prefixed/deploy/README create mode 100644 android-prefixed/deploy/javadoc.jar create mode 100644 android-prefixed/deploy/sources.jar create mode 100644 android-prefixed/shadow/.gitignore create mode 100644 android-prefixed/shadow/build.gradle create mode 100644 android/.gitignore create mode 100644 android/build.gradle create mode 100644 android/deploy/README create mode 100644 android/deploy/javadoc.jar create mode 100644 android/deploy/sources.jar create mode 100755 downloadAar_prefixed.sh create mode 100755 prefixmove.sh diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a952031..17f00dc 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,11 +25,15 @@ jobs: java-version: '12' distribution: 'adopt' - - name: Download aar - run: ./downloadAar.sh + - name: Download aars + run: | + ./downloadAar.sh + ./downloadAar_prefixed.sh - name: Check aar exists - run: test -f "libwebrtc.aar" + run: | + test -f "android/libwebrtc.aar" + test -f "android-prefixed/libwebrtc_prefixed.aar" - name: Grant execute permission for gradlew run: chmod +x gradlew diff --git a/.gitignore b/.gitignore index d015fa2..4d9ac33 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build/ .gradle/ .DS_Store -*.asc \ No newline at end of file +*.asc +local.properties \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..1c5ab05 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..f869fbc --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f61c2d0 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 429914b..fab8e7b 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,15 @@ This library is hosted on Maven Central. To include this library in your project ```gradle dependencies { - implementation 'io.github.webrtc-sdk:android:114.5735.05' + implementation 'io.github.webrtc-sdk:android:114.5735.06' } ``` + +We also offer a shadowed version that moves the `org.webrtc` package to `livekit.org.webrtc`, +avoiding any collisions with other WebRTC libraries: + +```gradle + dependencies { + implementation 'io.github.webrtc-sdk:android-prefixed:114.5735.06' + } +``` \ No newline at end of file diff --git a/android-prefixed/.gitignore b/android-prefixed/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/android-prefixed/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/android-prefixed/build.gradle b/android-prefixed/build.gradle new file mode 100644 index 0000000..bc6433b --- /dev/null +++ b/android-prefixed/build.gradle @@ -0,0 +1,118 @@ +plugins { + id 'signing' + id 'com.android.library' + id 'com.kezong.fat-aar' + id 'maven-publish' +} +group = 'com.github.davidliu' + +android { + namespace 'com.github.davidliu.lkshadowwebrtc' + compileSdk 33 + + defaultConfig { + minSdk 21 + } + + buildTypes { + release { + minifyEnabled false + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + afterEvaluate { + generateReleaseBuildConfig.enabled = false + generateDebugBuildConfig.enabled = false + generateReleaseResValues.enabled = false + generateDebugResValues.enabled = false + } +} + +dependencies { + compileOnly project(path: ':android-prefixed:shadow', configuration: 'shadow') + embed project(path: ':android-prefixed:shadow', configuration: 'shadow') +} + +def POM_ARTIFACT_ID = "android-prefixed" + +def getReleaseRepositoryUrl() { + return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL + : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" +} + +def getRepositoryUsername() { + return hasProperty('nexusUsername') ? nexusUsername : "" +} + +def getRepositoryPassword() { + return hasProperty('nexusPassword') ? nexusPassword : "" +} + +def configurePom(pom) { + pom.name = POM_NAME + pom.packaging = POM_PACKAGING + pom.description = POM_DESCRIPTION + pom.url = POM_URL + + pom.scm { + url = POM_SCM_URL + connection = POM_SCM_CONNECTION + developerConnection = POM_SCM_DEV_CONNECTION + } + + pom.licenses { + license { + name = POM_LICENCE_NAME + url = POM_LICENCE_URL + distribution = POM_LICENCE_DIST + } + } + + pom.developers { + developer { + id = POM_DEVELOPER_ID + name = POM_DEVELOPER_NAME + } + } +} + +afterEvaluate { + + publishing { + repositories { + maven { + url getReleaseRepositoryUrl() + credentials(PasswordCredentials) { + username = getRepositoryUsername() + password = getRepositoryPassword() + } + } + } + publications { + androidPrefixed(MavenPublication) { + // Applies the component for the release build variant. + from components.release + + groupId = GROUP + artifactId = POM_ARTIFACT_ID + version = VERSION_NAME + artifact("deploy/sources.jar") { + classifier 'sources' + } + artifact("deploy/javadoc.jar") { + classifier 'javadoc' + } + configurePom(pom) + } + } + + signing { + publishing.publications.all { publication -> + sign publication + } + } + } +} \ No newline at end of file diff --git a/android-prefixed/deploy/README b/android-prefixed/deploy/README new file mode 100644 index 0000000..5f2833f --- /dev/null +++ b/android-prefixed/deploy/README @@ -0,0 +1 @@ +Javadoc and sources are not available, but are required for deployment on Sonatype. These jars are used to bypass those checks. \ No newline at end of file diff --git a/android-prefixed/deploy/javadoc.jar b/android-prefixed/deploy/javadoc.jar new file mode 100644 index 0000000000000000000000000000000000000000..97523a5084e963d8a990973ee1b787c5ae528572 GIT binary patch literal 206 zcmWIWW@Zs#-~dAAO}SwVP{0SI*%%ZUf?OS4d|g9Bcp2Eml=xF%xU_0|3yvocF;LXmlZ}Q{C0zf&CNdexBOd`w(Tae{Iw!pxWMi7fQ UI|IB~*+8lpfiMI}r+_#N0Il*O1^@s6 literal 0 HcmV?d00001 diff --git a/android-prefixed/deploy/sources.jar b/android-prefixed/deploy/sources.jar new file mode 100644 index 0000000000000000000000000000000000000000..97523a5084e963d8a990973ee1b787c5ae528572 GIT binary patch literal 206 zcmWIWW@Zs#-~dAAO}SwVP{0SI*%%ZUf?OS4d|g9Bcp2Eml=xF%xU_0|3yvocF;LXmlZ}Q{C0zf&CNdexBOd`w(Tae{Iw!pxWMi7fQ UI|IB~*+8lpfiMI}r+_#N0Il*O1^@s6 literal 0 HcmV?d00001 diff --git a/android-prefixed/shadow/.gitignore b/android-prefixed/shadow/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/android-prefixed/shadow/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/android-prefixed/shadow/build.gradle b/android-prefixed/shadow/build.gradle new file mode 100644 index 0000000..9b8c584 --- /dev/null +++ b/android-prefixed/shadow/build.gradle @@ -0,0 +1,24 @@ +plugins { + id 'java-library' + id 'com.github.johnrengelman.shadow' version '7.1.2' +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_7 + targetCompatibility = JavaVersion.VERSION_1_7 +} + +dependencies { + api files("libs/classes.jar") +} + +shadowJar { + +} +import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation + +task relocateShadowJar(type: ConfigureShadowRelocation) { + target = tasks.shadowJar + prefix = "livekit" // Default value is "shadow" +} +tasks.shadowJar.dependsOn tasks.relocateShadowJar diff --git a/android/.gitignore b/android/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/android/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle new file mode 100644 index 0000000..84cd3ea --- /dev/null +++ b/android/build.gradle @@ -0,0 +1,83 @@ + +apply plugin: "maven-publish" +apply plugin: 'signing' + +def POM_ARTIFACT_ID = "android" +def AAR_FILE = "libwebrtc.aar" + +def getReleaseRepositoryUrl() { + return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL + : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" +} + +def getRepositoryUsername() { + return hasProperty('nexusUsername') ? nexusUsername : "" +} + +def getRepositoryPassword() { + return hasProperty('nexusPassword') ? nexusPassword : "" +} + +def configurePom(pom) { + pom.name = POM_NAME + pom.packaging = POM_PACKAGING + pom.description = POM_DESCRIPTION + pom.url = POM_URL + + pom.scm { + url = POM_SCM_URL + connection = POM_SCM_CONNECTION + developerConnection = POM_SCM_DEV_CONNECTION + } + + pom.licenses { + license { + name = POM_LICENCE_NAME + url = POM_LICENCE_URL + distribution = POM_LICENCE_DIST + } + } + + pom.developers { + developer { + id = POM_DEVELOPER_ID + name = POM_DEVELOPER_NAME + } + } +} + +afterEvaluate { + + publishing { + repositories { + maven { + url getReleaseRepositoryUrl() + credentials(PasswordCredentials) { + username = getRepositoryUsername() + password = getRepositoryPassword() + } + } + } + publications { + android(MavenPublication) { + groupId = GROUP + artifactId = POM_ARTIFACT_ID + version = VERSION_NAME + artifact(AAR_FILE) + artifact("deploy/sources.jar") { + classifier 'sources' + } + artifact("deploy/javadoc.jar") { + classifier 'javadoc' + } + configurePom(pom) + } + } + + signing { + publishing.publications.all { publication -> + sign publication + } + } + } +} \ No newline at end of file diff --git a/android/deploy/README b/android/deploy/README new file mode 100644 index 0000000..5f2833f --- /dev/null +++ b/android/deploy/README @@ -0,0 +1 @@ +Javadoc and sources are not available, but are required for deployment on Sonatype. These jars are used to bypass those checks. \ No newline at end of file diff --git a/android/deploy/javadoc.jar b/android/deploy/javadoc.jar new file mode 100644 index 0000000000000000000000000000000000000000..97523a5084e963d8a990973ee1b787c5ae528572 GIT binary patch literal 206 zcmWIWW@Zs#-~dAAO}SwVP{0SI*%%ZUf?OS4d|g9Bcp2Eml=xF%xU_0|3yvocF;LXmlZ}Q{C0zf&CNdexBOd`w(Tae{Iw!pxWMi7fQ UI|IB~*+8lpfiMI}r+_#N0Il*O1^@s6 literal 0 HcmV?d00001 diff --git a/android/deploy/sources.jar b/android/deploy/sources.jar new file mode 100644 index 0000000000000000000000000000000000000000..97523a5084e963d8a990973ee1b787c5ae528572 GIT binary patch literal 206 zcmWIWW@Zs#-~dAAO}SwVP{0SI*%%ZUf?OS4d|g9Bcp2Eml=xF%xU_0|3yvocF;LXmlZ}Q{C0zf&CNdexBOd`w(Tae{Iw!pxWMi7fQ UI|IB~*+8lpfiMI}r+_#N0Il*O1^@s6 literal 0 HcmV?d00001 diff --git a/build.gradle b/build.gradle index 7170124..8c4b4bd 100644 --- a/build.gradle +++ b/build.gradle @@ -1,92 +1,20 @@ buildscript { repositories { google() + gradlePluginPortal() mavenCentral() } dependencies { classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0" + classpath "com.android.tools.build:gradle:7.1.3" + classpath 'com.github.kezong:fat-aar:1.3.8' } } -apply plugin: "maven-publish" -apply plugin: 'signing' + apply plugin: 'io.codearte.nexus-staging' nexusStaging { serverUrl = "https://s01.oss.sonatype.org/service/local/" packageGroup = GROUP stagingProfileId = "550fa82137976" -} - -def getReleaseRepositoryUrl() { - return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL - : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" -} - -def getRepositoryUsername() { - return hasProperty('nexusUsername') ? nexusUsername : "" -} - -def getRepositoryPassword() { - return hasProperty('nexusPassword') ? nexusPassword : "" -} - -def configurePom(pom) { - pom.name = POM_NAME - pom.packaging = POM_PACKAGING - pom.description = POM_DESCRIPTION - pom.url = POM_URL - - pom.scm { - url = POM_SCM_URL - connection = POM_SCM_CONNECTION - developerConnection = POM_SCM_DEV_CONNECTION - } - - pom.licenses { - license { - name = POM_LICENCE_NAME - url = POM_LICENCE_URL - distribution = POM_LICENCE_DIST - } - } - - pom.developers { - developer { - id = POM_DEVELOPER_ID - name = POM_DEVELOPER_NAME - } - } -} - -publishing { - repositories { - maven { - url getReleaseRepositoryUrl() - credentials(PasswordCredentials) { - username = getRepositoryUsername() - password = getRepositoryPassword() - } - } - } - publications { - maven(MavenPublication) { - groupId = GROUP - artifactId = POM_ARTIFACT_ID - version = VERSION_NAME - artifact ("libwebrtc.aar") - artifact ("deploy/sources.jar") { - classifier 'sources' - } - artifact ("deploy/javadoc.jar") { - classifier 'javadoc' - } - configurePom(pom) - } - } - - signing { - publishing.publications.all { publication -> - sign publication - } - } } \ No newline at end of file diff --git a/downloadAar.sh b/downloadAar.sh index 3dffe2f..3dc6baa 100755 --- a/downloadAar.sh +++ b/downloadAar.sh @@ -1,6 +1,7 @@ #!/bin/bash set -e +set -x # Get VERSION_NAME from gradle.properties VERSION=`grep -o 'VERSION_NAME=.*' gradle.properties | cut -f2- -d=` diff --git a/downloadAar_prefixed.sh b/downloadAar_prefixed.sh new file mode 100755 index 0000000..fd8e72c --- /dev/null +++ b/downloadAar_prefixed.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -e +set -x + +# Get VERSION_NAME from gradle.properties +VERSION=`grep -o 'VERSION_NAME=.*' gradle.properties | cut -f2- -d=` + +SDK_BIN_URL=https://github.com/webrtc-sdk/android/releases/download/v${VERSION}/libwebrtc_prefixed.aar + +echo "Downloading webrtc-sdk ${VERSION} prefixed binary for android." +curl -f -L -O ${SDK_BIN_URL} + +# The prefixed aar can't be used as is. +# The jar itself needs to be shadowed to properly add on the prefix. +unzip -o libwebrtc_prefixed.aar -d prefix/ +rm -rf android-prefixed/shadow/libs/* +mkdir -p android-prefixed/shadow/libs +mv prefix/classes.jar android-prefixed/shadow/libs/ + +# Copy the .so files to the main project for inclusion. +rm -rf android-prefixed/src/main/jniLibs/* +mkdir -p android-prefixed/src/main/jniLibs +mv prefix/jni/* android-prefixed/src/main/jniLibs + +# Rename the so files to liblkjingle_peerconnection_so.so +find android-prefixed/src/main/jniLibs/ -type f \ + -name "libjingle_peerconnection_so.so" \ + -exec sh -c 'f="{}"; mv -- "$f" "${f%libjingle_peerconnection_so.so}liblkjingle_peerconnection_so.so"' \; + +# clean up unzipped prefix files +rm -rf prefix/ \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 0637cd8..04d4456 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,23 +1,17 @@ GROUP=io.github.webrtc-sdk VERSION_NAME=114.5735.05 - POM_NAME=WebRTC Android SDK POM_DESCRIPTION=WebRTC Android SDK -POM_ARTIFACT_ID=android POM_PACKAGING=aar - POM_URL=https://github.com/webrtc-sdk/android POM_SCM_URL=https://github.com/webrtc-sdk/android POM_SCM_CONNECTION=scm:git:git://github.com/webrtc-sdk/android.git POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/webrtc-sdk/android.git - POM_LICENCE_NAME=The 3-Clause BSD License POM_LICENCE_URL=https://opensource.org/license/bsd-3-clause/ POM_LICENCE_DIST=repo - POM_DEVELOPER_ID=webrtc-sdk POM_DEVELOPER_NAME=webrtc-sdk - RELEASE_REPOSITORY_URL=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ SNAPSHOT_REPOSITORY_URL=https://s01.oss.sonatype.org/content/repositories/snapshots/ # Variables required to allow build.gradle to parse for publishing. @@ -27,4 +21,4 @@ nexusUsername= nexusPassword= signing.keyId= signing.password= -signing.secretKeyRingFile= \ No newline at end of file +signing.secretKeyRingFile= diff --git a/prefixmove.sh b/prefixmove.sh new file mode 100755 index 0000000..6c3414a --- /dev/null +++ b/prefixmove.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# Similar script to downloadAar_prefixed.sh, without the download part. +# For use with local testing aars. + +set -e +set -x + +# The prefixed aar can't be used as is. +# The jar itself needs to be shadowed to properly add on the prefix. +unzip -o libwebrtc_prefixed.aar -d prefix/ +rm -rf android-prefixed/shadow/libs/* +mkdir -p android-prefixed/shadow/libs +mv prefix/classes.jar android-prefixed/shadow/libs/ + +# Copy the .so files to the main project for inclusion. +rm -rf android-prefixed/src/main/jniLibs/* +mkdir -p android-prefixed/src/main/jniLibs +mv prefix/jni/* android-prefixed/src/main/jniLibs + +# Rename the so files to liblkjingle_peerconnection_so.so +find android-prefixed/src/main/jniLibs/ -type f \ + -name "libjingle_peerconnection_so.so" \ + -exec sh -c 'f="{}"; mv -- "$f" "${f%libjingle_peerconnection_so.so}liblkjingle_peerconnection_so.so"' \; + +# clean up unzipped prefix files +rm -rf prefix/ \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 7a10b9d..01f03ee 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,17 @@ pluginManagement { repositories { + google() + mavenCentral() gradlePluginPortal() } -} \ No newline at end of file +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} +include ':android' +include ':android-prefixed' +include ':android-prefixed:shadow'