简体   繁体   English

单个应用程序二进制文件如何支持64位和32位应用程序

[英]How Single App Binary Supports 64-bit and 32-bit Apps

We can see apple announcement here. 我们可以在这里看到苹果公告 . According to this doc, we can submit same binary with supporting 32-bit and also 64-bit. 根据这个文档,我们可以提交相同的二进制文件,支持32位和64位。 I found one stack overflow answer here . 我发现这里有一个堆栈溢出答案。 But According to this answer, we should set deployment target as IO7+ . 但根据这个答案,我们shoulddeployment target as IO7+设置deployment target as IO7+ But apple doc said, you can submit this with IOS 7 and IOS 6 support? 但是苹果医生说,您可以通过IOS 7和IOS 6支持提交吗? My question is, How can we generate binary with supporting 32-bit and 64-bit by deployment target IOS6+? 我的问题是, 如何通过部署目标IOS6 +生成支持32位和64位的二进制文件?

Note: I'm using xcode 5.0 注意:我正在使用xcode 5.0

Update: Question above is fixed by using xcode 5.0.2 . 更新: Question above is fixed by using xcode 5.0.2 But I get confused how can I make code for 32-bit as well 64-bit. 但我很困惑如何为32位以及64位编写代码。 I know one thing, we must do code for two separately in some times. 我知道一件事,我们必须在某些时候分别做两个代码。 But How can I do? 但是How can I do? . for example, if one method in deprecated in ios6 means, we provide code for ios 6 and ios7 also. 例如,如果在ios6中不推荐使用一种方法,我们也为ios 6和ios7提供代码。 In same case also followed here or do some other technic for this. 在同样的情况下也遵循这里或为此做一些其他技术。

Xcode can build your app with both 32-bit and 64-bit binaries included so it works across all devices running iOS 7. If you wish to continue to support iOS 6 then you will need to build for 32-bit only. Xcode可以构建包含32位和64位二进制文​​件的应用程序,因此它适用于运行iOS 7的所有设备。如果您希望继续支持iOS 6,那么您将需要仅为32位构建。 Next month we will be making changes that will allow you create a single app binary that supports 32-bit on iOS 6, as well as 32-bit and 64-bit on iOS 7. 下个月我们将进行更改,允许您创建单个应用程序二进制文件,支持iOS 6上的32位,以及iOS 7上的32位和64位。

Converting Your App to a 64-Bit Binary 将您的应用程序转换为64位二进制文​​件

At a high level, here are the steps to create an app that targets both the 32-bit and the 64-bit runtime environments: 在较高的层次上,以下是创建针对32位和64位运行时环境的应用程序的步骤:

1.Install Xcode 5.0.1. 1.安装Xcode 5.0.1。

2.Open your project. 2.打开你的项目。 Xcode prompts you to modernize your project. Xcode会提示您使项目现代化。 Modernizing the project adds new warnings and errors that are important when compiling your app for 64-bit. 现代化项目会在编译64位应用程序时添加新的警告和错误。

3.Update your project settings to support iOS 5.1.1 or later. 3.更新项目设置以支持iOS 5.1.1或更高版本。 You can't build a 64-bit project if it targets an iOS version earlier than iOS 5.1. 如果它针对早于iOS 5.1的iOS版本,则无法构建64位项目。

4.Change the Architectures build setting in your project to “Standard Architectures (including 64-bit).” 4.将项目中的体系结构构建设置更改为“标准体系结构(包括64位)”。

5.Update your app to support the 64-bit runtime environment. 5.更新您的应用程序以支持64位运行时环境。 The new compiler warnings and errors will help guide you through this process. 新的编译器警告和错误将指导您完成此过程。 However, the compiler doesn't do all of the work for you; 但是,编译器不会为您完成所有工作; use the information in this document to help guide you through investigating your own code. 使用本文档中的信息来指导您调查自己的代码。

6.Test your app on actual 64-bit hardware. 6.在实际的64位硬件上测试您的应用程序。 iOS Simulator can also be helpful during development, but some changes, such as the function calling conventions, are visible only when your app is running on a device. iOS模拟器在开发过程中也很有用,但只有当您的应用程序在设备上运行时,某些更改(例如函数调用约定)才可见。

7.Use Instruments to tune your app's memory performance. 7.使用Instruments调整应用程序的内存性能。

8.Submit an app that includes both architectures for approval. 8.提交包含两种架构以供批准的应用程序。

The remainder of this chapter describes problems that frequently occur when porting a Cocoa Touch app to the 64-bit runtime environment. 本章的其余部分描述了将Cocoa Touch应用程序移植到64位运行时环境时经常出现的问题。 Use these sections to guide your own efforts to investigate your code. 使用这些部分来指导您自己调查代码的工作。

