fastlane-plugin-analyze_apk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1cffa2a4628a19bbda3325cc00861407830e8466
4
+ data.tar.gz: a6a43083421a0844923d476a71f611b9d2d1c662
5
+ SHA512:
6
+ metadata.gz: 136d4a66fa17033e1a20bbce2e20f6d4a8e461dd115fb9307c9d743ed83a9b23f595f7edaaca792737ad2a6434a49d3d044429aaf29578d84b23aada74c384ca
7
+ data.tar.gz: 49e79a58441672ad60ddb4caaf53f17fb5ce36ac9f61e8a916cdd5640f29ddee540954c03e26d5c4912bad2543def1c0a8e5b2e3da15e14686bc6334911ef27f
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Daniel Kochavi <>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,81 @@
1
+ # analyze_apk plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-analyze_apk)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-analyze_apk`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin analyze_apk
11
+ ```
12
+
13
+ ## About analyze_apk
14
+ Analyze APK extracts usefull information about your generated APK.
15
+
16
+ **Options:**
17
+
18
+ **Key**|**Description**
19
+ -----|-----
20
+ apk\_path|Path to the apk you want to inspect
21
+ android\_home|Path to the root of your Android SDK installation, e.g. ~/tools/android-sdk-macosx
22
+ build\_tools\_version|The Android build tools version to use e.g. '23.0.2'
23
+
24
+ **Output variables:**
25
+
26
+ **SharedValue**|**Description**
27
+ -----|-----
28
+ ANALYZE\_APK\_PACKAGE\_NAME|APK's package name
29
+ ANALYZE\_APK\_VERSION\_CODE|APK's version code
30
+ ANALYZE\_APK\_VERSION\_NAME|APK's version name
31
+ ANALYZE\_APK\_APP\_NAME|App's name
32
+ ANALYZE\_APK\_MIN\_SDK|APK's minimal sdk version
33
+ ANALYZE\_APK\_SIZE|APK's size (bytes)
34
+
35
+ * You can access these values using: ```lane_context[SharedValues::VARIABLE_NAME]```
36
+
37
+ ## Example
38
+ The following lane creates an apk using the [gradle action](https://docs.fastlane.tools/actions/#gradle) then it takes the generated apk and runs ```analyze_apk``` on it (using a ```SharedValue``` set by the gradle action):
39
+
40
+ ```ruby
41
+ fastlane_version "2.39.2"
42
+
43
+ default_platform :android
44
+
45
+ platform :android do
46
+
47
+ desc "Create an apk and print information about it"
48
+ lane :apk do
49
+ gradle( #builds your apk
50
+ task: "assembleRelease"
51
+ )
52
+ analyze_apk(
53
+ android_home: 'path/to/your/Android/sdk',
54
+ build_tools_version: '23.0.2',
55
+ apk_path: lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]
56
+ )
57
+ puts("Version name: #{lane_context[SharedValues::ANALYZE_APK_VERSION_NAME]}")
58
+ puts("Package name: #{lane_context[SharedValues::ANALYZE_APK_PACKAGE_NAME]}")
59
+ puts("Version code: #{lane_context[SharedValues::ANALYZE_APK_VERSION_CODE]}")
60
+ puts("App name: #{lane_context[SharedValues::ANALYZE_APK_APP_NAME]}")
61
+ puts("Minimum sdk: #{lane_context[SharedValues::ANALYZE_APK_MIN_SDK]}")
62
+ puts("Apk size: #{lane_context[SharedValues::ANALYZE_APK_SIZE]} bytes")
63
+ end
64
+ end
65
+ ```
66
+
67
+ ## Issues and Feedback
68
+
69
+ For any other issues and feedback about this plugin, please submit it to this repository.
70
+
71
+ ## Troubleshooting
72
+
73
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
74
+
75
+ ## Using _fastlane_ Plugins
76
+
77
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
78
+
79
+ ## About _fastlane_
80
+
81
+ _fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/analyze_apk/version'
2
+
3
+ module Fastlane
4
+ module AnalyzeApk
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::AnalyzeApk.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,102 @@
1
+ # Code inspired by Bitrise Deploy Step - https://github.com/bitrise-io/steps-deploy-to-bitrise-io
2
+ module Fastlane
3
+ module Actions
4
+ module SharedValues
5
+ ANALYZE_APK_PACKAGE_NAME = :ANALYZE_APK_PACKAGE_NAME
6
+ ANALYZE_APK_VERSION_CODE = :ANALYZE_APK_VERSION_CODE
7
+ ANALYZE_APK_VERSION_NAME = :ANALYZE_APK_VERSION_NAME
8
+ ANALYZE_APK_APP_NAME = :ANALYZE_APK_APP_NAME
9
+ ANALYZE_APK_MIN_SDK = :ANALYZE_APK_MIN_SDK
10
+ ANALYZE_APK_SIZE = :ANALYZE_APK_SIZE
11
+ end
12
+ class AnalyzeApkAction < Action
13
+ def self.run(params)
14
+
15
+ app_apk_path = params[:apk_path]
16
+ android_home = params[:android_home]
17
+
18
+ UI.user_error!("Couldn't find Android SDK at path '#{android_home}'") if android_home.nil? || !File.directory?(android_home)
19
+
20
+ android_env = Fastlane::Helper::AndroidEnvironment.new(params[:android_home],
21
+ params[:build_tools_version])
22
+
23
+ helper = Helper::AnalyzeApkHelper
24
+ executor = FastlaneCore::CommandExecutor
25
+
26
+ aapt_path = android_env.aapt_path
27
+
28
+ aapt_info = executor.execute(command: "#{aapt_path} dump badging #{app_apk_path}",
29
+ print_all: false,
30
+ print_command: false)
31
+
32
+ package_name, version_code, version_name = helper.filter_package_infos(aapt_info)
33
+ app_name = helper.filter_app_label(aapt_info)
34
+ min_sdk = helper.filter_min_sdk_version(aapt_info)
35
+ apk_file_size = File.size(app_apk_path)
36
+
37
+ Actions.lane_context[SharedValues::ANALYZE_APK_PACKAGE_NAME] = package_name if package_name
38
+ Actions.lane_context[SharedValues::ANALYZE_APK_VERSION_CODE] = version_code if version_code
39
+ Actions.lane_context[SharedValues::ANALYZE_APK_VERSION_NAME] = version_name if version_name
40
+
41
+ Actions.lane_context[SharedValues::ANALYZE_APK_APP_NAME] = app_name if app_name
42
+ Actions.lane_context[SharedValues::ANALYZE_APK_MIN_SDK] = min_sdk if min_sdk
43
+ Actions.lane_context[SharedValues::ANALYZE_APK_SIZE] = apk_file_size if apk_file_size
44
+ end
45
+
46
+ def self.description
47
+ 'Analyzes an apk to fetch: versionCode, versionName, apk size, permissions, etc.'
48
+ end
49
+
50
+ def self.authors
51
+ ['kochavi-daniel']
52
+ end
53
+
54
+ def self.output
55
+ [
56
+ ['ANALYZE_APK_VERSION_NAME', 'Apk\'s version name'],
57
+ ['ANALYZE_APK_VERSION_CODE', 'Apk\'s version code'],
58
+ ['ANALYZE_APK_PACKAGE_NAME', 'Apk\'s package name'],
59
+ ['ANALYZE_APK_APP_NAME', 'App name'],
60
+ ['ANALYZE_APK_MIN_SDK', 'Apk\'s min sdk version'],
61
+ ['ANALYZE_APK_SIZE', 'Apk\'s size (bytes)']
62
+ ]
63
+ end
64
+
65
+ def self.return_value
66
+ # If your method provides a return value, you can describe here what it does
67
+ end
68
+
69
+ def self.details
70
+ "Using this plugin will enable you to extract the following info about your generated apk: versionName, versionCode, package name, app name, minSdkVersion, apk size"
71
+ end
72
+
73
+ def self.available_options
74
+ [
75
+ FastlaneCore::ConfigItem.new(key: :apk_path,
76
+ env_name: 'FL_APK_PATH',
77
+ description: 'Path to the apk you want to inspect',
78
+ is_string: true,
79
+ optional: false,
80
+ verify_block: proc do |value|
81
+ UI.user_error!("Couldn't find apk file at path '#{value}'") unless File.exist?(value)
82
+ end),
83
+ FastlaneCore::ConfigItem.new(key: :android_home,
84
+ env_name: 'FL_ANDROID_HOME',
85
+ description: 'Path to the root of your Android SDK installation, e.g. ~/tools/android-sdk-macosx',
86
+ is_string: true,
87
+ optional: true,
88
+ default_value: ENV['ANDROID_HOME'] || ENV['ANDROID_SDK']),
89
+ FastlaneCore::ConfigItem.new(key: :build_tools_version,
90
+ env_name: 'FL_BUILD_TOOLS_VERSION',
91
+ description: "The Android build tools version to use, e.g. '23.0.2'",
92
+ is_string: true,
93
+ optional: true)
94
+ ]
95
+ end
96
+
97
+ def self.is_supported?(platform)
98
+ platform == :android
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,47 @@
1
+ module Fastlane
2
+ module Helper
3
+ class AnalyzeApkHelper
4
+ class << self
5
+ def filter_package_infos(infos)
6
+ package_name = ''
7
+ version_code = ''
8
+ version_name = ''
9
+
10
+ package_name_version_regex = 'package: name=\'(?<package_name>.*)\' versionCode=\'(?<version_code>.*)\' versionName=\'(?<version_name>.*)\' platformBuildVersionName='
11
+ package_name_version_match = infos.match(package_name_version_regex)
12
+
13
+ if package_name_version_match && package_name_version_match.captures
14
+ package_name = package_name_version_match.captures[0]
15
+ version_code = package_name_version_match.captures[1]
16
+ version_name = package_name_version_match.captures[2]
17
+ end
18
+
19
+ return [package_name, version_code, version_name]
20
+ end
21
+ def filter_app_label(infos)
22
+ app_label_regex = 'application: label=\'(?<label>.+)\' icon='
23
+ app_label_match = infos.match(app_label_regex)
24
+
25
+ return app_label_match.captures[0] if app_label_match && app_label_match.captures
26
+
27
+ app_label_regex = 'application-label:\'(?<label>.*)\''
28
+ app_label_match = infos.match(app_label_regex)
29
+
30
+ return app_label_match.captures[0] if app_label_match && app_label_match.captures
31
+
32
+ return ''
33
+ end
34
+
35
+ def filter_min_sdk_version(infos)
36
+ min_sdk = ''
37
+
38
+ min_sdk_regex = 'sdkVersion:\'(?<min_sdk_version>.*)\''
39
+ min_sdk_match = infos.match(min_sdk_regex)
40
+ min_sdk = min_sdk_match.captures[0] if min_sdk_match && min_sdk_match.captures
41
+
42
+ return min_sdk
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,72 @@
1
+ # Relevant code was copied from the Screengrab action (https://github.com/fastlane/fastlane/blob/master/screengrab/lib/screengrab/android_environment.rb)
2
+
3
+ require 'fileutils'
4
+ require 'fastlane_core'
5
+ module Fastlane
6
+ module Helper
7
+ class AndroidEnvironment
8
+ attr_reader :android_home
9
+ attr_reader :build_tools_version
10
+
11
+ # android_home - the String path to the install location of the Android SDK
12
+ # build_tools_version - the String version of the Android build tools that should be used
13
+ def initialize(android_home, build_tools_version)
14
+ @android_home = android_home
15
+ @build_tools_version = build_tools_version
16
+ end
17
+
18
+ def build_tools_path
19
+ @build_tools_path ||= find_build_tools(android_home, build_tools_version)
20
+ end
21
+
22
+ def aapt_path
23
+ @aapt_path ||= find_aapt(build_tools_path)
24
+ end
25
+
26
+ private
27
+
28
+ def find_build_tools(android_home, build_tools_version)
29
+ return nil unless android_home
30
+
31
+ build_tools_dir = File.join(android_home, 'build-tools')
32
+
33
+ return nil unless build_tools_dir && File.directory?(build_tools_dir)
34
+
35
+ return File.join(build_tools_dir, build_tools_version) if build_tools_version
36
+
37
+ version = select_build_tools_version(build_tools_dir)
38
+
39
+ version ? File.join(build_tools_dir, version) : nil
40
+ end
41
+
42
+ def select_build_tools_version(build_tools_dir)
43
+ # Collect the sub-directories of the build_tools_dir, rejecting any that start with '.' to remove . and ..
44
+ dir_names = Dir.entries(build_tools_dir).select { |e| !e.start_with?('.') && File.directory?(File.join(build_tools_dir, e)) }
45
+
46
+ # Collect a sorted array of Version objects from the directory names, handling the possibility that some
47
+ # entries may not be valid version names
48
+ versions = dir_names.map do |d|
49
+ begin
50
+ Gem::Version.new(d)
51
+ rescue
52
+ nil
53
+ end
54
+ end.reject(&:nil?).sort
55
+
56
+ # We'll take the last entry (highest version number) as the directory name we want
57
+ versions.last.to_s
58
+ end
59
+
60
+ def find_aapt(build_tools_path)
61
+ return FastlaneCore::CommandExecutor.which('aapt') unless build_tools_path
62
+
63
+ aapt_path = File.join(build_tools_path, 'aapt')
64
+ executable_command?(aapt_path) ? aapt_path : nil
65
+ end
66
+
67
+ def executable_command?(cmd_path)
68
+ cmd_path && File.executable?(cmd_path) && !File.directory?(cmd_path)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module AnalyzeApk
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-analyze_apk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kochavi-daniel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: fastlane
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.43.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 2.43.0
97
+ description:
98
+ email: ''
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - LICENSE
104
+ - README.md
105
+ - lib/fastlane/plugin/analyze_apk.rb
106
+ - lib/fastlane/plugin/analyze_apk/actions/analyze_apk_action.rb
107
+ - lib/fastlane/plugin/analyze_apk/helper/analyze_apk_helper.rb
108
+ - lib/fastlane/plugin/analyze_apk/helper/android_environment.rb
109
+ - lib/fastlane/plugin/analyze_apk/version.rb
110
+ homepage: https://github.com/kochavi-daniel/fastlane-plugin-analyze-apk
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.6.8
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: 'Analyzes an apk to fetch: versionCode, versionName, apk size, etc.'
134
+ test_files: []