openbakery / gradle-xcodePlugin

gradle plugin for building Xcode Projects for iOS, watchOS, macOS or tvOS
Apache License 2.0
458 stars 130 forks source link

Support for building frameworks #285

Closed duribreux closed 3 years ago

duribreux commented 8 years ago

I'm working on a Swift framework and I would like to create a sdk.framewok like I do from Xcode interface with product > archive > export process.

This is my build.gradle:

buildscript {
  repositories {
    maven {
      url('http://repository.openbakery.org/')
    }
    mavenCentral()
  }

  dependencies {
    classpath "org.openbakery:xcode-plugin:0.13.+"
  }
}

apply plugin: 'org.openbakery.xcode-plugin'

xcodebuild {
  version = "7" 

  scheme = "sdk"
  target = "sdk"
  configuration = "Release"

  destination = ["iPhone 6s"]
}

As you can see, there is nothing special. I also have part to override test task but that's irrelevant (Just changing scheme, target and configuration)

This is the error I have running gradle archive

** BUILD SUCCEEDED **

Done
:xcodebuild (Thread[main,5,main]) completed. Took 1.512 secs.
:archive (Thread[main,5,main]) started.
:archive
Executing task ':archive' (up-to-date check took 0.001 secs) due to:
  Task has not declared any outputs.
$(PRODUCT_NAME)
[ant:exec]  zip warning: name not matched: sdk.app
[ant:exec] 
[ant:exec] zip error: Nothing to do! (try: zip --symlinks --verbose --recurse-paths /path/to/project/build/archive/sdk.zip . -i sdk.app)
:archive FAILED
:archive (Thread[main,5,main]) completed. Took 0.194 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':archive'.
> exec returned: 12

Obviously running zip --symlinks --verbose --recurse-paths /path/to/project/build/archive/sdk.zip . -i sdk.app doesn't help.

And my build/ folder generated:

$ tree build -L 3
build
├── archive
├── derivedData
│   ├── Logs
│   │   └── Build
│   ├── ModuleCache
│   │   ├── 1EUCQ6XGIEYTP
│   │   ├── 1IAZKKMXUSGP
│   │   ├── 3KBDCMY29NDTM
│   │   ├── 7ZHI4DZGP9OX
│   │   ├── Session.modulevalidation
│   │   └── modules.timestamp
│   └── info.plist
├── obj
│   ├── Pods.build
│   │   ├── Release-iphonesimulator
│   │   └── all-product-headers.yaml
│   └── sdk.build
│       ├── Release-iphonesimulator
│       └── all-product-headers.yaml
├── project.plist
├── sym
│   └── Release-iphonesimulator
│       ├── Pods_sdk.framework
│       ├── sdk.framework
│       └── sdk.framework.dSYM
└── xcodebuild-output.txt

Since you're often asking for it, this is my gradle infoPlistModify --debug | grep org.openbakery.XcodeProjectFile output