From https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaTouch64BitGuide/ConvertingYourAppto64-Bit/ConvertingYourAppto64-Bit.html#//apple_ref/doc/uid/TP40013501-CH3-SW1 来自https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaTouch64BitGuide/ConvertingYourAppto64-Bit/ConvertingYourAppto64-Bit.html#//apple_ref/doc/uid/TP40013501-CH3-SW1

iOS apps rely on a low-level application binary interface and coding conventions established by the Objective-C language and the system frameworks. iOS应用程序依赖于Objective-C语言和系统框架建立的低级应用程序二进制接口和编码约定。 Starting with iOS 7, some iOS devices use 64-bit processors and offer both a 32-bit and a 64-bit runtime environment. 从iOS 7开始,一些iOS设备使用64位处理器,并提供32位和64位运行时环境。 For most apps, the 64-bit runtime environment differs from the 32-bit runtime environment in two significant ways: 对于大多数应用程序,64位运行时环境与32位运行时环境的区别在于两个重要方面:

In the 64-bit runtime, many data types used by Cocoa Touch frameworks (as well as the Objective-C language itself) have increased in size or have stricter memory alignment rules. 在64位运行时中,Cocoa Touch框架使用的许多数据类型(以及Objective-C语言本身)已经增加了大小或者具有更严格的内存对齐规则。 See “ Changes to Data Types .” The 64-bit runtime requires proper function prototypes to be used when making function calls. 请参阅“ 对数据类型的更改 。”64位运行时需要在进行函数调用时使用正确的函数原型。 See “ Changes to Function Calling .” 请参阅“ 函数调用的更改 ”。

application binary interface (ABI) 应用程序二进制接口(ABI)

Other Changes to the 64-Bit Runtime 64位运行时的其他更改

The 64-bit ARM instruction set is significantly different from the 32-bit instruction set. 64位ARM指令集与32位指令集明显不同。 If your app includes any assembly language code, you need to rewrite it to use the new instruction set. 如果您的应用程序包含任何汇编语言代码,则需要重写它以使用新的指令集。 You also need a more detailed description of the 64-bit calling conventions in iOS, because the conventions do not exactly match the ARM standard. 您还需要更详细地描述iOS中的64位调用约定,因为这些约定与ARM标准不完全匹配。 For more information, see iOS ABI Function Call Guide . 有关更多信息,请参阅iOS ABI函数调用指南

At a high level, to make your code 64-bit clean, you must do the following: 在较高的层次上,为了使您的代码保持64位清洁,您必须执行以下操作:

  1. Avoid assigning 64-bit long integers to 32-bit integers. 避免将64位长整数分配给32位整数。
  2. Avoid assigning 64-bit pointers to 32-bit integers. 避免将64位指针分配给32位整数。
  3. Avoid pointer and long integer truncation during arithmetic operations (or other arithmetic problems caused by the change in integer types). 在算术运算期间避免指针和长整数截断(或由整数类型的变化引起的其他算术问题)。
  4. Fix alignment issues caused by changes in data type sizes. 修复由数据类型大小的更改引起的对齐问题。
  5. Ensure that memory structures that are shared between the 32-bit and 64-bit runtimes share a similar layout. 确保在32位和64位运行时之间共享的内存结构共享相似的布局。
  6. Rewrite any assembly language code so that your code uses the new 64-bit opcodes and runtime. 重写任何汇编语言代码,以便您的代码使用新的64位操作码和运行时。
  7. Avoid casting variadic functions to functions that take a fixed number of parameters, or vice versa. 避免将可变参数函数转换为采用固定数量参数的函数,反之亦然。

At a high level, here are the steps to create an app that targets both the 32-bit and the 64-bit runtime environments: 在较高的层次上,以下是创建针对32位和64位运行时环境的应用程序的步骤:

Install Xcode 5.0.2 (I have done with this only, maybe higher is better) 安装Xcode 5.0.2(我已经完成了这个,也许更高更好)

Open your project. 打开你的项目。 Xcode prompts you to modernize your project. Xcode会提示您使项目现代化。 Modernizing the project adds new warnings and errors that are important when compiling your app for 64-bit. 现代化项目会在编译64位应用程序时添加新的警告和错误。

Update your project settings to support iOS 5.1.1 or later. 更新项目设置以支持iOS 5.1.1或更高版本。 You can't build a 64-bit project if it targets an iOS version earlier than iOS 5.1. 如果它针对早于iOS 5.1的iOS版本,则无法构建64位项目。

Change the Architectures build setting in your project to “Standard Architectures (including 64-bit).” 将项目中的体系结构构建设置更改为“标准体系结构(包括64位)”。

