android_apk 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c34a0896e31f26b93dea4960c846da52fb17baa5
4
- data.tar.gz: b4f17a56d8a4148d307027a2d94364f49d4207e7
3
+ metadata.gz: 0de1b3c20e0f09eea64dcd241fac6de24379dd67
4
+ data.tar.gz: 4de87bf59eda7fe3cb43a8b0b35c18881b6e34a0
5
5
  SHA512:
6
- metadata.gz: 72126a5303ca2c12c0d526039fe4c3786261adaa533b038d912bd557d0dddf4ef7c582e8734dce3d11506b576ca2544a57c328597dda30ffb6258d2bbaeee050
7
- data.tar.gz: 644427c81abf36372542bf1d6c5bd5aa536d23ff42d9f26e151b88e365bfd59642a4969f2de0e03effffeab4519194299255e5b658294bf7d42c817b61660f6c
6
+ metadata.gz: '033817bd77ccceb55636fff3df6d88464128e9ff326ea1a1b810450d874c2dd789d763c4c62f018dfb81253ca941298a94b7b4fa9bdee43be4a18090e1781eac'
7
+ data.tar.gz: 640ae49a4b46911a91485ad461a2134172a9eb33c51aa23f611606364385627822d2e28e288b4c16826d751cda5bf7d6a2c0196a8e15fc10ca8067ec1605287a
@@ -0,0 +1,56 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ #.DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ #*.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
50
+
51
+ # Intellij
52
+ .idea
53
+ *.iml
54
+
55
+ # OSX
56
+ .DS_Store
@@ -0,0 +1 @@
1
+ 2.2.0
@@ -27,7 +27,7 @@ GEM
27
27
  rake
28
28
  rdoc
29
29
  json (1.8.3)
30
- jwt (1.5.1)
30
+ jwt (1.5.2)
31
31
  multi_json (1.11.2)
32
32
  multi_xml (0.5.5)
33
33
  multipart-post (1.2.0)
data/README.md CHANGED
@@ -1,33 +1,90 @@
1
- #Android APK
1
+ # Android APK
2
2
 
