https://developers.google.com/j2objc 官网

Building J2ObjC

bookmark_border

Requirements

Apple Mac OS X system
Latest version of Xcode
JDK 1.8 and JDK 11 installed
Apache Maven

(Recommended but not required) Google Protocol Buffer source
Note: Maven is no longer distributed with Xcode’s command-line tools. Here is a well-written installation guide by Pankaj Kumar.

Mac Setup

Install Xcode command line tools by running:

sudo xcode-select --install

Add to your .bash_profile:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

https://www.jianshu.com/p/14f98f4a5667
Mac下配置.bash_profile(环境变量)

下载java jdk 1.8
https://www.jianshu.com/p/a85658902f26
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home
*路径复制 option+command+c

Create a Fork of the J2ObjC project
To fork the J2ObjC project, open its main page and click the Fork button:

List item

Fork

Select your GitHub account name, and the fork will be created in a few seconds.

Next, clone a copy of your fork to your local system for development. First, click the [Clone or download button], then click the Copy to Clipboard button:

Clone

Then clone into a local directory:

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

Install protobuf

You need to have protobuf C++ installed before you can build J2ObjC. The current version is 3.11.1.

https://www.jianshu.com/p/de6f1d2d37bf
安装homebrew

To install the protobuf binary package, use Homebrew:

brew install protobuf@3.11.1

You need to set PROTOBUF_ROOT_DIR to the root where protobuf is installed. Normally, that’s the Homebrew default /usr/local. Add the following to your .bash_profile:

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

To verify, run $PROTOBUF_ROOT_DIR/bin/protoc --version.

按这个来会有问题,所以没按这个来,直接
brew install protobuf
export PROTOBUF_ROOT_DIR=/usr/local # or your custom Homebrew dir一直有问题
但是protoc --version 是没问题的,所以就继续了

Building J2ObjC

To build from a command-line in a Terminal window, run:

#Build just the translator and libraries

make dist

> 出问题,没有下maven
> `brew install maven`

#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

Optional Setup for Protocol Buffers
The J2ObjC Protocol Buffers compiler and runtime requires that Protocol Buffers 3.11.1 be installed:

Download the source code from the Protocol Buffers 3.11.1 release.
Follow the C++ installation instructions from the README. Pay attention to the --prefix option to specify your install location.
Define the PROTOBUF_ROOT_DIR environment variable to point to your Protocol Buffers install location.
Post Java 8 language features.
See announcement. In addition to the steps in the previous section, a JRE module needs to be built with the JDK 11:

JAVA_HOME=/usr/libexec/java_home -v 11
make -C jre_emul/ -f java.mk emul_module_dist
Testing J2ObjC
To test from a command-line in a Terminal window, run:

Run translator and library unit tests

make test

Run all unit tests, including for protocol buffers

make test_all
Cleaning/Resetting a Build

Remove all files generated by the build

make clean
Parallel Builds
The J2ObjC build supports parallel builds, which are specified using the -j flag, where n is the maximum number of concurrent tasks. The maximum depends on how fast/powerful your system is; we suggest starting with -j4. Increase the number to shorten build times if your system can handle it, and decrease it if make fails with system errors.

Building Processor Architectures
As of j2objc release 2.3, 32-bit iOS architectures (“iphone” and “simulator”) are not included in the public distribution. You can build j2objc with these by first specifying the J2OBJC_ARCHS environment variable:

$ export J2OBJC_ARCHS=“iphone simulator macosx iphone64 watchv7k watch64 watchsimulator simulator64”
$ make -j8 all_dist
This can also be used to speed up the build, by only specifying the architectures your app needs. To only build the 64-bit iOS (“iphone64”) and its associated simulator (“simulator64”), for example, define J2OBJC_ARCHS=“iphone64 simulator64” before running make.

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