Repository: flutter
Issue: iOS build fails with "SecKey API returned: -25308" "codesign failed with exit code 1"
Labels: platform-ios,tool,t: xcode,P2,team-ios,triaged-ios

## Steps to Reproduce

Follow Getting started guide to create to create default "myapp"

Able to launch against simulator, but get following error against real iDevice

first run i get the standard message:

```
Could not build the precompiled application for the device.
══════════════════════════════════════════════════════════════════
Building an iOS app requires a selected Development Team with a Provisioning Profile
Please ensure that a Development Team is selected by:
  1- Opening the Flutter project's Xcode target with
       open ios/Runner.xcworkspace
  2- Select the 'Runner' project in the navigator then the 'Runner' target
     in the project settings
  3- In the 'General' tab, make sure a 'Development Team' is selected

For more information, please visit:
  https://flutter.io/setup/#deploy-to-ios-devices
```

I open the workspace as suggested and add my team.  (Xcode set for automatic management of signing, I have a a valid wildcard provisioning profile)

i run flutter run again and get this error

```
      /usr/bin/codesign --force --sign 7D8FC5A3FC9ADE6BFAA1B387E733C232D239A97F --preserve-metadata=identifier,entitlements --timestamp=none /Users/jeffa/Documents/myapp/build/ios/Release-iphoneos/Runner.app/Frameworks/Flutter.framework
    SecKey API returned: -25308, (null)/Users/jeffa/Documents/myapp/build/ios/Release-iphoneos/Runner.app/Frameworks/Flutter.framework: unknown error -1=ffffffffffffffff
    Command /usr/bin/codesign failed with exit code 1
    
Could not build the precompiled application for the device.
```

If I build/run the target from inside Xcode it launches on the device and runs.


Please tell us what you were doing and what went wrong. If you are running flutter tools from the command line, please try adding the `-v` or `--verbose` option to gather more information.

