xcode 使用 Cordova CLI 构建的 iOS 应用程序打包和签名时遇到问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22639577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:48:48  来源:igfitidea点击:

Trouble packaging and signing iOS apps built with Cordova CLI

xcodecordovacordova-plugins

提问by Adam Tuttle

Until now, all of my experience compiling PhoneGap apps has been via the excellent PhoneGap:Buildservice. However, I now find myself in a situation where I need to compile locally, because I need to use a plugin that includes a binary file, which precludes it from being included for use with PG:B.

到目前为止,我编译 PhoneGap 应用程序的所有经验都是通过出色的PhoneGap:Build服务获得的。但是,我现在发现自己处于需要在本地编译的情况,因为我需要使用一个包含二进制文件的插件,这使得它无法与 PG:B 一起使用

So for these reasons, I need to compile locally. "Great!" I thought, I'll just use the new CLI...

所以出于这些原因,我需要在本地编译。“伟大的!” 我想,我只会使用新的 CLI ......

I have developed my app, and I can test it on-device via deploy over USB from Xcode, but trying to get a release build, and sign it, with the provisioning profile embedded, has been a nightmare.

我已经开发了我的应用程序,我可以通过从 Xcode 通过 USB 部署在设备上测试它,但是试图获得一个发布版本,并在嵌入的配置文件的情况下对其进行签名,一直是一场噩梦。

For completeness, this is the basic outline of everything I've done, aside from the app development itself.

为了完整起见,这是我所做的一切的基本大纲,除了应用程序开发本身。

$ pwd
 /users/adam/dev/myapp/mobile/
$ cordova create build_local com.foo.bar MyApp
 Creating a new cordova project with name "MyApp" and id "com.foo.bar" at location "/Users/adam/DEV/myapp/build_local"
$ cd build_local
$ cordova platform add ios
 Creating ios project...
$ cordova platform add android
 Creating android project...
 Creating Cordova project for the Android platform:
    Path: platforms/android
    Package: com.foo.bar
    Name: MyApp
    Android target: android-19
 Copying template files...
 <snip>
 Project successfully created.
$ cordova plugin add https://github.com/hazemhagrass/BackgroundJS
 Fetching plugin "https://github.com/hazemhagrass/BackgroundJS" via git clone
 Installing com.badrit.BackgroundJS (android)
 Fetching plugin "https://github.com/apache/cordova-plugin-device.git" via git clone
 Installing org.apache.cordova.device (android)
 Installing com.badrit.BackgroundJS (ios)
 Installing org.apache.cordova.device (ios)
$ cordova plugin add de.appplant.cordova.plugin.local-notification
 Fetching plugin "de.appplant.cordova.plugin.local-notification" via plugin registry
 Installing de.appplant.cordova.plugin.local-notification (android)
 Installing de.appplant.cordova.plugin.local-notification (ios)
$ cordova plugin add https://github.com/kdzwinel/phonegap-estimotebeacons
 Fetching plugin "https://github.com/kdzwinel/phonegap-estimotebeacons" via git clone
 Installing pl.makingwaves.estimotebeacons (android)
 Installing pl.makingwaves.estimotebeacons (ios)

For what it's worth, this last plugin is the reason that I have to compile locally.

就其价值而言,最后一个插件是我必须在本地编译的原因。

Now, here's one other potential monkey wrench: This app is actually two apps. It's the same core codebase, merged into two different deployment branches of the repo, one for each client. So each app will have its own id, name, and config stuff. Because of this, I actually have more than one cordova project folder(1 for each final app) and after creating each project through the steps above, I remove the generated wwwfolder and replace it with a symlink to the shared www folder that exists outside of these phonegap project directories.

现在,这是另一个潜在的猴子扳手:这个应用程序实际上是两个应用程序。它是相同的核心代码库,合并到 repo 的两个不同部署分支中,每个客户端一个。所以每个应用程序都有自己的 id、名称和配置内容。因此,我实际上有多个cordova项目文件夹(每个最终应用程序1个),在通过上述步骤创建每个项目后,我删除了生成的www文件夹并将其替换为指向共享www文件夹之外的符号链接这些 phonegap 项目目录。

