Alexandre Lision | db6c081 | 2016-11-02 10:47:28 -0400 | [diff] [blame] | 1 | module Fastlane |
| 2 | module Actions |
| 3 | module SharedValues |
| 4 | ZIPALIGN_CUSTOM_VALUE = :ZIPALIGN_CUSTOM_VALUE |
| 5 | end |
| 6 | |
| 7 | class ZipalignAction < Action |
| 8 | def self.run(params) |
| 9 | |
| 10 | UI.user_error!("Couldn't find '*release.apk' file at path 'app/build/outputs/apk/'") unless params[:apk_path] |
| 11 | |
| 12 | error_callback = proc do |error| |
| 13 | new_name = params[:apk_path].gsub('.apk', '-unaligned.apk') |
| 14 | rename_command = ["mv -n",params[:apk_path],new_name] |
| 15 | Fastlane::Actions.sh(rename_command, log: false) |
| 16 | |
| 17 | aligncmd = ["zipalign -v -f 4", new_name , " ", params[:apk_path] ] |
| 18 | Fastlane::Actions.sh(aligncmd, log: true) |
| 19 | |
| 20 | return |
| 21 | end |
| 22 | |
| 23 | zipalign = Fastlane::Actions.sh("zipalign -c -v 4 #{params[:apk_path]}", log: false , error_callback: error_callback) |
| 24 | |
| 25 | UI.message('Input apk is aligned') |
| 26 | |
| 27 | end |
| 28 | ##################################################### |
| 29 | # @!group Documentation |
| 30 | ##################################################### |
| 31 | |
| 32 | def self.description |
| 33 | "Zipalign an apk. Input apk is renamed '*-unaligned.apk'" |
| 34 | end |
| 35 | |
| 36 | def self.available_options |
| 37 | |
| 38 | apk_path_default = Dir["*.apk"].last || Dir[File.join("app", "build", "outputs", "apk", "*release.apk")].last |
| 39 | |
| 40 | [ |
| 41 | FastlaneCore::ConfigItem.new(key: :apk_path, |
| 42 | env_name: "INPUT_APK_PATH", |
| 43 | description: "Path to your APK file that you want to align", |
| 44 | default_value: Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH] || apk_path_default, |
| 45 | optional: true) |
| 46 | ] |
| 47 | end |
| 48 | |
| 49 | def self.authors |
| 50 | ["nomisRev"] |
| 51 | end |
| 52 | |
| 53 | def self.is_supported?(platform) |
| 54 | platform == :android |
| 55 | end |
| 56 | end |
| 57 | end |
| 58 | end |