ios - build.xml 中唯一的 Xcode BUILD_PATH 环境变量不可用

标签 ios xcode ant build jenkins

自从使用 CocoaPods 以来,我的 ant 脚本/Jenkins 出现问题(我认为这不是问题的真正原因,它更像是一类问题),这将 Xcode 项目变成了 Xcode 工作区。

我们使用 Jenkins 进行 OTA(无线)分发。

其中有一个作业,它执行一个 ant 脚本。 build.xml 是:

<project name="iOS Compile" default="simulatorbuild" basedir=".">

    <!-- properties --> 
    <property file="default.properties" />

    <property environment="env" />
    <property name="sdk.simulator" value="iphonesimulator${sdk.version}" />
    <property name="sdk.device" value="iphoneos${sdk.version}" />
    <property name="build.dir" location="build"/>

    <!-- clean -->
    <target name="clean">
        <exec executable="xcodebuild" failonerror="true">
            <arg line="clean" />    
        </exec>

        <delete dir="${build.dir}" />
        <mkdir dir="build"/>
    </target>


    <!-- simulator build -->
    <target name="simulatorbuild" depends="clean">
        <exec executable="xcodebuild" failonerror="true">
            <arg line="-sdk ${sdk.simulator}" />
            <arg line="-configuration ${config.simulator}" />       
            <!--<arg line="-target ${target.app}" />-->
            <arg line="-workspace ${app.title}.xcworkspace" />
            <arg line="-scheme ${app.title}" />
        </exec>
    </target>

    <!-- simulator build for code coverage -->
    <target name="-cc_simulatorbuild">
        <exec executable="xcodebuild" failonerror="true">
            <arg line="-sdk ${sdk.simulator}" />
            <arg line="-configuration ${config.simulator}" />       
            <!--<arg line="-target ${target.app}" />-->
            <arg line="-workspace ${app.title}.xcworkspace" />
            <arg line="-scheme ${app.title}" />

            <!-- Changing some project settings to activate code coverage. -->
            <!--<arg line="OTHER_CFLAGS=- -coverage" /> -->

            <arg line="GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES" />
            <arg line="GCC_GENERATE_TEST_COVERAGE_FILES=YES" />
            <!--<arg line="GCC_PRECOMPILE_PREFIX_HEADER=NO" />-->
        </exec>
    </target>

    <!-- device build -->   
    <target name="devicebuild">
        <exec executable="xcodebuild" failonerror="true">
            <arg line="-sdk ${sdk.device}" />
            <arg line="-configuration ${config.device}" />
            <!--<arg line="-target ${target.app}" />-->
            <arg line="-workspace ${app.title}.xcworkspace" />
            <arg line="-scheme ${app.title}" />
        </exec>
    </target>

    <!-- unit tests -->
    <target name="unittest" depends="simulatorbuild">
        <exec executable="xcodebuild" output="${build.dir}/tmp" errorproperty="error.unittest">
            <arg line="-sdk ${sdk.simulator}" />
            <arg line="-configuration Debug" />
            <arg line="-target ${target.unittests}" />
        </exec>

        <exec executable="ruby">
            <arg line="ocunit2junit.rb" />
            <arg file="${build.dir}/tmp" />
        </exec>

        <delete file="${build.dir}/tmp" />
    </target>

    <!-- code coverage -->
    <target name="codecoverage" depends="-cc_simulatorbuild">
        <exec executable="xcodebuild" output="${build.dir}/tmp" errorproperty="error.unittest">
            <arg line="-sdk ${sdk.simulator}" />
            <arg line="-configuration Debug" />
            <arg line="-target ${target.unittests}" />

            <!-- Changing some project settings to activate code coverage. -->
            <!--<arg line="OTHER_CFLAGS=- -coverage" /> --> 

            <arg line="GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES" />
            <arg line="GCC_GENERATE_TEST_COVERAGE_FILES=YES" />
        </exec>

        <exec executable="ruby">
            <arg line="ocunit2junit.rb" />
            <arg file="${build.dir}/tmp" />
        </exec>

        <delete file="${build.dir}/tmp" />

        <mkdir dir="${build.dir}/code-coverage"/>
        <exec executable="python">
            <arg line="gcovr" />
            <arg line="-x" />               <!-- set XML-Output-->
            <arg line="-v" />               <!-- set more output details -->
            <arg line="-r '${basedir}'" />  <!-- set the root dir -->
            <arg line="-o '${build.dir}/code-coverage/coverage.xml'" />  
        </exec>
    </target>


    <!-- Distribute Target -->
    <target name="distribute" depends="devicebuild">
        <echo message="Set up Over-The-Air-Distribution"/>
        <property name="fileprefix" value="${env.JOB_NAME}-${env.BUILD_NUMBER}-${config.device}"/>
        <property name="app.path" value="${build.dir}/${config.device}-iphoneos/${target.app}.app"/>
        <property name="dSYM.path" value="${build.dir}/${config.device}-iphoneos/${target.app}.app.dSYM"/>
        <property name="output.dir" location="${basedir}/output"/>
        <delete dir="${output.dir}" />
        <mkdir dir="${output.dir}/${fileprefix}" />

        <exec executable="perl">
            <arg line="parsePlist.pl" />
            <arg line="${target.app}" />
        </exec>
        <property file="${target.app}-Infoplist.properties" />

        <!-- generate ipa file -->       
        <exec executable="xcrun" failonerror="true">
            <arg line="-verbose" />
            <arg line="-sdk ${sdk.device}" />
            <arg line="PackageApplication" />
            <arg line="-v '${app.path}'" />
            <arg line="-o '${output.dir}/${fileprefix}/${app.title}.ipa'" />
            <arg line="--sign '${codesign}'" />
            <arg line="--embed '${basedir}/${provisioningprofile}'" />
        </exec>

        <!-- manage app icons -->
        <copy file="${basedir}/${icon.small}" tofile="${output.dir}/${fileprefix}/Icon-57.png"/>
        <copy file="${basedir}/${icon.large}" tofile="${output.dir}/${fileprefix}/Icon-512.png"/>

        <!--copy file="${dSYM.path}" tofile="${output.dir}/${fileprefix}/${target.app}.app.dSYM"/-->

        <!-- generate app manifest -->
        <echoxml file="${output.dir}/${fileprefix}/app-manifest.plist">
            <!--<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">-->
            <plist version="1.0">
                <dict>
                    <key>items</key>
                    <array> 
                        <dict>
                            <key>assets</key>
                            <array>
                                <dict>
                                    <key>kind</key>
                                    <string>software-package</string>
                                    <key>url</key>
                                    <string>${OTAURL}/output/${fileprefix}/${app.title}.ipa</string>
                                </dict>
                                <dict>
                                    <key>kind</key>
                                    <string>full-size-image</string>
                                    <key>needs-shine</key>
                                    <true/>
                                    <key>url</key>
                                    <string>${OTAURL}/output/${fileprefix}/Icon-512.png</string>
                                </dict>
                                <dict>
                                    <key>kind</key>
                                    <string>display-image</string>
                                    <key>needs-shine</key>
                                    <true/>
                                    <key>url</key>
                                    <string>${OTAURL}/output/${fileprefix}/Icon-57.png</string>
                                </dict>
                            </array>
                            <key>metadata</key>
                            <dict>
                                <key>bundle-identifier</key>
                                <string>${CFBundleIdentifier}</string>
                                <key>bundle-version</key>
                                <string>${CFBundleShortVersionString} #${env.BUILD_NUMBER}</string>
                                <key>kind</key>
                                <string>software</string>
                                <key>title</key>
                                <string>${app.title}</string>
                                <key>subtitle</key>
                                <string>${app.subtitle}</string>
                            </dict>
                        </dict>
                    </array>
                </dict>
            </plist>
        </echoxml>
    </target>

</project>

还有一个 default.properties 文件:
# default properties
sdk.version         = 5.1
app.title           = <APP_NAME>
app.subtitle        = <APP_NAME>
config.simulator    = Debug
config.device       = Release
target.app          = <APP_NAME>
target.unittests    = <APP_NAME>Test
provisioningprofile = <APP_NAME>AdHoc.mobileprovision
codesign            = iPhone Distribution: <COMPANY_NAME>
icon.small          = Icon.png
icon.large          = Icon@2x.png
OTAURL              = http://<COMPANY_NAME>.com/OTA/<APP_NAME>

当我跑
ant distribute

在我的本地机器上(甚至在 CI 服务器上),出现以下错误:
[exec] error: Specified application doesn't exist or isn't a bundle directory : '/Users/<MY_USERNAME>/Documents/<COMPANY_NAME>/projects/<APP_NAME>/build/Release-iphoneos/<APP_NAME>.app'

我最近几天做了很多研究。但现在,我没有,还有什么办法......

到目前为止我得到了什么:
  • 从 Xcode 4 开始,构建路径不再是您的项目目录,而是用户库中的唯一文件夹。可以在“派生数据”下找到此设置。
    “Legacy”是项目文件夹,“unique”(新的默认设置)是用户库。
  • “distribute”的依赖是“devicebuild”。该目标使用唯一文件夹并在下正确创建它

    /用户//库/开发人员/Xcode/DerivedData
  • 在另一边(在目标“分发”中)我需要更改的唯一行是

    < arg line="-v '${app.path}'"/>

  • 它指向本地/项目目录。

    我需要设置唯一文件夹(用户库),而不是 app.path。
  • How do I print a list of "Build Settings" in Xcode project?我找到了 Xcode 环境变量的列表。这

    BUILD_DIR

  • 变量接近我需要的。它在文件夹层次结构中有点深,但没关系。
  • 我想,也许是Xcrun PackageApplication, failed unable to copy application类似的问题。但实际上并不相同。

  • 尽管 BUILD_DIR 不是绝对正确的,但我尝试使用那个。但我没有成功。

    如何在我的 ant 脚本中调用 Xcode 环境变量?这甚至可能吗?

    我试过:
    < arg line="-v '${BUILD_DIR}'" />
    < arg line="-v '$BUILD_DIR'" />
    < arg line="-v 'BUILD_DIR'" />
    

    请告诉我我在不知情的情况下犯了哪个愚蠢的错误。 :-)

    真的非常感谢提前!
    如果您需要更多信息(即使我认为我不认为,还有很多我没有告诉您),请问。

    问候并祝您有美好的一天,
    多米尼克

    最佳答案

    嗨,我想这有点晚了,但由于没有人回答这个话题,我会做的。
    有一个 xcrun 和 xcode-select 命令行工具可以管理开发者文件夹和许多其他有趣的东西。

    https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcrun.1.html#//apple_ref/doc/man/1/xcrun

    https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcode-select.1.html

    祝你好运

    关于ios - build.xml 中唯一的 Xcode BUILD_PATH 环境变量不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11506148/

    相关文章:

    ios - 手动居中时,UIButton 不会在 UITableViewCell 中居中

    ios - 多个 Xcode 项目将不再在真实的 iOS 设备上成功编译

    ios - 允许 NSBundle.mainBundle() 在 swift iOS 应用程序中查找 "der"格式的证书文件

    java - 通过 Eclipse 部署到 Glassfish

    java - JUnit4 测试类是否需要公共(public)无参数构造函数?

    ios - 无法使用 URLSession.shared.dataTask 加载某些图像

    ios - 将 Linphone 集成到自己的 iOS 项目中

    Java 实现的 rpmbuild 工具的等价物?

    ios - Xcode如何判断整个项目中是否有使用到当前开发目标不可用的API

    ios - 错误 ITMS-90161 无效的配置文件