Update your app to support the 64-bit runtime environment. 更新您的应用程序以支持64位运行时环境。 The new compiler warnings and errors will help guide you through this process. 新的编译器警告和错误将指导您完成此过程。 However, the compiler doesn't do all of the work for you; 但是,编译器不会为您完成所有工作; use the information in this document to help guide you through investigating your own code. 使用本文档中的信息来指导您调查自己的代码。

Test your app on actual 64-bit hardware. 在实际的64位硬件上测试您的应用程序。 iOS Simulator can also be helpful during development, but some changes, such as the function calling conventions, are visible only when your app is running on a device. iOS模拟器在开发过程中也很有用,但只有当您的应用程序在设备上运行时,某些更改(例如函数调用约定)才可见。

Use Instruments to tune your app's memory performance. 使用Instruments调整应用程序的内存性能。 Submit an app that includes both architectures for approval. 提交包含两种架构以供批准的应用程序。

The remainder of this chapter describes problems that frequently occur when porting a Cocoa Touch app to the 64-bit runtime environment. 本章的其余部分描述了将Cocoa Touch应用程序移植到64位运行时环境时经常出现的问题。 Use these sections to guide your own efforts to investigate your code. 使用这些部分来指导您自己调查代码的工作。

Follow the guide for supporting the 32 and 64 bit architecture by apple 按照指南通过apple 支持32位和64位架构

The program xcode 5 compiled contained two binary code:32-bit and 64 bit.In the 32-bit system will call the 32-bit code.In the 64-bit system will call the 64-bit code. 编译的程序xcode 5包含两个二进制代码:32位和64位。在32位系统中将调用32位代码。在64位系统中将调用64位代码。 At the same time, think about same program only have 32-bit code, the 64-bit system contained two framework:a 32-bit, a 64-bit.When the 64-bit system running the 32-bit program will call the 32-bit framework for the underlying support, running the 64-bit program will call the 64-bit framework for the underlying support.More detail you can see Apple's official documentation "64-Bit transition Guide for Cocoa Touch". 同时,考虑到同一个程序只有32位代码,64位系统包含两个框架:一个32位,一个64位。当运行32位程序的64位系统将调用底层支持的32位框架,运行64位程序将调用64位框架作为底层支持。更多详细信息,您可以看到Apple的官方文档“Cocoa Touch的64位转换指南”。

Use xcode 5 can be easily compiled program into 64.The basic procedure is as follow. 使用xcode 5可以很容易地将程序编译成64个。基本步骤如下。

  1. Set the support device into 'ios7' 将支持设备设置为'ios7'

  2. The "Architectures" in "Build Setting" changed to "Standard Architectures (including 64-bit)". “构建设置”中的“体系结构”更改为“标准体系结构(包括64位)”。

As for first part of question - Base SDK should be "Latest iOS SDK" which is iOS 7.0. 至于问题的第一部分 - 基础SDK应该是iOS 7.0的“最新iOS SDK”。 Minimum deployment target should be iOS 6.0 or you won't be able to select "Standard architectues including 64-bit(armv7, armv7s, armv8)" for architectures. 最低部署目标应该是iOS 6.0,否则您将无法为体系结构选择“标准体系结构,包括64位(armv7,armv7s,armv8)”。 After you select these settings your app will be built for either 32 bit and 64 bit. 选择这些设置后,您的应用程序将构建为32位和64位。

As for update - after switching to 32/64bit archs, analyze your project and fix new warnings that can appear. 至于更新 - 切换到32 / 64bit拱后,分析您的项目并修复可能出现的新警告。 Then test your app on real 64 bit device(iPhone 5s/iPad Air/iPad mini retina). 然后在真正的64位设备(iPhone 5s / iPad Air / iPad mini retina)上测试您的应用程序。 If your app uses iCloud, test synchronization between 32 and 64 bit devices. 如果您的应用使用iCloud,请测试32位和64位设备之间的同步。 Helpful info is in Apple's guide (summary from there is in @iDev answer). 有用的信息在Apple的指南中 (摘自@iDev答案)。

EDIT 编辑

Actually yes, minimum is 5.1.1, but you should either set it manually or set deployment target lower than 6.0 and when you select architectures to incl. 实际上是,最小值是5.1.1,但您应该手动设置它或将部署目标设置为低于6.0,并选择体系结构为incl。 64bit Xcode will ask you to set it as 5.1.1. 64位Xcode会要求您将其设置为5.1.1。 Anyway I'm not sure why you'd want to support 5.1.1 specifically if you want to use 64bit archs. 无论如何,如果你想使用64位拱门,我不确定你为什么要特别支持5.1.1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM