有没有办法在iOS上的同一个gradle构建脚本上构建多个目标?

时间:2014-01-20 21:39:40

标签: ios gradle

我正在使用Gradle XCODE插件,我可以构建一个目标,但我想知道我是否可以立即构建所有目标?

我目前的剧本:(适用于单个目标)

buildscript 
{ 
    repositories 
    { 
        maven 
        { 
            url('http://openbakery.org/repository/') 
        } 
        mavenCentral() 
    } 
    dependencies 
    {
        classpath group: 'org.openbakery', name: 'xcodePlugin', version: '0.9.2' 
    } 
} 
apply plugin: 'Xcode' 
xcodebuild 
{ 
    scheme = 'TestBuildGradle' 
    configuration = 'Debug' 
    sdk = 'iphonesimulator7.0' 
    target = 'TestBuildGradle' 
    unitTestTarget = 'TestBuildGradleTests' 
    destination 
    { 
        platform = 'iOS Simulator' 
        name = 'iPhone Retina (3.5-inch)' 
        os='7.0' 
    } 
}

我正在寻找一些选项,比如

target = "allTargets"

target = ['Target1', 'Target2', 'Target3', .....]

2 个答案:

答案 0 :(得分:3)

不是肯定这是你需要的,但这里是:

如果在命令行执行gradle任务,则xcodebuild任务为:

Xcode tasks
-----------
archive - Prepare the app bundle that it can be archive
build - Builds the Xcode project
clean - Cleans up the generated files from the previous build
codesign - Signs the app bundle that was created by xcodebuild
infoplist-modify
keychain-clean - Cleanup the keychain
keychain-create - Create a keychain that is used for signing the app
provisioning-clean
provisioning-install
test - Run the unit test fo the Xcode project
xcodebuild - Builds the Xcode project

在您的gradle脚本中,您可以拥有默认的xcodebuild块

xcodebuild {
   workspace = 'iPhone.xcworkspace'
   scheme='iPhone'
   configuration='Release' 
   sdk='iphoneos' 
   unitTestTarget='iPhoneTests' 
}

问题:unitTestTarget不起作用,因为sdk不是iphonesimulator(参见:https://github.com/openbakery/gradle-xcodePlugin

请注意,上面的Xcode插件为您定义了测试任务。所以我们添加一个测试块:

test {
    xcodebuild {
        sdk='iphonesimulator'
        configuration='Debug'
    }
}

答案 1 :(得分:0)

我不确定这会起作用,你可以尝试下一步:

task xcodebuild1 (type: XcodeBuildTask) {
    ....
    doFirst {
        project.xcodebuild.scheme = 'MyUnitTestScheme'
    }
    doLast {
        project.xcodebuild.scheme = null // resetting the scheme to default
    }
}

task xcodebuild2 (type: XcodeBuildTask) {
    ....
    doFirst {
        project.xcodebuild.sdk = 'iphoneos'
    }
    doLast {
        project.xcodebuild.sdk = 'iphonesimulator' // resetting the sdk to default
    }
}

task buildAll{
   dependsOn xcodebuild1, xcodebuild2
}