Last active
August 2, 2024 10:43
-
-
Save OleksandrKucherenko/8239dc7c792417eae344708f2e51f1b6 to your computer and use it in GitHub Desktop.
repack AAR with different types of compatibility things, like: androidx vs support library, include/exclude/repackage aar during compilation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Copyright: 2019-*, Oleksandr Kucherenko ([email protected]) */ | |
apply plugin: 'com.android.library' | |
android { | |
/* ... default android lib OR app configuration ... */ | |
} | |
configurations { | |
repack { transitive = false } | |
compatibility { transitive = false } | |
} | |
dependencies { | |
// include re-packed facebook conceal lib, https://github.com/facebook/conceal/releases | |
repack "com.facebook.conceal:conceal:1.1.3@aar" | |
/* https://mvnrepository.com/artifact/androidx.biometric/biometric | src: http://bit.ly/31DhLZG */ | |
compatibility 'androidx.biometric:biometric:1.0.0-rc01@aar' | |
} | |
task repackConceal(dependsOn: configurations.repack) { | |
group = "Workarounds" | |
description = "repack facebook conceal library, exclude soloader sources" | |
def concealVersion = configurations.repack.allDependencies.first().version | |
def generation = "${project.buildDir}/intermediates/repack" | |
def conceal = "com.facebook.conceal@${concealVersion}" | |
def destination = "${generation}/${conceal}" | |
def aarFile = "com.facebook.conceal-${concealVersion}-repack.aar" | |
project.dependencies { | |
implementation fileTree(dir: "${generation}", include: ["*-repack.aar"]) | |
} | |
doLast { | |
copy { | |
from { zipTree(configurations.repack.singleFile) } | |
into "${destination}" | |
} | |
copy { | |
from zipTree("${destination}/classes.jar") | |
into "${destination}/classes" | |
} | |
} | |
task recreateConcealClassesJar(type: Zip) { | |
archiveFileName = "classes-patched.jar" | |
destinationDirectory = file("${destination}") | |
from("${destination}/classes") { | |
exclude '**/facebook/jni/' | |
exclude '**/facebook/proguard/' | |
exclude '**/facebook/soloader/' | |
} | |
} | |
task recreateConcealAar(type: Zip, dependsOn: recreateConcealClassesJar) { | |
archiveFileName = aarFile | |
destinationDirectory = file("${generation}") | |
from("${destination}") { | |
exclude '**/jni/*/libfb.so' | |
exclude '**/classes' | |
exclude 'classes.jar' | |
rename('classes-patched.jar', 'classes.jar') | |
} | |
} | |
finalizedBy recreateConcealAar | |
} | |
task compatibilityBiometric(dependsOn: configurations.compatibility, type: Copy) { | |
group = "Workarounds" | |
description = "expand biometric library for androidx/android support compatibility" | |
def isAndroidX = Boolean.parseBoolean("${project.getProperties()["android.useAndroidX"]}") | |
def biometricVersion = configurations.compatibility.allDependencies.first().version | |
def generation = "${project.buildDir}/intermediates/compatibility" | |
def aarFile = "biometric-${biometricVersion}.aar" | |
def libPrefix = isAndroidX ? "androidx" : "support" | |
def supportFile = "biometric-${biometricVersion}-${libPrefix}.aar" | |
def bin = file("${project.projectDir}/../bin/jetifier-standalone/bin").absolutePath | |
logger.lifecycle("androidx: ${isAndroidX}, support lib: ${!isAndroidX}") | |
project.dependencies { | |
implementation fileTree(dir: "${generation}", include: ["*-${libPrefix}.aar"]) | |
/* We can include extra ldependencies if needed with different conditions. */ | |
if (isAndroidX) { | |
implementation 'androidx.appcompat:appcompat:1.1.0' | |
implementation 'androidx.legacy:legacy-support-v4:1.0.0' | |
} | |
} | |
from { configurations.compatibility.singleFile } | |
into "${generation}" | |
// https://developer.android.com/studio/command-line/jetifier | |
task reverseJetifier(type: Exec) { | |
outputs.cacheIf { true } | |
outputs.file "${generation}/${supportFile}" | |
inputs.file "${generation}/${aarFile}" | |
workingDir "${generation}" | |
commandLine "${bin}/jetifier-standalone" | |
args = [(isAndroidX ? "" : "--reversed"), | |
"--input", "${generation}/${aarFile}", | |
"--output", "${generation}/${supportFile}", | |
"--log", "error"] | |
} | |
finalizedBy reverseJetifier | |
} | |
preBuild.dependsOn([repackConceal, compatibilityBiometric]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment