0

我使用Travis和Fastlane構建應用並將其發佈到Google Play商店,但在同時處理多種風味時,Supply無法找到APK上傳它們。構建多種風味並從Fastlane部署到Google Play時未導出Apk路徑

這是我中fastfile:

fastlane_version "2.59.0" 

default_platform :android 

platform :android do 

    before_all do 
     gradle(task: "clean") 
    end 

    desc "Submit Whitelabels to Play Store" 
    lane :whitelabels_playstore do 
     gradle(
      task: 'releaseWhitelabel' 
    ) 

    lane_context[SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS].each do | apk | 
     puts "Uploading APK to Play Store: " + apk 
     begin 
      supply(
       skip_upload_images: true, 
       skip_upload_screenshots: true, 
       validate_only: true, 
       apk: apk 
      ) 
     rescue => ex 
      puts ex 
     end 
    end 
    end 
end 

任務releaseWhitelabel代碼:

def releaseTask = tasks.create(name: 'releaseWhitelabel') { 
    group 'Whitelabel' 
    description "Assembles and release all Whitelabels" 
} 

android.applicationVariants.all { variant -> 
    if (variant.buildType.name == 'release') { 

    variant.productFlavors.each { flavor -> 
     def flavorName = flavor.name.capitalize() 
     def releaseFlavorTaskName = "releaseWhitelabel${flavorName}" 
     def releaseFlavorTask 

     flavorsMap.each { name, jsonItem -> 
     if (flavorName.toUpperCase().startsWith(name.toUpperCase())) { 

      releaseFlavorTask = tasks.create(name: releaseFlavorTaskName) { 
      group 'Whitelabel' 
      description "Assembles and release build for flavor $flavorName" 
      } 
      releaseFlavorTask.dependsOn variant.assemble 
      releaseTask.dependsOn releaseFlavorTask 
     } 
     } 
    } 
    } 
} 

本地運行時任務完美的作品,當我執行的車道,我得到一個錯誤,說lane_context[SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS]不能是不行的。

當我運行下面的gradle配置時,我工作正常,但只有一種口味可以通過這種方式發佈,我的口味是動態生成的。

gradle(
    task: 'assemble', 
    flavor: 'Dell', 
    build_type: 'Release' 
) 

我該如何才能將lane_context[SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS]正確地更新爲每個apk的路徑?

回答

0

我採取的方法是使用JSON文件控制所有白標籤並從那裏獲取數據。

lane :whitelabels_playstore do 
    gradle(
     task: "whitelabelRelease" 
    ) 

    begin 
     # Retrieving Flavors from JSON file 
     require "json" 
     file = File.read "../buildsystem/whitelabels.json" 
     data = JSON.parse(file) 

     # Supply will deploy each flavor to Play Store 
     data['list'].each do | whitelabel | 

     begin 
     supply(
      // application_id_suffix is provided by JSON file 
      package_name: "my.app.package.#{whitelabel['application_id_suffix']}", 
      skip_upload_images: true, 
      skip_upload_screenshots: true, 
      // flavor_nameis provided by JSON file 
      apk: "app/build/outputs/apk/app-#{whitelabel['flavor_name']}-release.apk" 
     ) 
     rescue => ex 
      puts ex 

      slack(
       message: "Error uploading => #{/([^\/]*)$/.match(apk)} #{get_version_name} - #{get_version_code}: #{ex}", 
       slack_url: "SLACK_HOOK_URL", 
       success: false, 
       default_payloads: [:git_branch, :lane, :test_result] 
     ) 
     end 
     end 

     rescue => ex 
     puts ex 
    end 
    end