```
 myapp $ flutter doctor -v 
[[1m +178 ms[0m] /usr/bin/defaults read /Applications/Android Studio.app/Contents/Info CFBundleShortVersionString
[  +95 ms] Exit code 0 from: /usr/bin/defaults read /Applications/Android Studio.app/Contents/Info CFBundleShortVersionString
[        ] 2.3
[  +12 ms] [/Users/jeffa/Documents/flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +10 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/master
[        ] [/Users/jeffa/Documents/flutter/] git ls-remote --get-url origin
[   +9 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[        ] [/Users/jeffa/Documents/flutter/] git log -n 1 --pretty=format:%H
[  +12 ms] Exit code 0 from: git log -n 1 --pretty=format:%H
[        ] 15e51a9e3ed59b70605629b8bab1106b22354472
[        ] [/Users/jeffa/Documents/flutter/] git log -n 1 --pretty=format:%ar
[   +7 ms] Exit code 0 from: git log -n 1 --pretty=format:%ar
[        ] 17 hours ago
[  +50 ms] [1m[‚úì] Flutter (on Mac OS X 10.12.3 16D32, channel master)[0m
[        ] [1m    ‚Ä¢ Flutter at /Users/jeffa/Documents/flutter[0m
[        ] [1m    ‚Ä¢ Framework revision 15e51a9e3e (17 hours ago), 2017-03-22 01:42:40[0m
[        ] [1m    ‚Ä¢ Engine revision 6b9eda4a40[0m
[        ] [1m    ‚Ä¢ Tools Dart version 1.23.0-dev.9.0[0m
[  +28 ms] [1m[‚úì] Host Executable Compatibility[0m
[        ] [1m    ‚Ä¢ Downloaded executables execute on host[0m
[   +2 ms] /usr/libexec/java_home
[  +30 ms] Exit code 0 from: /usr/libexec/java_home
[   +1 ms] java -version
[[1m +288 ms[0m] [1m[‚úì] Android toolchain - develop for Android devices (Android SDK 25.0.2)[0m
[        ] [1m    ‚Ä¢ Android SDK at /Users/jeffa/Library/Android/sdk[0m
[        ] [1m    ‚Ä¢ Platform android-25, build-tools 25.0.2[0m
[        ] [1m    ‚Ä¢ Java binary at: /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/bin/java[0m
[        ] [1m    ‚Ä¢ Java version: Java(TM) SE Runtime Environment (build 1.8.0_77-b03)[0m
[   +2 ms] xcode-select --print-path
[   +7 ms] Exit code 0 from: xcode-select --print-path
[        ] /Applications/Xcode.app/Contents/Developer
[        ] xcodebuild -version
[  +81 ms] Exit code 0 from: xcodebuild -version
[        ] Xcode 8.2.1
           Build version 8C1002
[        ] xcrun clang
[  +12 ms] python -c import six
[  +99 ms] ideviceinstaller -h
[  +11 ms] ios-deploy --version
[  +17 ms] ios-deploy --version
[  +10 ms] Exit code 0 from: ios-deploy --version
[        ] 1.9.1
[        ] idevice_id -h
[   +6 ms] ios-deploy --version
[   +9 ms] ios-deploy --version
[   +8 ms] Exit code 0 from: ios-deploy --version
[        ] 1.9.1
[   +1 ms] idevice_id -l
[  +15 ms] 3d8b0e4ef50ee06b16f82dbef3f7c8af20df310a
[        ] ideviceName
[[1m +103 ms[0m] pod --version
[[1m +429 ms[0m] pod --version
[[1m +421 ms[0m] Exit code 0 from: pod --version
[        ] 1.2.0
[        ] pod --version
[[1m +413 ms[0m] Exit code 0 from: pod --version
[        ] 1.2.0
[        ] [1m[‚úì] iOS toolchain - develop for iOS devices (Xcode 8.2.1)[0m
[        ] [1m    ‚Ä¢ Xcode at /Applications/Xcode.app/Contents/Developer[0m
[        ] [1m    ‚Ä¢ Xcode 8.2.1, Build version 8C1002[0m
[        ] [1m    ‚Ä¢ ios-deploy 1.9.1[0m
[        ] [1m    ‚Ä¢ CocoaPods version 1.2.0[0m
[   +1 ms] [1m[‚úì] Android Studio (version 2.3)[0m
[        ] [1m    ‚Ä¢ Android Studio at /Applications/Android Studio.app/Contents[0m
[        ] [1m    ‚Ä¢ Gradle version 3.2[0m
[   +3 ms] /Users/jeffa/Library/Android/sdk/platform-tools/adb devices -l
[  +14 ms] Exit code 0 from: /Users/jeffa/Library/Android/sdk/platform-tools/adb devices -l
[        ] List of devices attached
[  +16 ms] idevice_id -h
[   +6 ms] which idevice_id
[   +4 ms] Exit code 0 from: which idevice_id
[        ] /usr/local/bin/idevice_id
[        ] /usr/local/bin/idevice_id -l
[   +6 ms] Exit code 0 from: /usr/local/bin/idevice_id -l
[        ] 3d8b0e4ef50ee06b16f82dbef3f7c8af20df310a
[        ] which ideviceinfo
[   +3 ms] Exit code 0 from: which ideviceinfo
[        ] /usr/local/bin/ideviceinfo
[        ] /usr/local/bin/ideviceinfo -k DeviceName -u 3d8b0e4ef50ee06b16f82dbef3f7c8af20df310a
[  +91 ms] Exit code 0 from: /usr/local/bin/ideviceinfo -k DeviceName -u 3d8b0e4ef50ee06b16f82dbef3f7c8af20df310a
[        ] JPHONE
[        ] which ideviceinstaller
[   +4 ms] Exit code 0 from: which ideviceinstaller
[        ] /usr/local/bin/ideviceinstaller
[        ] which idevice_id
[   +3 ms] Exit code 0 from: which idevice_id
[        ] /usr/local/bin/idevice_id
[        ] which ideviceinfo
[   +3 ms] Exit code 0 from: which ideviceinfo
[        ] /usr/local/bin/ideviceinfo
[        ] which iproxy
[   +3 ms] Exit code 0 from: which iproxy
[        ] /usr/local/bin/iproxy
[        ] which idevicedebug
[   +3 ms] Exit code 0 from: which idevicedebug
[        ] /usr/local/bin/idevicedebug
[        ] which idevicesyslog
[   +3 ms] Exit code 0 from: which idevicesyslog
[        ] /usr/local/bin/idevicesyslog
[        ] which idevicescreenshot
[   +4 ms] Exit code 0 from: which idevicescreenshot
[        ] /usr/local/bin/idevicescreenshot
[        ] which ios-deploy
[   +4 ms] Exit code 0 from: which ios-deploy
[        ] /usr/local/bin/ios-deploy
[   +2 ms] /usr/bin/xcrun simctl list --json devices
[[1m +106 ms[0m] which ideviceinfo
[   +4 ms] Exit code 0 from: which ideviceinfo
[        ] /usr/local/bin/ideviceinfo
[        ] /usr/local/bin/ideviceinfo -k ProductVersion -u 3d8b0e4ef50ee06b16f82dbef3f7c8af20df310a
[  +51 ms] Exit code 0 from: /usr/local/bin/ideviceinfo -k ProductVersion -u 3d8b0e4ef50ee06b16f82dbef3f7c8af20df310a
[        ] 10.2.1
[        ] which ideviceinfo
[   +4 ms] Exit code 0 from: which ideviceinfo
[        ] /usr/local/bin/ideviceinfo
[        ] /usr/local/bin/ideviceinfo -k BuildVersion -u 3d8b0e4ef50ee06b16f82dbef3f7c8af20df310a
[  +46 ms] Exit code 0 from: /usr/local/bin/ideviceinfo -k BuildVersion -u 3d8b0e4ef50ee06b16f82dbef3f7c8af20df310a
[        ] 14D27
[   +2 ms] [1m[‚úì] Connected devices[0m
[        ] [1m    ‚Ä¢ JPHONE   ‚Ä¢ 3d8b0e4ef50ee06b16f82dbef3f7c8af20df310a ‚Ä¢ ios ‚Ä¢ iOS 10.2.1 (14D27)[0m
[        ] [1m    ‚Ä¢ iPhone 6 ‚Ä¢ 19D068F4-F0DA-4F31-8FA3-A52546429DB1     ‚Ä¢ ios ‚Ä¢ iOS 10.2 (simulator)[0m
[        ] 'flutter doctor' took 2765ms.
[[1m +260 ms[0m] ensureAnalyticsSent: 258ms
[   +2 ms] exiting with code 0

```

myapp $ flutter analyze
Analyzing lib/main.dart...
No analyzer warnings! (ran in 6.0s)