我们从一开始就使用 fastlane(从深圳等地迁移过来)和 Cordova(与 Phonegap 不太一样,但足够接近),并且发现它非常节省时间。我认为主要区别在于使用 phonegap 构建服务,理论上您可以使用 shell 命令通过 fastlane 调用该服务,尽管我建议在本地构建。
我还建议使用他们的 brew 包安装 Fastlane。 (假设您使用的是 Mac)
brew cask install fastlane
在项目的根目录中运行:
fastlane init
这将设置一个主 fastlane 目录,您将在其中管理 Android 和 iOS。
我们的目录结构如下:
── fastlane
│ ├── Appfile
│ ├── Deliverfile
│ ├── Fastfile
│ ├── Gymfile
│ ├── Matchfile
│ ├── Supplyfile
│ └── metadata
我们的快速文件看起来像这样:
fastlane_version "2.1.1"
default_platform :ios
app_name = "REDACTED"
app_identifier = CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)
platform :ios do
lane :development_profiles do
match(type: 'development', app_identifier: "#{app_identifier}")
match(type: 'development', app_identifier: "#{app_identifier}.MessagesExtension")
end
lane :appstore_profiles do
match(type: 'appstore', app_identifier: "#{app_identifier}")
match(type: 'appstore', app_identifier: "#{app_identifier}.MessagesExtension")
end
lane :profiles do
development_profiles
appstore_profiles
end
lane :build_development do
development_profiles
gym(
configuration: "Debug",
output_name: "#{app_name}-development.ipa"
)
end
lane :build_release do
appstore_profiles
gym(
configuration: "Release",
output_name: "#{app_name}-release.ipa"
)
end
lane :hockeyapp do |options|
hockey(
ipa: "REDACTED",
dsym: "REDACTED",
api_token: "REDACTED",
notes: "Build " + (ENV["BUILD_NUMBER"] ? ENV["BUILD_NUMBER"] + " " : "") + "From " + git_branch + " branch on " + Time.now.strftime('%F') + " at " + Time.now.strftime('%T'),
notify: "0"
)
end
lane :ci do
build_development
hockeyapp
end
lane :beta do
build_release
pilot
end
lane :release do
deliver(
ipa: "REDACTED",
force: true,
skip_metadata: true,
skip_screenshots: true
)
end
lane :screenshots do
deliver(
skip_binary_upload: true
)
end
after_all do |lane|
end
error do |lane, exception|
end
end
platform :android do
lane :build_development do
Dir.chdir ".." do
sh("platforms/android/cordova/clean")
end
gradle(
task: "cdvBuildDebug",
project_dir: "platforms/android/",
properties: {
'android.useDeprecatedNdk' => true
}
)
Dir.chdir ".." do
sh("mkdir -p REDACTED/")
sh("cp -f platforms/android/build/outputs/apk/android-armv7-debug.apk REDACTED/")
sh("cp -f platforms/android/build/outputs/apk/android-x86-debug.apk REDACTED/")
end
end
lane :build_release do
Dir.chdir ".." do
sh("platforms/android/cordova/clean")
end
gradle(
task: "cdvBuildRelease",
project_dir: "platforms/android/",
properties: {
'android.useDeprecatedNdk' => true
}
)
Dir.chdir ".." do
sh("mkdir -p REDACTED/")
sh("cp -f platforms/android/build/outputs/apk/android-armv7-release.apk REDACTED/")
sh("cp -f platforms/android/build/outputs/apk/android-x86-release.apk REDACTED/")
end
end
lane :hockeyapp do |options|
hockey(
apk: "REDACTED",
notes: "Build " + (ENV["BUILD_NUMBER"] ? ENV["BUILD_NUMBER"] + " " : "") + "From " + git_branch + " branch on " + Time.now.strftime('%F') + " at " + Time.now.strftime('%T'),
notify: "0"
)
end
lane :release do |options|
supply(
track: options[:track],
apk_paths: ["REDACTED", "REDACTED"],
skip_upload_metadata: true,
skip_upload_images: true,
skip_upload_screenshots: true
)
end
lane :ci do
build_development
hockeyapp
end
after_all do |lane|
end
error do |lane, exception|
end
end
关键在于,您将项目视为普通的原生项目,并以这种方式构建它。效果很好。