14:56:26.381 [DEBUG] [org.openbakery.XcodeProjectFile] String rootObject=88885438D4629EC33A76233D
14:56:26.381 [DEBUG] [org.openbakery.XcodeProjectFile] rootObjectKey 88885438D4629EC33A76233D
14:56:26.382 [DEBUG] [org.openbakery.XcodeProjectFile] List objects.88885438D4629EC33A76233D.targets=[888855DA03A313D4C9203D2D, 888856810491253D063A8EA9]
14:56:26.383 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888855DA03A313D4C9203D2D.name=sdk
14:56:26.383 [DEBUG] [org.openbakery.XcodeProjectFile] List objects.88885438D4629EC33A76233D.targets=[888855DA03A313D4C9203D2D, 888856810491253D063A8EA9]
14:56:26.383 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888855DA03A313D4C9203D2D.name=sdk
14:56:26.383 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888855DA03A313D4C9203D2D.productType=com.apple.product-type.framework
14:56:26.384 [DEBUG] [org.openbakery.XcodeProjectFile] List objects.88885438D4629EC33A76233D.targets=[888855DA03A313D4C9203D2D, 888856810491253D063A8EA9]
14:56:26.384 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888855DA03A313D4C9203D2D.name=sdk
14:56:26.385 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888855DA03A313D4C9203D2D.buildConfigurationList=888859854DEBF58E31E830B5
14:56:26.385 [DEBUG] [org.openbakery.XcodeProjectFile] List objects.888859854DEBF58E31E830B5.buildConfigurations=[88885CA5818535E1E7046FDA, 88885879B55ADF50CDE701C4]
14:56:26.385 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885CA5818535E1E7046FDA.name=Debug
14:56:26.386 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885879B55ADF50CDE701C4.name=Release
14:56:26.390 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885879B55ADF50CDE701C4.buildSettings.PRODUCT_NAME=$(TARGET_NAME)
14:56:26.396 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885438D4629EC33A76233D.buildConfigurationList=888855707A42AC7540FF6530
14:56:26.396 [DEBUG] [org.openbakery.XcodeProjectFile] List objects.888855707A42AC7540FF6530.buildConfigurations=[888850050244C7F9BE79DF28, 8888597DA0CE9C41340FD3F6]
14:56:26.396 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888850050244C7F9BE79DF28.name=Debug
14:56:26.396 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.8888597DA0CE9C41340FD3F6.name=Release
14:56:26.397 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885879B55ADF50CDE701C4.buildSettings.SDKROOT=null
14:56:26.397 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.8888597DA0CE9C41340FD3F6.buildSettings.SDKROOT=iphoneos
14:56:26.398 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885879B55ADF50CDE701C4.buildSettings.TARGETED_DEVICE_FAMILY=null
14:56:26.402 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885879B55ADF50CDE701C4.buildSettings.INFOPLIST_FILE=sdk/Info.plist
14:56:26.402 [INFO] [org.openbakery.XcodeProjectFile] infoPlist: sdk/Info.plist
14:56:26.403 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885438D4629EC33A76233D.buildConfigurationList=888855707A42AC7540FF6530
14:56:26.404 [DEBUG] [org.openbakery.XcodeProjectFile] List objects.888855707A42AC7540FF6530.buildConfigurations=[888850050244C7F9BE79DF28, 8888597DA0CE9C41340FD3F6]
14:56:26.404 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888850050244C7F9BE79DF28.name=Debug
14:56:26.404 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.8888597DA0CE9C41340FD3F6.name=Release
14:56:26.408 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885438D4629EC33A76233D.buildConfigurationList=888855707A42AC7540FF6530
14:56:26.408 [DEBUG] [org.openbakery.XcodeProjectFile] List objects.888855707A42AC7540FF6530.buildConfigurations=[888850050244C7F9BE79DF28, 8888597DA0CE9C41340FD3F6]
14:56:26.408 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888850050244C7F9BE79DF28.name=Debug
14:56:26.409 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888850050244C7F9BE79DF28.buildSettings.INFOPLIST_FILE=null
14:56:26.409 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888850050244C7F9BE79DF28.buildSettings.PRODUCT_BUNDLE_IDENTIFIER=null
14:56:26.409 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888850050244C7F9BE79DF28.buildSettings.PRODUCT_NAME=null
14:56:26.410 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888850050244C7F9BE79DF28.buildSettings.SDKROOT=iphoneos
14:56:26.410 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888850050244C7F9BE79DF28.buildSettings.CODE_SIGN_ENTITLEMENTS=null
14:56:26.410 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888850050244C7F9BE79DF28.buildSettings.TARGETED_DEVICE_FAMILY=1,2
14:56:26.411 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885438D4629EC33A76233D.buildConfigurationList=888855707A42AC7540FF6530
14:56:26.411 [DEBUG] [org.openbakery.XcodeProjectFile] List objects.888855707A42AC7540FF6530.buildConfigurations=[888850050244C7F9BE79DF28, 8888597DA0CE9C41340FD3F6]
14:56:26.411 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888850050244C7F9BE79DF28.name=Debug
14:56:26.411 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.8888597DA0CE9C41340FD3F6.name=Release
14:56:26.411 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.8888597DA0CE9C41340FD3F6.buildSettings.INFOPLIST_FILE=null
14:56:26.412 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.8888597DA0CE9C41340FD3F6.buildSettings.PRODUCT_BUNDLE_IDENTIFIER=null
14:56:26.412 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.8888597DA0CE9C41340FD3F6.buildSettings.PRODUCT_NAME=null
14:56:26.412 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.8888597DA0CE9C41340FD3F6.buildSettings.SDKROOT=iphoneos
14:56:26.412 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.8888597DA0CE9C41340FD3F6.buildSettings.CODE_SIGN_ENTITLEMENTS=null
14:56:26.413 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.8888597DA0CE9C41340FD3F6.buildSettings.TARGETED_DEVICE_FAMILY=1,2
14:56:26.413 [DEBUG] [org.openbakery.XcodeProjectFile] List objects.88885438D4629EC33A76233D.targets=[888855DA03A313D4C9203D2D, 888856810491253D063A8EA9]
14:56:26.413 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888855DA03A313D4C9203D2D.name=sdk
14:56:26.413 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888856810491253D063A8EA9.name=sdkTests
14:56:26.416 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888855DA03A313D4C9203D2D.buildConfigurationList=888859854DEBF58E31E830B5
14:56:26.417 [DEBUG] [org.openbakery.XcodeProjectFile] List objects.888859854DEBF58E31E830B5.buildConfigurations=[88885CA5818535E1E7046FDA, 88885879B55ADF50CDE701C4]
14:56:26.418 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885CA5818535E1E7046FDA.name=Debug
14:56:26.418 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885CA5818535E1E7046FDA.buildSettings.INFOPLIST_FILE=sdk/Info.plist
14:56:26.419 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885CA5818535E1E7046FDA.buildSettings.PRODUCT_BUNDLE_IDENTIFIER=com.apisense.sdk
14:56:26.419 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885CA5818535E1E7046FDA.buildSettings.PRODUCT_NAME=$(TARGET_NAME)
14:56:26.420 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885CA5818535E1E7046FDA.buildSettings.SDKROOT=null
14:56:26.421 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885CA5818535E1E7046FDA.buildSettings.CODE_SIGN_ENTITLEMENTS=null
14:56:26.421 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885CA5818535E1E7046FDA.buildSettings.TARGETED_DEVICE_FAMILY=null
14:56:26.422 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888855DA03A313D4C9203D2D.buildConfigurationList=888859854DEBF58E31E830B5
14:56:26.422 [DEBUG] [org.openbakery.XcodeProjectFile] List objects.888859854DEBF58E31E830B5.buildConfigurations=[88885CA5818535E1E7046FDA, 88885879B55ADF50CDE701C4]
14:56:26.423 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885CA5818535E1E7046FDA.name=Debug
14:56:26.423 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885879B55ADF50CDE701C4.name=Release
14:56:26.423 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885879B55ADF50CDE701C4.buildSettings.INFOPLIST_FILE=sdk/Info.plist
14:56:26.423 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885879B55ADF50CDE701C4.buildSettings.PRODUCT_BUNDLE_IDENTIFIER=com.apisense.sdk
14:56:26.423 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885879B55ADF50CDE701C4.buildSettings.PRODUCT_NAME=$(TARGET_NAME)
14:56:26.424 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885879B55ADF50CDE701C4.buildSettings.SDKROOT=null
14:56:26.424 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885879B55ADF50CDE701C4.buildSettings.CODE_SIGN_ENTITLEMENTS=null
14:56:26.424 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885879B55ADF50CDE701C4.buildSettings.TARGETED_DEVICE_FAMILY=null
14:56:26.425 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888856810491253D063A8EA9.buildConfigurationList=888854EB64636E569A06E8EE
14:56:26.425 [DEBUG] [org.openbakery.XcodeProjectFile] List objects.888854EB64636E569A06E8EE.buildConfigurations=[88885939A46A9580F36D4BFF, 88885BDC9B50E3F0FC6D09FF]
14:56:26.427 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885939A46A9580F36D4BFF.name=Debug
14:56:26.428 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885939A46A9580F36D4BFF.buildSettings.INFOPLIST_FILE=sdkTests/Info.plist
14:56:26.428 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885939A46A9580F36D4BFF.buildSettings.PRODUCT_BUNDLE_IDENTIFIER=com.apisense.sdkTests
14:56:26.428 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885939A46A9580F36D4BFF.buildSettings.PRODUCT_NAME=$(TARGET_NAME)
14:56:26.429 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885939A46A9580F36D4BFF.buildSettings.SDKROOT=null
14:56:26.429 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885939A46A9580F36D4BFF.buildSettings.CODE_SIGN_ENTITLEMENTS=null
14:56:26.429 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885939A46A9580F36D4BFF.buildSettings.TARGETED_DEVICE_FAMILY=null
14:56:26.429 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.888856810491253D063A8EA9.buildConfigurationList=888854EB64636E569A06E8EE
14:56:26.430 [DEBUG] [org.openbakery.XcodeProjectFile] List objects.888854EB64636E569A06E8EE.buildConfigurations=[88885939A46A9580F36D4BFF, 88885BDC9B50E3F0FC6D09FF]
14:56:26.430 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885939A46A9580F36D4BFF.name=Debug
14:56:26.430 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885BDC9B50E3F0FC6D09FF.name=Release
14:56:26.430 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885BDC9B50E3F0FC6D09FF.buildSettings.INFOPLIST_FILE=sdkTests/Info.plist
14:56:26.431 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885BDC9B50E3F0FC6D09FF.buildSettings.PRODUCT_BUNDLE_IDENTIFIER=com.apisense.sdkTests
14:56:26.431 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885BDC9B50E3F0FC6D09FF.buildSettings.PRODUCT_NAME=$(TARGET_NAME)
14:56:26.432 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885BDC9B50E3F0FC6D09FF.buildSettings.SDKROOT=null
14:56:26.433 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885BDC9B50E3F0FC6D09FF.buildSettings.CODE_SIGN_ENTITLEMENTS=null
14:56:26.433 [DEBUG] [org.openbakery.XcodeProjectFile] String objects.88885BDC9B50E3F0FC6D09FF.buildSettings.TARGETED_DEVICE_FAMILY=null

I did try a lot of variations in my build.gradle but without any success. Maybe it's simply not the good command, maybe it's not possible, i didn't find any input about archive in the documentation.

Thanks

renep commented 8 years ago

Building standalone frameworks and archiving is missing in the plugin.

saravnandm commented 5 years ago

Hi, struck with the same problem. Any update on this ?

renep commented 5 years ago

Building frameworks should be possible. I have created an example with this project: https://github.com/openbakery/OBInjector

When you execute ./gradlew archiveFramework a zip archive is created in ./build/distributions

(The example is not a swift project, but this should not make any difference)

saravnandm commented 5 years ago

Hi, Tried your Gradle script. still getting the same error. Am I missing something ?

Task :archiveFramework FAILED

FAILURE: Build failed with an exception.

Could not list contents of '/build/sym/Release-iphoneos/TEST.framework/TEST'. Couldn't follow symbolic link.

renep commented 5 years ago

When you execute the buildFramework is the framework built in /build/sym/Release-iphoneos ?

saravnandm commented 5 years ago

Yes its there for both simulator and iphoneos. But my framework has the dependency of .a file. is it problem?

screen shot 2019-01-30 at 12 09 08

saravnandm commented 5 years ago

Finally, it worked by separately building debug and release [simulator + iphoneos]. The below task will create TEST.framework.zip in 'buildDir/nexus_build' directory. is it possible to build debug and release [simulator + iphoneos] in single shot?

task packageDistribution(type: Zip) { archiveName = "TEST.framework.zip" destinationDir = file("$buildDir/nexus_build")

from "$buildDir/sym/Release-iphoneos/TEST.framework" }

renep commented 5 years ago

You can define your tasks by yourself in your build.gradle file. Just create a task buildSimulator and a Task buildRelease and the packageDistribution depends on both.

saravnandm commented 5 years ago

Hi, The built framework is working for simulator app. But when I try to use it for iphoneos app getting the following error.

/Pods-TestApp/Pods-TEST-frameworks.sh: line 104: EXPANDED_CODE_SIGN_IDENTITY: unbound variable Command PhaseScriptExecution failed with a nonzero exit code

I guess its due to signing issue. Could you tell me what's wrong with the following TESTAPP code signing? Also, I'm not doing any signing for my built framework.

signing { certificateURI = 'file:///Users/saravanan/Desktop/certificates/Certificates.p12' certificatePassword = 'test' mobileProvisionURI = 'file:///Users/saravanan/Desktop/certificates/saravanandev.mobileprovision' }

ErikEverson commented 5 years ago

That issue could be from cocoa pods. Basically a newer version of cocoa pods may be able to fix it Reference to the issue here There is also a pre-released version rather than the beta version of cocoa pods in release 1.6.0.rc.2

renep commented 5 years ago

Yes, I think I had the same issue.