How to build iOS application with supported Architectures 64bit only in Cordova?

Viewed 1191

This article guide to you How to customize building process of Cordova.

My sample for this article focus to building iOS application and How to setting for application to supported Architectures 64bit only in Corodva.

You can add more extended configuration parameters for xcodebuild command via build-release.xcconfig, build-debug.xcconfig files which is Cordova's build core file.

This article guide you to use the Corodova Hook also, and how to use "before_build" hook action to update -xcconfig parameter of xcodebuild command. You can catch up an idea of Cordova Hook and deploy your ideas with other hook actions of Cordova.

I hope this article will help many guys Who work with Cordova framework and want to customize the building processing of Cordova.

[INVESTIGATION]

  • There are configurations in XCode which allow we restrict supported architectures of application. Modify below all settings in Build Settings of Xcode:

    • Architectures
    • Build Actives Architectures Only
    • Valid Architectures
  • The configuration values of supported architecture 64bit of settings as below:

    • Architectures = arm64
    • Build Actives Architectures Only = YES
    • Valid Architectures = arm64
  • Cordova building command have not supported setting of extra configuration. That mean we can not build app with extra configuration of application.

  • Cordova have supported HOOKs mechanism which allow hook to some execution like: build, run, prepare, compile, platform add, platform rm, … So that, we can use hook mechanism to inject our extended process to building process of Cordova.Reference link to http://cordova.apache.org/docs/en/latest/guide/appdev/hooks/index.html

  • Cordova building mechanism use configuration files build-release.xcconfig, build-debug.xcconfig in platforms/ios/cordova/ folder to setting up extra configuration for xcodebuild command. So that, we can use this files for our customization.

    • Reference Cordova building core source: platforms/ios/cordova/lib/build.js
  • The setting of architecture parameters which use for -xcconfig parameter of xcodebuild command:

    • ARCHS stand for Architectures parameter.
    • VALID_ARCHS stand for Valid Architectures parameter.
    • ONLY_ACTIVE_ARCH stand for Build Actives Architectures Only parameter.

[SOLUTION]

  • By use HOOK mechanism:

    • We use "before_build" hook action to inject our extended process before building process started.
    • We create executing job file as *.sh file which use as running script for before_build hook action.
    • We need to add configuration for hook action to config.xml. Add this configuration to /hooks folder: <hook src="hooks/before_build.sh" type="before_build" />
  • By use Corodova's build configuration files:

    • We add our new configuration as we wanted to configuration files(We should keep original setting of genereated content from Cordova).
    • Add below settings for supported architectures 64 bits in block of #include "build.xcconfig" and #include "build-extras.xcconfig".

The sample content of build-release.xcconfig file:

#include "build.xcconfig"

CODE_SIGN_IDENTITY = iPhone Distribution
CODE_SIGN_IDENTITY[sdk=iphoneos*] = iPhone Distribution
ONLY_ACTIVE_ARCH = YES
ARCHS = arm64
VALID_ARCHS = arm64

#include "build-extras.xcconfig"

Please note that, we add below configuration for Architectures 64bit supported:

ONLY_ACTIVE_ARCH = YES
ARCHS = arm64
VALID_ARCHS = arm64

Note: The setting of CODE_SIGN_IDENTITY above depend your signing provision profile. In my case is iPhone Distribution.

  • Create executing job file in shell script *.sh
    • Main idea is overwriting our customize build configuration files to original build configuration files of Corodva in platforms/ios/cordova/ folder.
    • You could store your new build configuration files anywhere- it should be store in hooks for easy maintain. I store the build configuration files in hooks/build/ios/ folder.

The content of shell script before_build.sh:

#!/usr/bin/env bash

#Overwrite the configurations files of Cordova    
cp "hooks/build/ios/build-debug.xcconfig" "platforms/ios/cordova/";
cp "hooks/build/ios/build-release.xcconfig" "platforms/ios/cordova/";
  • Execute build app via Cordova's build command: cordova build ios -device

===

Thank you,

DQ.

0 Answers
Related