This is supported behavior; the CLI allows you to generate your app with a symlink via the --link-toflag (see cordova help createfor details). However, doing so seems to have issues; so I've resorted to doing all of the app config up front and then replacing the generated wwwfolder with a symlink after everything is ready to compile.

这是受支持的行为;CLI 允许您通过--link-to标志生成带有符号链接的应用程序(请参阅cordova help create有关详细信息)。但是,这样做似乎有问题;所以我采取了预先完成所有应用程序配置,然后www在一切准备好编译后用符号链接替换生成的文件夹。

At this point, I can deploy to either the iOS simulator or Android emulator, and I can deploy to devices over USB, and everything works just fine; all of my plugins are available and function as expected. So I'm ready to compile a release build. Android is easy. iOS, not so much.

此时,我可以部署到iOS模拟器或Android模拟器,也可以通过USB部署到设备,一切正常;我的所有插件都可用并且按预期运行。所以我准备编译一个发布版本。安卓很简单。iOS,没那么多。

$ cordova build ios
 <snip>
 ** BUILD SUCCEEDED **

However, this is a DEV build. The generated file is in the build/emulator/folder, and when I attempt to sign it, I'm told that it's not signed because of the I386 architecture (which indicates that it's a development build).

但是,这是一个 DEV 版本。生成的文件在build/emulator/文件夹中,当我尝试对其进行签名时,我被告知由于 I386 架构(这表明它是一个开发版本)而未签名。

$ xcrun -sdk iphoneos PackageApplication -v "platforms/ios/build/emulator/MyApp.app" -o "/users/adam/dev/myapp/MyApp.ipa" --sign "iPhone Distribution: {our cert name} ({our cert id})"
 <snip>
 Codesign check fails : platforms/ios/build/emulator/MyApp.app: code object is not signed at all
 In architecture: i386
 <snip>

I've attempted to generate a release build from the cordova CLI. I haven't been able to find the --releaseflag documented anywhere, but the CLI doesn't complain, and it usually does if it doesn't recognize a flag.

我试图从cordova CLI 生成一个发布版本。我无法在--release任何地方找到记录的标志,但 CLI 不会抱怨,如果它不能识别标志,它通常会抱怨。

$ cordova build ios --release
 <same result as previously>

Attempting to sign this build results in the same problem.

尝试签署此版本会导致同样的问题。



At this point, I started attempting to work directly in Xcode. I've set the .mobileprovisionfile and the signing credentials up appropriately, to the best of my knowledge:

此时,我开始尝试直接在 Xcode 中工作。据.mobileprovision我所知,我已经适当地设置了文件和签名凭据:

screenshot of signing and provisioning profile settings

签名和配置文件设置的屏幕截图

With these values set, Xcode no longer allows me to build:

设置这些值后,Xcode 不再允许我构建:

screenshot of build menu disabled

禁用构建菜单的屏幕截图

So I'm stuck: I have no choice but to build locally, and I can't figure out how to get it to build for release and sign! Please help!

所以我被困住了:我别无选择,只能在本地构建,而且我不知道如何让它构建以供发布和签名!请帮忙!



Additionally, if I attempt to embed a provisioning profile, that fails because of an issue with entitlements. I'm not exactly sure what this means, but I'm hopeful that it's a result of working with a dev build, and resolving that will resolve this as well.

此外,如果我尝试嵌入配置文件,则会由于权利问题而失败。我不确定这意味着什么,但我希望这是使用开发构建的结果,并且解决这个问题也能解决这个问题。

$ test -e ~/.ios/DEV.mobileprovision && echo exists
 exists
$ xcrun -sdk iphoneos PackageApplication -v "platforms/ios/build/emulator/MyApp.app" -o "/users/adam/dev/myapp/MyApp.ipa" --embed "~/.ios/DEV.mobileprovision"
 <snip>
 error: Failed to read entitlements from '/var/folders/zs/j2hmt69n12sbjm6gyn0m_q4c0000gn/T/tyYvYPQKf3/Payload/MyApp.app'


Update 1:

更新 1:

This SO questionhelped in one regard. I don't know how the active scheme (I'm not really sure what that means, but that's the tooltip when I hover over the control) got changed as part of specifying keys/etc, but clearly it did. Changing this back to an iOS Device, like iPhone, allows me to build my project, and even Archive(which, to the best of my understanding, means it's creating the .ipafile I need to submit to the app store), but I can't find the archived file. Where should it be? Can I define this in a setting somewhere in Xcode?

