-
-
Save gloc-mike/79d7ec0040447637f2639af7f020f94d to your computer and use it in GitHub Desktop.
iOS Gradle Utilities for Generating Fat Frameworks and dSYMs
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
afterEvaluate { | |
// Create tasks for creating fat frameworks and fat dsyms for sim and device | |
def binaryKinds = [ | |
// config, sim task, device task | |
new Tuple('Debug', linkDebugFrameworkIosSim, linkDebugFrameworkIosDevice), | |
new Tuple('Release', linkReleaseFrameworkIosSim, linkReleaseFrameworkIosDevice), | |
] | |
def libName = rootProject.name | |
def binaryOutputs = [ | |
// binary path, bundle name, task suffix | |
new Tuple("Contents/Resources/DWARF/$libName", "${libName}.framework.dSYM", 'DSYM'), | |
new Tuple(libName, "${libName}.framework", "Framework") | |
] | |
for (kind in binaryKinds) { | |
def (config, sim, device) = kind | |
def defaultOutputDir = "$buildDir/bin/ios${config}Fat" | |
for (outputInfo in binaryOutputs) { | |
def (binaryPath, bundleName, taskSuffix) = outputInfo | |
task("createIos${config}Fat${taskSuffix}", type: Exec, dependsOn: [sim, device]) { | |
// put together final path | |
def finalContainerParentDir = System.getenv('PG_POD_FRAMEWORK_DIR') ?: defaultOutputDir | |
def finalContainerPath = "$finalContainerParentDir/$bundleName" | |
def finalOutputPath = "$finalContainerPath/$binaryPath" | |
// gather initial paths | |
def simContainerParentDir = sim.outputFile.get().parent | |
def deviceContainerParentDir = device.outputFile.get().parent | |
doFirst { | |
mkdir new File(finalOutputPath).parent | |
} | |
executable 'lipo' | |
args = [ | |
'-create', | |
'-arch', 'arm64', "$deviceContainerParentDir/$bundleName/$binaryPath", | |
'-arch', 'x86_64', "$simContainerParentDir/$bundleName/$binaryPath", | |
'-output', finalOutputPath | |
] | |
doLast { | |
// copy other framework bits like info plist and headers | |
def initialContainer = "$deviceContainerParentDir/$bundleName" | |
copy { | |
from(initialContainer) { | |
// don't copy the thin binary, since we have a fat one already | |
exclude binaryPath | |
} | |
into finalContainerPath | |
} | |
// clean plist (only works for frameworks) | |
def plistPath = "$finalContainerPath/Info.plist" | |
if (new File(plistPath).exists()) { | |
exec { | |
executable '/usr/libexec/PlistBuddy' | |
args = ['-c', 'Delete :UIRequiredDeviceCapabilities', plistPath] | |
ignoreExitValue = true | |
} | |
} | |
// add the [system] attribute to the module map to silence warnings | |
def moduleMapPath = "$finalContainerPath/Modules/module.modulemap" | |
if (new File(moduleMapPath).exists()) { | |
exec { | |
executable 'sed' | |
args = ['-i', '.bak', '1 s/{/\\[system\\] {/', moduleMapPath] | |
} | |
delete "${moduleMapPath}.bak" | |
} | |
} | |
} | |
} | |
// Create the tasks that will call the framework and dsym tasks | |
def dependencies = binaryOutputs.collect { "createIos${config}Fat${it.last()}" } | |
task("createIos${config}Artifacts", dependsOn: dependencies, group: "iOS")) | |
} | |
// disable release dSYM task until https://github.com/JetBrains/kotlin-native/issues/2422 is fixed | |
createIosReleaseFatDSYM.enabled = false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment