openbakery / gradle-xcodePlugin

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

Code signing issue when using xcodetest #378

Closed tobiasbe closed 6 years ago

tobiasbe commented 6 years ago

Hi :)

I am facing an issue when trying to test my application using gradle.

Situation:

What i've found out myself:

How to reproduce:

SampleApp.zip

Thanks in advance, Tobias

This is the part of the debug output i am referring to:

15:32:47.293 [INFO] [org.openbakery.CommandRunner]     /usr/bin/codesign --force --sign - --timestamp=none /Users/tobiasbecker/Desktop/DynTest/build/sym/Debug-iphonesimulator/DynTest.app/PlugIns/DynTestTests.xctest
15:32:47.620 [INFO] [org.openbakery.CommandRunner]
15:32:55.201 [INFO] [org.openbakery.CommandRunner] dyld: Library not loaded: @rpath/Dynatrace.framework/Dynatrace
15:32:55.201 [INFO] [org.openbakery.CommandRunner]   Referenced from: /Users/tobiasbecker/Library/Developer/CoreSimulator/Devices/9579DF94-884A-49A8-85EC-1842756997A8/data/Containers/Bundle/Application/481E79C3-5621-4E18-A1CC-34EBC2E2C5F9/DynTest.app/DynTest
15:32:55.201 [INFO] [org.openbakery.CommandRunner]   Reason: no suitable image found.  Did find:
15:32:55.201 [INFO] [org.openbakery.CommandRunner]      /Users/tobiasbecker/Library/Developer/CoreSimulator/Devices/9579DF94-884A-49A8-85EC-1842756997A8/data/Containers/Bundle/Application/481E79C3-5621-4E18-A1CC-34EBC2E2C5F9/DynTest.app/Frameworks/Dynatrace.framework/Dynatrace: required code signature missing for '/Users/tobiasbecker/Library/Developer/CoreSimulator/Devices/9579DF94-884A-49A8-85EC-1842756997A8/data/Containers/Bundle/Application/481E79C3-5621-4E18-A1CC-34EBC2E2C5F9/DynTest.app/Frameworks/Dynatrace.framework/Dynatrace'
15:32:55.201 [INFO] [org.openbakery.CommandRunner]
15:32:55.202 [INFO] [org.openbakery.CommandRunner]      /Users/tobiasbecker/Library/Developer/CoreSimulator/Devices/9579DF94-884A-49A8-85EC-1842756997A8/data/Containers/Bundle/Application/481E79C3-5621-4E18-A1CC-34EBC2E2C5F9/DynTest.app/Frameworks/Dynatrace.framework/Dynatrace: required code signature missing for '/Users/tobiasbecker/Library/Developer/CoreSimulator/Devices/9579DF94-884A-49A8-85EC-1842756997A8/data/Containers/Bundle/Application/481E79C3-5621-4E18-A1CC-34EBC2E2C5F9/DynTest.app/Frameworks/Dynatrace.framework/Dynatrace'
15:32:55.202 [INFO] [org.openbakery.CommandRunner]
15:32:55.202 [INFO] [org.openbakery.CommandRunner]      /Users/tobiasbecker/Library/Developer/CoreSimulator/Devices/9579DF94-884A-49A8-85EC-1842756997A8/data/Containers/Bundle/Application/481E79C3-5621-4E18-A1CC-34EBC2E2C5F9/DynTest.app/Frameworks/Dynatrace.framework/Dynatrace: required code signature missing for '/Users/tobiasbecker/Library/Developer/CoreSimulator/Devices/9579DF94-884A-49A8-85EC-1842756997A8/data/Containers/Bundle/Application/481E79C3-5621-4E18-A1CC-34EBC2E2C5F9/DynTest.app/Frameworks/Dynatrace.framework/Dynatrace'
renep commented 6 years ago

Ok the binary framework must be signed first.

A workaround for this is that you create a custom task that is executed after the cocoapodsInstall and before the test tasks an executes the following command:

/usr/bin/codesign --force --sign - --verbose ./Pods/Dynatrace/iOS/agent/Dynatrace.framework
tobiasbe commented 6 years ago

Thank you, Rene.

This little workaround helps for now.

task manualCodeSign() {
    def command = "/usr/bin/codesign --force --sign - --verbose ./Pods/Dynatrace/iOS/agent/Dynatrace.framework"
    def proc = command.execute()
    proc.waitFor()
}

xcodetest {
    dependsOn manualCodeSign
}
tobiasbe commented 6 years ago

@renep Unfortunately this did only work for the sample app. In my main app there seems to be yet another issue that makes xcodebuild fail with error code 65.

The question here is, why signing is relevant for a simulator build at all? I've recognized the following: When using the xcodetest task, it starts xcodebuild like this:

xcodebuild -scheme DynTest -workspace DynTest.xcworkspace -configuration Debug \
CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO \
-destination platform=iOS\ Simulator,id=9579DF94-884A-49A8-85EC-1842756997A8 \
-derivedDataPath /Users/tobiasbecker/Desktop/DynTest/connect-ios/build/derivedData \
DSTROOT=/Users/tobiasbecker/Desktop/DynTest/connect-ios/build/dst \
OBJROOT=/Users/tobiasbecker/Desktop/DynTest/connect-ios/build/obj \
SYMROOT=/Users/tobiasbecker/Desktop/DynTest/connect-ios/build/sym \
SHARED_PRECOMPS_DIR=/Users/tobiasbecker/Desktop/DynTest/connect-ios/build/shared \
-enableCodeCoverage yes test

When this command is run, xcodebuild runs the codesigning, even though in gradle i've specificied that i want to run a simulator build.

When i remove the CODE_SIGINING_IDENTITY= and CODE_SIGNING_REQUIRED=NO parts it does not code sign anything, which makes the tests run without any problems on both the sample app and my main project.

Is there any way to make the gradle-xcodePlugin not add these two or would that need a change?

renep commented 6 years ago

I have updated the plugin that the CODE_SIGINING_IDENTITY= and CODE_SIGNING_REQUIRED=NO is not added for a iOS simualtor build. Can you test the latest develop version if this solves this issue: https://github.com/openbakery/gradle-xcodePlugin/tree/develop#current-develop-version

tobiasbe commented 6 years ago

Hi Rene,

thank you very much. This indeed solves the problem. :+1:

phatblat commented 6 years ago

@tobiasbe Can this issue be closed now?

tobiasbe commented 6 years ago

Oh sure. Thanks for the reminder