3
3
  [![Circle CI](https://circleci.com/gh/kyoro/android_apk.svg?style=svg)](https://circleci.com/gh/kyoro/android_apk)
4
4
 
5
- This gem library is Android application package file (.apk) analyzer.
6
- you can read any information of android apk files.
5
+ This gem allows you to analyze Android application package file (*i.e.* .apk files.)
7
6
 
8
- ## Attention
9
7
 
10
- You must set path to 'AndroidSDK/platform-tools'.
11
- And you must can execute 'aapt' command.
8
+ ## Prerequisite
12
9
 
13
- ## How to use
10
+ You must set PATH to `$ANDROID_SDK_HOME/platform-tools` and make sure the `aapt` command executable.
14
11
 
12
+ ## Installation
13
+
14
+ Append to Gemfile:
15
+
16
+ ```
17
+ gem 'android_apk'
18
+ ```
19
+
20
+ or run on your terminal:
21
+
22
+ ```
23
+ gem install android_apk
15
24
  ```
25
+
26
+ ## Usage
27
+
28
+ ```ruby
16
29
  require 'android_apk'
17
30
 
18
31
  apk = AndroidApk.analyze("/path/to/apkfile.apk")
19
32
 
20
- apk.nil? # This file is invalid apk file.
33
+ apk.sdk_version
34
+ # => 14
35
+
36
+ apk.target_sdk_version
37
+ # => 26
38
+
39
+ apk.label
40
+ # => "Sample"
41
+
42
+ apk.package_name
43
+ # => "com.example.sample"
44
+
45
+ apk.version_code
46
+ # => 1
47
+
48
+ apk.version_name
49
+ # => "1.0"
21
50
 
22
- apk.label #Application Name
23
- apk.package_name #Package Name
24
- apk.icon #Included Icon file in apk file
25
- apk.version_code #Version Code
26
- apk.version_name #Version Name
51
+ apk.labels.length
52
+ # => 2
53
+
54
+ apk.labels['ja']
55
+ # => 'サンプル'
56
+
57
+ apk.signature
58
+ # => "c1f285f69cc02a397135ed182aa79af53d5d20a1"
59
+
60
+ apk.icons.length
61
+ # => 5
62
+
63
+ apk.icon
64
+ # => "res/mipmap-anydpi-v26/ic_launcher.xml"
65
+
66
+ apk.icon_file
67
+ # => File (png/xml)
68
+
69
+ apk.icon_file('hdpi')
70
+ # => File (png/xml)
71
+
72
+ apk.icon_file('hdpi', true)
73
+ # => File (png)
74
+
75
+ apk.dpi_str(240)
76
+ # => "hdpi"
27
77
  ```
28
78
 
29
- ## License
30
- This Library is using MIT license.
31
79
 
32
- ## Contact
33
- Kyosuke INOUE < kyoro@hakamastyle.net>
80
+ # License
81
+
82
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
83
+
84
+ Copyright &copy; 2017 Kyosuke Inoue <kyoro@hakamastyle.net>
85
+
86
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
87
+
88
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
89
+
90
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ Jeweler::Tasks.new do |gem|
18
18
  gem.homepage = "http://github.com/kyoro/android_apk"
19
19
  gem.license = "MIT"
20
20
  gem.summary = "Android APK file analyzer"
21
- gem.description = "This library can analyze Android APK application package. You can get any information of android apk file."
21
+ gem.description = "This gem allows you to analyze Android application package file (.apk files)"
22
22
  gem.email = "kyoro@hakamastyle.net"
23
23
  gem.authors = ["Kyosuke INOUE"]
24
24
  # dependencies defined in Gemfile
@@ -1,72 +1,21 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
- # stub: android_apk 0.8.0 ruby lib
6
-
7
1
  Gem::Specification.new do |s|
8
2
  s.name = "android_apk".freeze
9
- s.version = "0.8.0"
3
+ s.version = "0.9.0"
10
4
 
11
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
6
  s.require_paths = ["lib".freeze]
13
7
  s.authors = ["Kyosuke INOUE".freeze]
14
8
  s.date = "2016-03-01"
15
- s.description = "This library can analyze Android APK application package. You can get any information of android apk file.".freeze
9
+ s.description = "Library for analyzing Android APK application package. You can get any information of android apk file.".freeze
16
10
  s.email = "kyoro@hakamastyle.net".freeze
17
11
  s.extra_rdoc_files = [
18
12
  "LICENSE.txt",
19
13
  "README.md"
20
14
  ]
21
- s.files = [
22
- ".document",
23
- ".rspec",
24
- "Gemfile",
25
- "Gemfile.lock",
26
- "LICENSE.txt",
27
- "README.md",
28
- "Rakefile",
29
- "VERSION",
30
- "android_apk.gemspec",
31
- "circle.yml",
32
- "lib/android_apk.rb",
33
- "spec/android_apk_spec.rb",
34
- "spec/mock/BarcodeScanner4.2.apk",
35
- "spec/mock/UECExpress.apk",
36
- "spec/mock/dsa.apk",
37
- "spec/mock/dummy.apk",
38
- "spec/mock/sample with space.apk",
39
- "spec/mock/sample.apk",
40
- "spec/mock/vector-icon.apk",
41
- "spec/spec_helper.rb"
42
- ]
15
+ s.files = `git ls-files`.split($/)
43
16
  s.homepage = "http://github.com/kyoro/android_apk".freeze
44
17
  s.licenses = ["MIT".freeze]
45
18
  s.rubygems_version = "2.6.1".freeze
46
19
  s.summary = "Android APK file analyzer".freeze
47
-
48
- if s.respond_to? :specification_version then
49
- s.specification_version = 4
50
-
51
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
- s.add_development_dependency(%q<rspec>.freeze, ["~> 3.2.0"])
53
- s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
54
- s.add_development_dependency(%q<bundler>.freeze, ["~> 1.11.2"])
55
- s.add_development_dependency(%q<jeweler>.freeze, ["~> 1.8.4"])
56
- s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
57
- else
58
- s.add_dependency(%q<rspec>.freeze, ["~> 3.2.0"])
59
- s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
60
- s.add_dependency(%q<bundler>.freeze, ["~> 1.11.2"])
61
- s.add_dependency(%q<jeweler>.freeze, ["~> 1.8.4"])
62
- s.add_dependency(%q<simplecov>.freeze, [">= 0"])
63
- end
64
- else
65
- s.add_dependency(%q<rspec>.freeze, ["~> 3.2.0"])
66
- s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
67
- s.add_dependency(%q<bundler>.freeze, ["~> 1.11.2"])
68
- s.add_dependency(%q<jeweler>.freeze, ["~> 1.8.4"])
69
- s.add_dependency(%q<simplecov>.freeze, [">= 0"])
70
- end
71
20
  end
72
21
 
@@ -4,6 +4,11 @@ require 'open3'
4
4
 
5
5
  class AndroidApk
6
6
  attr_accessor :results,:label,:labels,:icon,:icons,:package_name,:version_code,:version_name,:sdk_version,:target_sdk_version,:filepath
7
+
8
+ NOT_ALLOW_DUPLICATE_TAG_NAMES = %w(application)
9
+ class AndroidManifestValidateError < StandardError
10
+ end
11
+
7
12
  def self.analyze(filepath)
8
13
  return nil unless File.exist?(filepath)
9
14
  apk = AndroidApk.new
@@ -45,7 +50,7 @@ class AndroidApk
45
50
 
46
51
  if want_png && icon.end_with?('.xml')
47
52
  dpis = dpi_str(dpi)
48
- icon.gsub! %r{res/drawable-anydpi-v21/([^/]+)\.xml}, "res/drawable-#{dpis}-v4/\\1.png"
53
+ icon.gsub! %r{res/(drawable|mipmap)-anydpi-(?:v\d+)/([^/]+)\.xml}, "res/\\1-#{dpis}-v4/\\2.png"
49
54
  end
50
55
 
51
56
  Dir.mktmpdir do |dir|
@@ -121,7 +126,7 @@ class AndroidApk
121
126
  results.split("\n").each do |line|
122
127
  key, value = _parse_line(line)
123
128
  next if key.nil?
124
- if vars.key?(key)
129
+ if vars.key?(key) && allow_duplicate?(key)
125
130
  if (vars[key].is_a?(Hash) and value.is_a?(Hash))
126
131
  vars[key].merge(value)
127
132
  else
@@ -140,4 +145,9 @@ class AndroidApk
140
145
  end
141
146
  return vars
142
147
  end
148
+
149
+ def self.allow_duplicate?(key)
150
+ raise AndroidManifestValidateError, "Duplication of #{key} tag is not allowed" if NOT_ALLOW_DUPLICATE_TAG_NAMES.include?(key)
151
+ true
152
+ end
143
153
  end
@@ -7,14 +7,16 @@ describe "AndroidApk" do
7
7
  apk2 = nil
8
8
  icon_not_set_apk = nil
9
9
 
10
- mockdir = File.join(File.dirname(__FILE__), 'mock')
11
- sample_file_path = File.join(mockdir, 'sample.apk')
12
- sample2_file_path = File.join(mockdir, 'BarcodeScanner4.2.apk')
13
- sample_space_file_path = File.join(mockdir, 'sample with space.apk')
14
- icon_not_set_file_path = File.join(mockdir, 'UECExpress.apk')
15
- dummy_file_path = File.join(mockdir, 'dummy.apk')
16
- dsa_file_path = File.join(mockdir, 'dsa.apk')
17
- vector_file_path = File.join(mockdir, 'vector-icon.apk')
10
+ mockdir = File.join(File.dirname(__FILE__), 'mock')
11
+ sample_file_path = File.join(mockdir, 'sample.apk')
12
+ sample2_file_path = File.join(mockdir, 'BarcodeScanner4.2.apk')
13
+ sample_space_file_path = File.join(mockdir, 'sample with space.apk')
14
+ icon_not_set_file_path = File.join(mockdir, 'UECExpress.apk')
15
+ dummy_file_path = File.join(mockdir, 'dummy.apk')
16
+ dsa_file_path = File.join(mockdir, 'dsa.apk')
17
+ vector_file_path = File.join(mockdir, 'vector-icon.apk')
18
+ vector_v26_file_path = File.join(mockdir, 'vector-icon-v26.apk')
19
+ multi_application_tag_file_path = File.join(mockdir, 'multi_application_tag.apk')
18
20
 
19
21
  it "Sample apk file exist" do
20
22
  File.exist?(sample_file_path).should == true
@@ -109,8 +111,7 @@ describe "AndroidApk" do
109
111
  end
110
112
  end
111
113
 
112
- context "with vector icon" do
113
- subject { AndroidApk.analyze(vector_file_path) }
114
+ shared_examples_for 'vector icon' do
114
115
  it 'can be analyzed' do
115
116
  is_expected.not_to be_nil
116
117
  end
@@ -124,4 +125,28 @@ describe "AndroidApk" do
124
125
  expect(subject.icon_file(240, true)).not_to be_nil
125
126
  end
126
127
  end
128
+
129
+ context "with vector icon" do
130
+ subject { AndroidApk.analyze(vector_file_path) }
131
+ it_behaves_like 'vector icon'
132
+ end
133
+
134
+ context "with vector icon v26" do
135
+ subject { AndroidApk.analyze(vector_v26_file_path) }
136
+ it_behaves_like 'vector icon'
137
+ end
138
+
139
+ context "multi application tag error" do
140
+ it 'should raise error' do
141
+ expect {
142
+ AndroidApk.analyze(multi_application_tag_file_path)
143
+ }.to raise_error AndroidApk::AndroidManifestValidateError
144
+ end
145
+
146
+ it 'not raise error' do
147
+ expect {
148
+ AndroidApk.analyze(vector_file_path)
149
+ }.not_to raise_error
150
+ end
151
+ end
127
152
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: android_apk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyosuke INOUE
@@ -9,79 +9,9 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2016-03-01 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rspec
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 3.2.0
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 3.2.0
27
- - !ruby/object:Gem::Dependency
28
- name: rdoc
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '3.12'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '3.12'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 1.11.2
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 1.11.2
55
- - !ruby/object:Gem::Dependency
56
- name: jeweler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 1.8.4
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 1.8.4
69
- - !ruby/object:Gem::Dependency
70
- name: simplecov
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
- description: This library can analyze Android APK application package. You can get
84
- any information of android apk file.
12
+ dependencies: []
13
+ description: Library for analyzing Android APK application package. You can get any
14
+ information of android apk file.
85
15
  email: kyoro@hakamastyle.net
86
16
  executables: []
87
17
  extensions: []
@@ -90,7 +20,9 @@ extra_rdoc_files:
90
20
  - README.md
91
21
  files:
92
22
  - ".document"
23
+ - ".gitignore"
93
24
  - ".rspec"
25
+ - ".ruby-version"
94
26
  - Gemfile
95
27
  - Gemfile.lock
96
28
  - LICENSE.txt
@@ -105,8 +37,10 @@ files:
105
37
  - spec/mock/UECExpress.apk
106
38
  - spec/mock/dsa.apk
107
39
  - spec/mock/dummy.apk
40
+ - spec/mock/multi_application_tag.apk
108
41
  - spec/mock/sample with space.apk
109
42
  - spec/mock/sample.apk
43
+ - spec/mock/vector-icon-v26.apk
110
44
  - spec/mock/vector-icon.apk
111
45
  - spec/spec_helper.rb
112
46
  homepage: http://github.com/kyoro/android_apk
@@ -129,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
63
  version: '0'
130
64
  requirements: []
131
65
  rubyforge_project:
132
- rubygems_version: 2.6.1
66
+ rubygems_version: 2.4.5
133
67
  signing_key:
134
68
  specification_version: 4
135
69
  summary: Android APK file analyzer