danger-apkstats 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Dangerfile.sample +2 -0
- data/Gemfile.lock +4 -4
- data/README.md +5 -1
- data/lib/apkstats/command/apk_analyzer.rb +18 -0
- data/lib/apkstats/command/executable.rb +6 -0
- data/lib/apkstats/entity/apk_info.rb +3 -1
- data/lib/apkstats/entity/apk_info_diff.rb +10 -0
- data/lib/apkstats/gem_version.rb +1 -1
- data/lib/apkstats/plugin.rb +43 -3
- data/spec/command/apk_analyzer_spec.rb +11 -0
- data/spec/entity/apk_info_diff_spec.rb +6 -0
- data/spec/entity/apk_info_spec.rb +2 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6aa65759eac00e6bdc2a9a745455a10d07a40c9e
|
4
|
+
data.tar.gz: 49efc61524d8d75eeef95050977fb4d0e1a08ca7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cf8e9d23c34f2af359cb01c18b36ca2e556e613e6bc7757421b1fc19ff115be7f4055b54f73ffa68e84a95932af847d15bc720f2c83b237caee57085296cac1
|
7
|
+
data.tar.gz: e1a15a138f9f446b4c8be024ae8bae0545f09fd7857ea7c01cbb90aa323368416dba9bdb9d758ce3d1869d1c1fa34b5f8d39482c586b225618d427be13589c0a
|
data/Dangerfile.sample
CHANGED
@@ -11,5 +11,7 @@ message(apkstats.non_required_features)
|
|
11
11
|
message(apkstats.permissions)
|
12
12
|
message(apkstats.min_sdk)
|
13
13
|
message(apkstats.target_sdk)
|
14
|
+
message("#{apkstats.reference_count}")
|
15
|
+
message("#{apkstats.dex_count}")
|
14
16
|
|
15
17
|
apkstats.compare_with('/spec/fixture/app-other5.apk', do_report: true)
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
danger-apkstats (0.
|
4
|
+
danger-apkstats (0.2.0)
|
5
5
|
danger-plugin-api (~> 1.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -40,7 +40,7 @@ GEM
|
|
40
40
|
faraday (~> 0.8)
|
41
41
|
ffi (1.9.25)
|
42
42
|
formatador (0.2.5)
|
43
|
-
git (1.
|
43
|
+
git (1.5.0)
|
44
44
|
guard (2.14.2)
|
45
45
|
formatador (>= 0.2.4)
|
46
46
|
listen (>= 2.7, < 4.0)
|
@@ -69,7 +69,7 @@ GEM
|
|
69
69
|
notiffany (0.1.1)
|
70
70
|
nenv (~> 0.1)
|
71
71
|
shellany (~> 0.0)
|
72
|
-
octokit (4.
|
72
|
+
octokit (4.10.0)
|
73
73
|
sawyer (~> 0.8.0, >= 0.5.3)
|
74
74
|
open4 (1.3.4)
|
75
75
|
parallel (1.12.1)
|
@@ -79,7 +79,7 @@ GEM
|
|
79
79
|
pry (0.11.3)
|
80
80
|
coderay (~> 1.1.0)
|
81
81
|
method_source (~> 0.9.0)
|
82
|
-
public_suffix (3.0.
|
82
|
+
public_suffix (3.0.3)
|
83
83
|
rainbow (3.0.0)
|
84
84
|
rake (10.5.0)
|
85
85
|
rb-fsevent (0.10.3)
|
data/README.md
CHANGED
@@ -31,6 +31,8 @@ apkstats.non_required_features #=> Array<String> | Nil
|
|
31
31
|
apkstats.permissions #=> Array<String> | Nil
|
32
32
|
apkstats.min_sdk #=> String | Nil
|
33
33
|
apkstats.target_sdk #=> String | Nils
|
34
|
+
apkstats.reference_count #=> Fixnum
|
35
|
+
apkstats.dex_count #=> Fixnum
|
34
36
|
```
|
35
37
|
|
36
38
|
### Get a comparison report
|
@@ -43,12 +45,14 @@ For example, the report will be like below.
|
|
43
45
|
|
44
46
|
Property | Summary
|
45
47
|
:--- | :---
|
46
|
-
New File Size | 1621248 Bytes. (1.55 MB
|
48
|
+
New File Size | 1621248 Bytes. (1.55 MB)
|
47
49
|
File Size Change | -13352 Bytes. (-13.04 KB)
|
48
50
|
Download Size Change | +41141 Bytes. (+40.18 KB)
|
49
51
|
Removed Required Features | - android.hardware.camera
|
50
52
|
Removed Non-required Features | - android.hardware.camera.front (not-required)
|
51
53
|
Removed Permissions | - android.permission.INTERNET<br>- android.permission.CAMERA
|
54
|
+
New Number of dex file(s) | 15720
|
55
|
+
Number of dex file(s) Change | 1
|
52
56
|
|
53
57
|
## Development
|
54
58
|
|
@@ -37,6 +37,17 @@ module Apkstats::Command
|
|
37
37
|
run_command("manifest", "target-sdk", apk_filepath)
|
38
38
|
end
|
39
39
|
|
40
|
+
def method_reference_count(apk_filepath)
|
41
|
+
ApkAnalyzer.parse_reference_to_map(run_command("dex", "references", apk_filepath))
|
42
|
+
.values
|
43
|
+
.map(&:to_i)
|
44
|
+
.inject(:+)
|
45
|
+
end
|
46
|
+
|
47
|
+
def dex_count(apk_filepath)
|
48
|
+
ApkAnalyzer.parse_reference_to_map(run_command("dex", "references", apk_filepath)).size
|
49
|
+
end
|
50
|
+
|
40
51
|
def self.parse_permissions(command_output)
|
41
52
|
command_output.split(/\r?\n/).map { |s| to_permission(s) }
|
42
53
|
end
|
@@ -59,6 +70,13 @@ module Apkstats::Command
|
|
59
70
|
::Apkstats::Entity::Feature.new(name, not_required: kind == "not-required", implied_reason: kind == "implied:" && tail)
|
60
71
|
end
|
61
72
|
|
73
|
+
def self.parse_reference_to_map(command_output)
|
74
|
+
command_output.split(/\r?\n/).each_with_object({}) do |s, acc|
|
75
|
+
dex_file, method_count = s.strip.split(/\t/, 2)
|
76
|
+
acc[dex_file] = method_count
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
62
80
|
private
|
63
81
|
|
64
82
|
def run_command(*args)
|
@@ -21,6 +21,8 @@ module Apkstats::Command
|
|
21
21
|
# permissions: Array<String>,
|
22
22
|
# min_sdk: String,
|
23
23
|
# target_sdk: String,
|
24
|
+
# method_reference_count: Integer,
|
25
|
+
# dex_count: Integer,
|
24
26
|
# },
|
25
27
|
# other: {
|
26
28
|
# file_size: Integer,
|
@@ -30,6 +32,8 @@ module Apkstats::Command
|
|
30
32
|
# permissions: Array<String>,
|
31
33
|
# min_sdk: String,
|
32
34
|
# target_sdk: String,
|
35
|
+
# method_reference_count: Integer,
|
36
|
+
# dex_count: Integer,
|
33
37
|
# },
|
34
38
|
# diff: {
|
35
39
|
# file_size: Integer,
|
@@ -48,6 +52,8 @@ module Apkstats::Command
|
|
48
52
|
# },
|
49
53
|
# min_sdk: Array<String>,
|
50
54
|
# target_sdk: Array<String>,
|
55
|
+
# method_reference_count: Integer,
|
56
|
+
# dex_count: Integer,
|
51
57
|
# }
|
52
58
|
# }
|
53
59
|
#
|
@@ -10,10 +10,12 @@ module Apkstats::Entity
|
|
10
10
|
permissions
|
11
11
|
min_sdk
|
12
12
|
target_sdk
|
13
|
+
method_reference_count
|
14
|
+
dex_count
|
13
15
|
).freeze
|
14
16
|
|
15
17
|
# Integer
|
16
|
-
attr_accessor :file_size, :download_size
|
18
|
+
attr_accessor :file_size, :download_size, :method_reference_count, :dex_count
|
17
19
|
|
18
20
|
# String
|
19
21
|
attr_accessor :min_sdk, :target_sdk
|
@@ -63,5 +63,15 @@ module Apkstats::Entity
|
|
63
63
|
# String
|
64
64
|
[@base[__method__], @other[__method__]].uniq
|
65
65
|
end
|
66
|
+
|
67
|
+
def method_reference_count
|
68
|
+
# Integer
|
69
|
+
@base[__method__].to_i - @other[__method__].to_i
|
70
|
+
end
|
71
|
+
|
72
|
+
def dex_count
|
73
|
+
# Integer
|
74
|
+
@base[__method__].to_i - @other[__method__].to_i
|
75
|
+
end
|
66
76
|
end
|
67
77
|
end
|
data/lib/apkstats/gem_version.rb
CHANGED
data/lib/apkstats/plugin.rb
CHANGED
@@ -52,6 +52,14 @@ module Danger
|
|
52
52
|
#
|
53
53
|
# apkstats.target_sdk
|
54
54
|
#
|
55
|
+
# @example Show the methods reference count of your apk file.
|
56
|
+
#
|
57
|
+
# apkstats.method_reference_count
|
58
|
+
#
|
59
|
+
# @example Show the number of dex of your apk file.
|
60
|
+
#
|
61
|
+
# apkstats.dex_count
|
62
|
+
#
|
55
63
|
# @see Jumpei Matsuda/danger-apkstats
|
56
64
|
# @tags android, apk_stats
|
57
65
|
#
|
@@ -81,7 +89,7 @@ module Danger
|
|
81
89
|
# @return [String]
|
82
90
|
attr_accessor :apk_filepath
|
83
91
|
|
84
|
-
# rubocop:disable Metrics/AbcSize
|
92
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
85
93
|
|
86
94
|
# Get stats of two apk files and calculate diffs between them.
|
87
95
|
#
|
@@ -122,7 +130,7 @@ module Danger
|
|
122
130
|
result[:base][:file_size].tap do |file_size|
|
123
131
|
size = Apkstats::Helper::Bytes.from_b(file_size)
|
124
132
|
|
125
|
-
md << "New File Size | #{size.to_b} Bytes. (#{size.to_mb} MB " << "\n"
|
133
|
+
md << "New File Size | #{size.to_b} Bytes. (#{size.to_mb} MB) " << "\n"
|
126
134
|
end
|
127
135
|
|
128
136
|
diff[:file_size].tap do |file_size|
|
@@ -137,6 +145,22 @@ module Danger
|
|
137
145
|
md << "Download Size Change | #{size.to_s_b} Bytes. (#{size.to_s_kb} KB) " << "\n"
|
138
146
|
end
|
139
147
|
|
148
|
+
result[:base][:method_reference_count].tap do |method_reference_count|
|
149
|
+
md << "New Method Reference Count | #{method_reference_count}" << "\n"
|
150
|
+
end
|
151
|
+
|
152
|
+
diff[:method_reference_count].tap do |method_reference_count|
|
153
|
+
md << "Method Reference Count Change | #{method_reference_count}" << "\n"
|
154
|
+
end
|
155
|
+
|
156
|
+
result[:base][:dex_count].tap do |dex_count|
|
157
|
+
md << "New Number of dex file(s) | #{dex_count}" << "\n"
|
158
|
+
end
|
159
|
+
|
160
|
+
diff[:dex_count].tap do |dex_count|
|
161
|
+
md << "Number of dex file(s) Change | #{dex_count}" << "\n"
|
162
|
+
end
|
163
|
+
|
140
164
|
report_hash_and_arrays = lambda { |key, name|
|
141
165
|
list_up_entities = lambda { |type_key, label|
|
142
166
|
diff[key][type_key].tap do |features|
|
@@ -162,7 +186,7 @@ module Danger
|
|
162
186
|
e.backtrace&.each { |line| STDOUT.puts line }
|
163
187
|
end
|
164
188
|
|
165
|
-
# rubocop:enable Metrics/AbcSize
|
189
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
166
190
|
|
167
191
|
# Show the file size of your apk file.
|
168
192
|
#
|
@@ -220,6 +244,22 @@ module Danger
|
|
220
244
|
run_command(__method__)
|
221
245
|
end
|
222
246
|
|
247
|
+
# Show the methods reference count of your apk file.
|
248
|
+
#
|
249
|
+
# @return [Fixnum] return positive value if exists, otherwise -1.
|
250
|
+
def method_reference_count(_opts = {})
|
251
|
+
result = run_command(__method__)
|
252
|
+
result || -1
|
253
|
+
end
|
254
|
+
|
255
|
+
# Show the number of dex of your apk file.
|
256
|
+
#
|
257
|
+
# @return [Fixnum] return positive value if exists, otherwise -1.
|
258
|
+
def dex_count(_opts = {})
|
259
|
+
result = run_command(__method__)
|
260
|
+
result || -1
|
261
|
+
end
|
262
|
+
|
223
263
|
private
|
224
264
|
|
225
265
|
def run_command(name)
|
@@ -10,6 +10,7 @@ module Apkstats::Command
|
|
10
10
|
let(:apk_other3) { fixture_path + "app-other3.apk" }
|
11
11
|
let(:apk_other4) { fixture_path + "app-other4.apk" }
|
12
12
|
let(:apk_other5) { fixture_path + "app-other5.apk" }
|
13
|
+
let(:apk_method64k) { fixture_path + "app-method64k.apk" }
|
13
14
|
|
14
15
|
it "should use custom path if set" do
|
15
16
|
expect(ApkAnalyzer.new({}).command_path).to eq("#{ENV.fetch('ANDROID_HOME')}/tools/bin/apkanalyzer")
|
@@ -55,6 +56,16 @@ module Apkstats::Command
|
|
55
56
|
it "target_sdk should return target sdk" do
|
56
57
|
expect(command.target_sdk(apk_base)).to eq("28")
|
57
58
|
end
|
59
|
+
|
60
|
+
it "method_reference_count should return reference count" do
|
61
|
+
expect(command.method_reference_count(apk_base)).to eq(15_720)
|
62
|
+
expect(command.method_reference_count(apk_method64k)).to eq(124_304)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "dex_count should return dex count" do
|
66
|
+
expect(command.dex_count(apk_base)).to eq(1)
|
67
|
+
expect(command.dex_count(apk_method64k)).to eq(2)
|
68
|
+
end
|
58
69
|
end
|
59
70
|
|
60
71
|
context "to_permission" do
|
@@ -31,6 +31,8 @@ module Apkstats::Entity
|
|
31
31
|
]),
|
32
32
|
min_sdk: "16",
|
33
33
|
target_sdk: "26",
|
34
|
+
method_reference_count: 20_000,
|
35
|
+
dex_count: 1,
|
34
36
|
}
|
35
37
|
end
|
36
38
|
|
@@ -57,6 +59,8 @@ module Apkstats::Entity
|
|
57
59
|
]),
|
58
60
|
min_sdk: "21",
|
59
61
|
target_sdk: "27",
|
62
|
+
method_reference_count: base_apk_values[:method_reference_count] + 2000,
|
63
|
+
dex_count: base_apk_values[:dex_count] + 1,
|
60
64
|
}
|
61
65
|
end
|
62
66
|
|
@@ -105,6 +109,8 @@ module Apkstats::Entity
|
|
105
109
|
)
|
106
110
|
expect(diff.min_sdk).to eq(%w(16 21))
|
107
111
|
expect(diff.target_sdk).to eq(%w(26 27))
|
112
|
+
expect(diff.method_reference_count).to eq(-2000)
|
113
|
+
expect(diff.dex_count).to eq(-1)
|
108
114
|
end
|
109
115
|
end
|
110
116
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-apkstats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jumpei Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -209,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
209
|
version: '0'
|
210
210
|
requirements: []
|
211
211
|
rubyforge_project:
|
212
|
-
rubygems_version: 2.
|
212
|
+
rubygems_version: 2.4.5
|
213
213
|
signing_key:
|
214
214
|
specification_version: 4
|
215
215
|
summary: This is a danger plugin to inspect android application file.
|