MultiBranding相同的源代码而不使用xcode

时间:2016-07-14 10:13:04

标签: ios jenkins build branding

我有一个应用程序,我想把它标记为3个不同的用户界面。

我不想直接使用 Xcode

到目前为止,我发现有很多解决方案可以创建不同的目标并拖放图像

但我打算在Xcode之外做这个品牌推广工作

帮帮我吧!

1 个答案:

答案 0 :(得分:2)

现在我们可以在不打开Xcode的情况下构建代码

<强>品牌 UI,构建设置和功能

  • UI
    • App icon&amp;其他图标
    • iTunes Artwork
  • 构建设置
    • 应用名称
    • 捆绑标识符
    • 供应资料
    • 代码签名身份
  • 功能
    • 品牌特定网址(登录,退出,资源获取等...)

使用终端

Branding.sh

   #Author: Durai Amuthan(h.duraiamuthan@gmail.com)
#This is to achieve multiple branding of an iOS app by configuring the variables below

#************ Configuring the brand starts ************

#Directory path where .xcworkspace or .xcodeproj exists
PathOfProjectDirectory=/Users/Shared/Jenkins/Documents/JenkinsTestNuu/New/

#Path where info.plist exists
PathOfInfoPlist=$PathOfProjectDirectory/XxYyZz

#Path to icons where new iTunesArtwork and application icon exixts
#Note: Make sure proper naming conventions of file has been followed
PathOfNewIcons=/Users/Shared/Jenkins/Documents/icons-two

#Path to asset resource where you have kept your application icon.
PathOfAppIconSet=$PathOfProjectDirectory/XxYyZz/Icon.xcassets/AppIcon.appiconset

#Path where do you want the .app file has to be kept
PathToApp=/Users/Shared/Jenkins/Documents/JenkinsTestNuu/app

#Path where do you want the .ipa file has to kept
PathToIpa=/Users/Shared/Jenkins/Documents/JenkinsTestNuu/ipa

#Cocoapods project or project that involves more than one modules are scheme based
isWorkspaceBased=true

#Path of the Project (.xcodeproj) - applicable for workspace(.xcworkspace) based project
PathofProjectFile=$PathOfProjectDirectory/XxYyZz.xcodeproj

#Path of the Workspace (.xcworkspace)
PathofWorkspaceFile=$PathOfProjectDirectory/XxYyZz.xcworkspace

#Name of the target - applicable only for non-workspace(.xcodeproj)  based projects
Target=XxYyZz

#Scheme of the iOS app
Scheme=XxYyZz

#To ascertain Cocoapods has been used or not
isCocoaPodsBased=true

#Configuration of the app (Debug -(Development) or Release(Adhoc or Distribution))
Config=Release

#For giving access to signing idetity found in KeyChain
LoginKeychainPath=/Users/Shared/Jenkins/Library/Keychains/login.keychain
LoginKeyChainPassword=xxyyzz

#Name of the code signing identity.You can find the name in Keychain or xcode build setting
CodeSigningIdentity='iPhone Distribution: Xx Yy Zz Limited (3Z5MHUYJ2L)'

#Path of the provisioning profile
PathToMobileProvision=/Users/Shared/Jenkins/Desktop/BrandingTest.mobileprovision

#UUID value found inside Provisioning profile has to be given
#Do not forget to install provisiong profile in the system
ProvisioningProfileIdentity=6e6506e9-8233-4886-9084-zf21e8f8bbae

#Bundle identifier of the app
BundleIdentifier=com.xxyy.zz

#AppVersion of the app
AppVersion=2.2.2

#App Name
Appname=Two

#************ Configuring the brand ends ************

#** Creatting the build based on configuration starts **

cd $PathOfInfoPlist
echo "****************** Setting App Name ******************"
/usr/libexec/PlistBuddy -c "Set :CFBundleName $Appname" info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName $Appname" info.plist
echo "app name has been set as $Appname"

cd $PathOfProjectDirectory
echo "****************** Setting AppVersion ******************"
/usr/bin/agvtool new-marketing-AppVersion $AppVersion
/usr/bin/agvtool new-AppVersion -all $AppVersion

echo "****************** Changing app icons & iTunes Artwork ******************"
cp -R $PathOfNewIcons/*.png $PathOfAppIconSet
echo "App icons has been changed at $PathOfNewIcons"
cp -R $PathOfNewIcons/iTunesArtwork@2x $PathOfProjectDirectory/XxYyZz
cp -R $PathOfNewIcons/iTunesArtwork $PathOfProjectDirectory/XxYyZz
echo "iTunesArtwork has been changed at $PathOfProjectDirectory"

#Unlock login keychain
security unlock-keychain -p $LoginKeyChainPassword $LoginKeychainPath
if $isCocoaPodsBased == 'true'
then
echo "****************** Installing Cocoapods **********************"
/usr/local/bin/pod install
echo "Cocoapods has been installed"
fi

echo "****************** Creating .app ******************"
if $isWorkspaceBased == 'true'
then
/usr/bin/xcodebuild -scheme $Scheme -workspace $PathofWorkspaceFile -configuration $Config clean build CONFIGURATION_BUILD_DIR=$PathToApp "CODE_SIGN_IDENTITY=$CodeSigningIdentity" "PRODUCT_BUNDLE_IDENTIFIER=$BundleIdentifier" "PROVISIONING_PROFILE=$ProvisioningProfileIdentity"
else
/usr/bin/xcodebuild -target $Target -project $PathofProjectFile -configuration $Config clean build CONFIGURATION_BUILD_DIR=$PathToApp "CODE_SIGN_IDENTITY=$CodeSigningIdentity" "PRODUCT_BUNDLE_IDENTIFIER=$BundleIdentifier" "PROVISIONING_PROFILE=$ProvisioningProfileIdentity"
fi
echo ".app has been generated at $PathToApp"

echo "****************** Creating .ipa *******************"
/usr/bin/xcrun -sdk iphoneos PackageApplication -v $PathToApp/XxYyZz.app -o $PathToIpa/$Appname.ipa --embed $PathToMobileProvision --sign "$CodeSigningIdentity"
echo "$Appname.ipa has been generated at $PathToIpa"

#** Creatting the build based on configuration ends **

该文件具有自我描述性,您可以轻松理解。 只需在文件中配置变量值并按下面的方式调用

sh Branding.sh

<强> 供参考:

如果你想要除了App Icon和iTunesArtwork之外还要更改其他一些图标 使用cp命令,例如

cp path/to/source path/to/destination

要了解更多信息cp man

使用上述文件,您可以执行 UI和构建设置的品牌

对于功能性品牌,您必须保留

  • 品牌特定网址

  • 与品牌相关的其他输入

在单独的plist文件中,以便在构建应用程序时也可以根据各自的品牌更改这些内容

Plist file

在编码方面,您可以自定义您的应用程序,以便像这样读取plist中的值

功能定义:

func getPlistFile()->Dictionary<String,AnyObject>? {
        var dictPlistFile:Dictionary<String,AnyObject>?
        if let path = NSBundle.mainBundle().pathForResource("plistfile", ofType: "plist") {
            if let dictValue = NSDictionary(contentsOfFile: path) as? Dictionary<String, AnyObject> {
                dictPlistFile=dictValue
            }
        }
        return dictPlistFile
    }

函数调用:

var Value=getPlistFile()?["Key"]

您可以在构建应用时使用 PlistBuddy 根据品牌更改密钥的值

这是语法

/usr/libexec/PlistBuddy -c "Set :Key Value" plistfile.plist

使用Jenkins

我们可以在jenkins

中有效地重用shell脚本

1.你必须使用 添加参数 对jenkins中的shell脚本中的所有变量进行参数设置...就像在下面的屏幕截图中我为一个变量做的那样你必须为所有其他人做这件事

Paramterization

2.在 构建步骤

中选择 执行shell

Build Step

3.复制基于配置启动创建构建基于配置结束创建构建之间的脚本并将其粘贴到执行中外壳   Execute Shell

<强> 注意:

  • 资源规则

    在通过非xcode接口构建和打包应用程序时,某些版本中存在关于Xcode的 ResourceRules 的已知错误。

    因此必须运行一次才能停用 xcode 资源规则路径的验证。资源规则路径是不推荐使用的功能和apple 不接受资源规则附带的应用程序但是如果我们在不使用Xcode的情况下构建应用程序,则会出现验证错误,说明尚未找到资源规则以反驳我们必须运行脚本只有一次。

xcode_fix_PackageApplicationResourceRules.sh

#!/bin/sh
# A script to patch xcrun PackageInstallation so that it doesn't use the deprecated --resource-rules
# See "Do not use the --resource-rules flag or ResourceRules.plist. They have been obsoleted and will be rejected."
#   under https://developer.apple.com/library/mac/technotes/tn2206/_index.html#//apple_ref/doc/uid/DTS40007919-CH1-TNTAG205
# Reported as Apple bug #19384243
# 
# should be run as a user who can modify the PackageApplication file

xcodedir=$1

function usage {
        # FIXME we cannot parse args properly because 2 are optional...
        echo "USAGE: $0 xcodedir"
        echo "  xcodedir: an install dir like /Application/Xcode6.1.1.app"
}

if [[ $# -ne 1 ]]; then
        echo "ERROR: invalid number of arguments"
        usage
        exit -1 
fi

pi="$xcodedir/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication"
piorig="$piOrig"

if [[ ! -f "$pi" ]]; then
    echo "$pi file not found. Invalid argument ?"
    usage
    exit -1
fi

grep resource-rules "$pi" 
if [[ $? -ne 0 ]]; then
    echo "PackageApplication doesn't use resource-rules. Skipping"
    exit 0
fi

if [[ -f "$piorig" ]]; then
    echo "Backup file $piorig already exist. Aborting"
    exit -1
fi

perl  -p -i'Orig' -e 'BEGIN{undef $/;} s/,resource-rules(.*sign}).*ResourceRules.plist"/$1/smg' "$pi" 
echo $?
  • 解锁钥匙串

    每当您在终端中运行Branding.sh时,它会提示用户名和密码作为其访问系统密钥链

    每当您在jenkins中运行作业时,您将获得&#34; 不允许用户交互&#34;错误

    所以要解决这个问题,你必须遵循以下步骤

    • 打开钥匙串访问
    • 右键单击私钥
    • 选择&#34;获取信息&#34;
    • 选择&#34;访问控制&#34;标签
    • 点击&#34;允许所有应用程序访问此项目&#34;
    • 点击&#34;保存更改&#34;
    • 输入您的密码
  • 供应资料

    如果您得到&#34; 找不到匹配的配置文件&#34;确保双击并通过Xcode安装它。

    您安装的那一刻,您将在〜/ Library / MobileDevice / Provisioning Profiles /

    中看到 UUID.mobileprovision

    此UUID是移动配置中的值,表示已安装配置文件。

我希望这有助于你