这个问题在一方面有帮助。我不知道活动方案(我不确定这意味着什么,但这是我将鼠标悬停在控件上时的工具提示)如何作为指定键/等的一部分而改变,但显然它确实如此。将其改回 iOS 设备,如 iPhone,允许我构建我的项目,甚至存档(据我所知,这意味着它正在创建我需要提交给应用程序商店的.ipa文件),但我找不到存档文件。它应该在哪里?我可以在 Xcode 某处的设置中定义它吗?

Update 2:

更新 2:

By fiddling with certificates and provisioning profiles I've finally been able to create an archive from Xcode, which I've been told is a release build (is it?). Ideally I would like to be able to build from the command line so that I can automate it as much as possible, so that's where I'll be picking up in the morning. Any advice on that front would be quite welcome!

通过摆弄证书和配置文件,我终于能够从 Xcode 创建一个存档,我被告知这是一个发布版本(是吗?)。理想情况下,我希望能够从命令行进行构建,这样我就可以尽可能地自动化它,这就是我早上要去的地方。任何关于这方面的建议将非常受欢迎!

回答by Nacho Marín

If you managed to create an archive in Xcode, then your signing certificate and provisioning profiles are known to Xcode, so cordova build ios --release --deviceshould make it.

如果您设法在 Xcode 中创建了一个存档,那么您的签名证书和配置文件对于 Xcode 是已知的,因此应该使用cordova build ios --release --device

The steps are:

步骤是:

1) Import your iOS developer certificate for production to the keychain by downloading and double clicking on it in Finder (or get it via Xcode)

1) 通过在 Finder 中下载并双击它(或通过 Xcode 获取),将用于生产的 iOS 开发人员证书导入到钥匙串

2) Download your provisioning profile (with the App ID set to the id attribute of the widget element in config.xml) and double click it on Finder so it goes to the Xcode provisioning profile store

2) 下载您的配置文件(将 App ID 设置为 config.xml 中小部件元素的 id 属性)并在 Finder 上双击它,以便它转到 Xcode 配置文件商店

3) cordova build ios --release --device

3) 科尔多瓦构建 ios --release --device

回答by Eddy Verbruggen

it looks like you're trying to sign the app with a wildcard provisioning profile (the XCode screenshot). Can you try creating and downloading a distribution certificate and provprofile to your Mac? Then import the .cer file in the keychain access app (doubleclicking should suffice) and doubleclick the provprofile as well.

看起来您正在尝试使用通配符配置文件(XCode 屏幕截图)对应用程序进行签名。您可以尝试创建分发证书和 provprofile 并将其下载到您的 Mac 上吗?然后在钥匙串访问应用程序中导入 .cer 文件(双击就足够了)并双击 provprofile。

Now you should be able to select the appropriate values from the release dropdowns in the XCode build settings.

现在您应该能够从 XCode 构建设置的发布下拉列表中选择适当的值。

Hope this helps somewhat... Eddy

希望这会有所帮助... Eddy

回答by whodeee

One other issue I am seeing from your screenshot is I don't think you can Build an Archive (Release) version using the Developer Signing Idenetity, you would need to create a Distribution certificate and use that one for the Release (Archive) version.

我从您的屏幕截图中看到的另一个问题是,我认为您无法使用 Developer Signing Idenetity 构建存档(发布)版本,您需要创建一个分发证书并将该证书用于发布(存档)版本。