构建 J2ObjC

要求

  • Apple Mac OS X 系统
  • 最新版本的 Xcode
  • 已安装 JDK JDK 11
  • Apache Maven
  • (建议但不强制要求)Google 协议缓冲区来源

Mac 设置

  • 运行以下命令以安装 Xcode 命令行工具:
sudo xcode-select --install
  • 添加到您的 .bash_profile
export JAVA_HOME=`/usr/libexec/java_home -v 11`

创建 J2ObjC 项目的分支

如需为 J2ObjC 项目创建分支,请打开其主页面,然后点击“创建分支”按钮:

Fork

选择您的 GitHub 账号名称,几秒钟后即可创建分支。

接下来,将分支的副本克隆到本地系统以进行开发。首先,点击 [Clone or download button],然后点击“复制到剪贴板”按钮:

克隆

然后克隆到一个本地目录:

git clone (Command-V)  # Paste the copied URL

安装 protobuf

您需要先安装 protobuf C++,然后才能构建 J2ObjC。

如需安装 protobuf 二进制软件包,请使用 HomeBrer:

brew install protobuf

您需要将 PROTOBUF_ROOT_DIR 设置为安装 protobuf 的根目录。通常,这是 Home 窗口中的默认值 /usr/local。将以下代码添加到 .bash_profile 中:

export PROTOBUF_ROOT_DIR=/usr/local # or your custom Homebrew dir

如需进行验证,请运行 $PROTOBUF_ROOT_DIR/bin/protoc --version

构建 J2ObjC

如需在终端窗口中从命令行构建,请运行以下命令:

# Build just the translator and libraries
make dist

# Build the full distribution (including frameworks)
make frameworks

# Build the protocol buffer compiler and runtime for J2ObjC
make protobuf_dist

# Build everything that is included in the project's distribution bundles
make all_dist

协议缓冲区的可选设置

J2ObjC Protocol Buffers 编译器和运行时要求安装 Protocol Buffer(至少 3.21.3):

  • Protocol Buffers 3.21.7 版本下载源代码。
  • 按照 README 中的 C++ 安装说明进行操作。请注意用于指定安装位置的 --prefix 选项。
  • PROTOBUF_ROOT_DIR 环境变量定义为指向 Protocol Buffers 安装位置。

发布 Java 8 语言功能。

请参阅公告。 除了上一部分中的步骤之外,还需要使用 JDK 11 构建 JRE 模块:

JAVA_HOME=`/usr/libexec/java_home -v 11` \
make -C jre_emul/ -f java.mk emul_module_dist

测试 J2ObjC

如需在终端窗口中从命令行进行测试,请运行以下命令:

# Run translator and library unit tests
make test

# Run all unit tests, including for protocol buffers
make test_all

清理/重置 build

# Remove all files generated by the build
make clean

并行构建

J2ObjC build 支持使用 -j<n> 标志指定的并行构建,其中 n 是最大并发任务数。上限取决于您的系统的速度/功能;我们建议从 -j4 开始。如果系统能够处理,请增加此编号以缩短构建时间,如果在系统错误导致构建失败时减少构建时间。

构建处理器架构

从 j2objc 2.3 版开始,公开发行版中不包含 32 位 iOS 架构(“iphone”和“simulator”)。您可以使用以下代码构建 j2objc,只需指定 J2OBJC_ARCHS 环境变量即可:

$ export J2OBJC_ARCHS="iphone simulator macosx iphone64 watchv7k watch64 watchsimulator simulator64"
$ make -j8 all_dist

通过仅指定应用所需的架构,这也可用于加快构建速度。例如,若要仅构建 64 位 iOS(“iphone64”)及其关联的模拟器(“simulator64”),请在运行 make 之前定义 J2OBJC_ARCHS="iphone64 simulator64"