感谢@advayDev1 为我指明了正确的方向。
解决方法是声明模块的build.gradle
文件SharedCode
如下:
plugins {
id 'java'
id 'com.github.j2objccontrib.j2objcgradle' version '0.6.0-alpha'
}
dependencies {
compile 'com.google.guava:guava:18.0'
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-core:1.3'
}
j2objcConfig {
autoConfigureDeps true
minVersionIos '8.4'
xcodeProjectDir '../iOS'
xcodeTargetsIos 'MySDK', 'MySDKTests'
finalConfigure()
}
并声明模块的build.gradle
文件TestContracts
如下:
plugins {
id 'java'
id 'com.github.j2objccontrib.j2objcgradle' version '0.6.0-alpha'
}
dependencies {
compile project(':SharedCode')
compile 'junit:junit:4.12' // this is compile scope deliberately
compile 'org.hamcrest:hamcrest-core:1.3' // this is compile scope deliberately
}
j2objcConfig {
autoConfigureDeps true
minVersionIos '8.4'
xcodeProjectDir '../iOS'
xcodeTargetsIos 'MySDKTests'
finalConfigure()
}
基于上述内容,在构建项目时,您应该期望您的内容Podfile
如下:
target 'MySDK' do
platform :ios, '8.4'
j2objc_SharedCode
import_other_pods
end
target 'MySDKTests' do
platform :ios, '8.4'
j2objc_TestContracts
j2objc_SharedCode
import_other_pods
end
J2ObjC Gradle 插件中有一个错误,它不能完全产生预期的Podfile
输出,但请参阅此处了解更多信息。