apu 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +5 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +44 -0
- data/Rakefile +5 -0
- data/apu.gemspec +36 -0
- data/bin/apu +5 -0
- data/extras/apu.gif +0 -0
- data/extras/apu2.gif +0 -0
- data/extras/apu3.gif +0 -0
- data/lib/apk-utils/android_project.rb +176 -0
- data/lib/apu.rb +112 -0
- data/lib/apu/android_project.rb +170 -0
- data/lib/apu/version.rb +3 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f79a90e0ddf23a429f6e765d6e6b18e0fd1f68b0
|
4
|
+
data.tar.gz: f01e40f3220de39a18c0ae1345d7436405e85f67
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1331aea84f604d1f4482a27165b3292557bbf1a459140c7d595ac4a3ae4d1db8755441438f10d061eaeb57631f5b2a8d043d9da3acf762598e3bb8b192f0c31c
|
7
|
+
data.tar.gz: 924df7fb51761272d74219c149453cbe048ed28f13d960ea77bed83fbf6893c527a0ef1c32b27ec4795878aaf8d16de0ebd308228bf54e0fd155db9781a8177b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
apu
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 César Ferreira
|
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.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# apu
|
2
|
+
[![Build Status](https://travis-ci.org/cesarferreira/apu.svg?branch=master)](https://travis-ci.org/cesarferreira/apu) [![Gem Version](https://badge.fury.io/rb/apu.svg)](http://badge.fury.io/rb/apu)
|
3
|
+
|
4
|
+
**A**ndroid a**p**plication **u**tils
|
5
|
+
|
6
|
+
> A set of useful tools for android developers
|
7
|
+
|
8
|
+
<p align="center">
|
9
|
+
<img src="https://raw.githubusercontent.com/cesarferreira/apu/master/extras/apu.gif" width="100%" />
|
10
|
+
</p>
|
11
|
+
|
12
|
+
|
13
|
+
## Quick sample
|
14
|
+
Regarding the android project on: `~/Downloads/hello-world`
|
15
|
+
```shell
|
16
|
+
apu --path ~/Downloads/hello-world --install # build and install on your device
|
17
|
+
apu --path ~/Downloads/hello-world --run # build, install and run on your device
|
18
|
+
apu --path ~/Downloads/hello-world --uninstall # uninstall the app
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```shell
|
24
|
+
$ apu -h
|
25
|
+
Usage: apu PATH [OPTIONS]
|
26
|
+
|
27
|
+
Options
|
28
|
+
-k, --package Retrieves package name (eg. com.example.app)
|
29
|
+
-u, --uninstall Uninstalls the apk from your device
|
30
|
+
-i, --install Installs the apk on your device
|
31
|
+
-a, --android-home Checks if the ANDROID_HOME variable is defined
|
32
|
+
-l, --launcher Get the launcher activity path
|
33
|
+
-p, --path PATH Custom path to android project
|
34
|
+
-r, --run Run the build on the device
|
35
|
+
-c, --clear Clear app data
|
36
|
+
```
|
37
|
+
|
38
|
+
## Installation
|
39
|
+
|
40
|
+
$ gem install apu
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cesarferreira/apu.
|
data/Rakefile
ADDED
data/apu.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'apu/version'
|
5
|
+
|
6
|
+
#rake build # Build apu-0.0.1.gem into the pkg directory
|
7
|
+
#rake install # Build and install apu-0.0.1.gem into system gems
|
8
|
+
#rake release # Create tag v0.0.1 and build and push apu-0.0.1.gem t...
|
9
|
+
#rake spec # Run RSpec code examples
|
10
|
+
|
11
|
+
Gem::Specification.new do |spec|
|
12
|
+
spec.name = "apu"
|
13
|
+
spec.version = Apu::VERSION
|
14
|
+
spec.authors = ["cesar ferreira"]
|
15
|
+
spec.email = ["cesar.manuel.ferreira@gmail.com"]
|
16
|
+
|
17
|
+
spec.summary = %q{Android Application Utils}
|
18
|
+
spec.description = %q{Android Application Utils}
|
19
|
+
spec.homepage = "https://apu.com/cesarferreira/apu"
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
spec.bindir = "bin"
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.required_ruby_version = '>= 2.0.0'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.1'
|
30
|
+
spec.add_development_dependency 'rspec'
|
31
|
+
|
32
|
+
spec.add_dependency 'bundler', '~> 1.7'
|
33
|
+
spec.add_dependency 'colorize', '~> 0.7'
|
34
|
+
spec.add_dependency 'nokogiri', '~> 1.6.6.2'
|
35
|
+
|
36
|
+
end
|
data/bin/apu
ADDED
data/extras/apu.gif
ADDED
Binary file
|
data/extras/apu2.gif
ADDED
Binary file
|
data/extras/apu3.gif
ADDED
Binary file
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'tempfile'
|
4
|
+
require 'pry'
|
5
|
+
|
6
|
+
module Apu
|
7
|
+
class AndroidProject
|
8
|
+
def initialize(path)
|
9
|
+
@base_path = "#{path}/"
|
10
|
+
@settings_gradle_path = settings_gradle_file
|
11
|
+
@modules = find_modules
|
12
|
+
path, @execute_command = sample_project #supa hack
|
13
|
+
end
|
14
|
+
|
15
|
+
def execution_line
|
16
|
+
@execute_command
|
17
|
+
end
|
18
|
+
|
19
|
+
def remove_local_properties
|
20
|
+
Dir.chdir @base_path
|
21
|
+
file_name = 'local.properties'
|
22
|
+
|
23
|
+
File.delete(file_name) if File.exist?(file_name)
|
24
|
+
|
25
|
+
system("touch #{file_name}")
|
26
|
+
end
|
27
|
+
|
28
|
+
def remove_application_id
|
29
|
+
# Open temporary file
|
30
|
+
tmp = Tempfile.new("extract")
|
31
|
+
|
32
|
+
file = "#{@path_to_sample}/build.gradle"
|
33
|
+
|
34
|
+
# Write good lines to temporary file
|
35
|
+
open(file, 'r').each { |l| tmp << l unless l.include? 'applicationId' }
|
36
|
+
tmp.close
|
37
|
+
|
38
|
+
# Move temp file to origin
|
39
|
+
FileUtils.mv(tmp.path, file)
|
40
|
+
end
|
41
|
+
|
42
|
+
def settings_gradle_file(path = @base_path)
|
43
|
+
File.join(path, 'settings.gradle')
|
44
|
+
end
|
45
|
+
|
46
|
+
def is_valid(settings_path = @settings_gradle_path)
|
47
|
+
File.exist?(settings_path)
|
48
|
+
end
|
49
|
+
|
50
|
+
def find_modules
|
51
|
+
return [] unless is_valid
|
52
|
+
|
53
|
+
content = File.open(@settings_gradle_path, "rb").read
|
54
|
+
modules = content.scan(/'([^']*)'/)
|
55
|
+
modules.each {|replacement| replacement.first.gsub!(':', '/')}
|
56
|
+
end
|
57
|
+
|
58
|
+
def install
|
59
|
+
Dir.chdir @base_path
|
60
|
+
|
61
|
+
path, execute_line = sample_project
|
62
|
+
|
63
|
+
if path == false and execute_line == false
|
64
|
+
puts "Couldn't open the sample project, sorry!".red
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
|
68
|
+
builder = "gradle"
|
69
|
+
|
70
|
+
if File.exist?('gradlew')
|
71
|
+
system('chmod +x gradlew')
|
72
|
+
|
73
|
+
builder = 'sh gradlew'
|
74
|
+
end
|
75
|
+
|
76
|
+
# Generate the gradle/ folder
|
77
|
+
system('gradle wrap') if File.exist?('gradlew') and !is_gradle_wrapped
|
78
|
+
|
79
|
+
remove_application_id
|
80
|
+
remove_local_properties
|
81
|
+
|
82
|
+
system("#{builder} clean installDebug")
|
83
|
+
|
84
|
+
clear_app_data
|
85
|
+
|
86
|
+
puts "Installing #{@package.green}...\n"
|
87
|
+
|
88
|
+
@execute_line = execute_line
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_execute_line
|
92
|
+
@execute_line
|
93
|
+
end
|
94
|
+
|
95
|
+
def is_gradle_wrapped
|
96
|
+
return false if !File.directory?('gradle/')
|
97
|
+
|
98
|
+
File.exist?('gradle/wrapper/gradle-wrapper.properties') and File.exist?('gradle/wrapper/gradle-wrapper.jar')
|
99
|
+
end
|
100
|
+
|
101
|
+
def sample_project
|
102
|
+
|
103
|
+
@modules.each do |child|
|
104
|
+
full_path = File.join(@base_path, child.first)
|
105
|
+
@path_to_sample = full_path
|
106
|
+
|
107
|
+
execution_line_command = get_execution_line_command(full_path)
|
108
|
+
return full_path, execution_line_command if execution_line_command
|
109
|
+
|
110
|
+
end
|
111
|
+
[false, false]
|
112
|
+
end
|
113
|
+
|
114
|
+
def get_clear_app_command
|
115
|
+
"adb shell pm clear #{@package}"
|
116
|
+
end
|
117
|
+
|
118
|
+
def get_uninstall_command
|
119
|
+
"adb uninstall #{@package}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def get_package_name
|
123
|
+
@package
|
124
|
+
end
|
125
|
+
|
126
|
+
def clear_app_data
|
127
|
+
system(get_clear_app_command)
|
128
|
+
end
|
129
|
+
|
130
|
+
def uninstall_application
|
131
|
+
system(get_uninstall_command) # > /dev/null 2>&1")
|
132
|
+
end
|
133
|
+
|
134
|
+
def get_execution_line_command(path_to_sample)
|
135
|
+
path_to_manifest = File.join(path_to_sample, 'src/main/AndroidManifest.xml')
|
136
|
+
|
137
|
+
if !File.exist?(path_to_manifest)
|
138
|
+
return false
|
139
|
+
end
|
140
|
+
|
141
|
+
f = File.open(path_to_manifest)
|
142
|
+
doc = Nokogiri::XML(f)
|
143
|
+
|
144
|
+
@package = get_package(doc)
|
145
|
+
@launcher_activity = get_launcher_activity(doc)
|
146
|
+
|
147
|
+
if !@launcher_activity
|
148
|
+
return false
|
149
|
+
end
|
150
|
+
|
151
|
+
f.close
|
152
|
+
|
153
|
+
"adb shell am start -n \"#{get_launchable_activity}\" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER"
|
154
|
+
end
|
155
|
+
|
156
|
+
def get_launchable_activity
|
157
|
+
full_path_to_launcher = "#{@package}#{@launcher_activity.gsub(@package,'')}"
|
158
|
+
"#{@package}/#{full_path_to_launcher}"
|
159
|
+
end
|
160
|
+
|
161
|
+
def get_package(doc)
|
162
|
+
doc.xpath("//manifest").attr('package').value
|
163
|
+
end
|
164
|
+
|
165
|
+
def get_launcher_activity(doc)
|
166
|
+
activities = doc.css('activity')
|
167
|
+
activities.each do |child|
|
168
|
+
intent_filter = child.css('intent-filter')
|
169
|
+
if intent_filter != nil and intent_filter.length != 0
|
170
|
+
return child.attr('android:name')
|
171
|
+
end
|
172
|
+
end
|
173
|
+
false
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
data/lib/apu.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'colorize'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'apu/version'
|
5
|
+
require 'apu/android_project'
|
6
|
+
|
7
|
+
module Apu
|
8
|
+
class MainApp
|
9
|
+
def initialize(arguments)
|
10
|
+
|
11
|
+
@app_path = `pwd`.tr("\n","")
|
12
|
+
|
13
|
+
create_options_parser
|
14
|
+
#@url = ['-h', '--help', '-v', '--version'].include?(arguments.first) ? nil : arguments.shift
|
15
|
+
|
16
|
+
@opt_parser.parse!(arguments)
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_options_parser
|
21
|
+
@opt_parser = OptionParser.new do |opts|
|
22
|
+
opts.banner = "Usage: apu PATH [OPTIONS]"
|
23
|
+
opts.separator ''
|
24
|
+
opts.separator "Options"
|
25
|
+
|
26
|
+
opts.on('-k', '--package', 'Retrieves package name (eg. com.example.app)') do |app_path|
|
27
|
+
android_project = get_android_project_object
|
28
|
+
puts android_project.get_package_name.green
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on('-u', '--uninstall', 'Uninstalls the apk from your device') do |app_path|
|
33
|
+
android_project = get_android_project_object
|
34
|
+
android_project.uninstall_application
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on('-i', '--install', 'Installs the apk on your device') do |app_path|
|
39
|
+
android_project = get_android_project_object
|
40
|
+
android_project.install
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on('-a', '--android-home', 'Checks if the ANDROID_HOME variable is defined') do |home|
|
45
|
+
p android_home_is_defined
|
46
|
+
exit
|
47
|
+
end
|
48
|
+
|
49
|
+
opts.on('-l', '--launcher', 'Get the launcher activity path') do |app_path|
|
50
|
+
android_project = get_android_project_object
|
51
|
+
puts android_project.get_launchable_activity.green
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on('-p PATH', '--path PATH', 'Custom path to android project') do |app_path|
|
56
|
+
@app_path = app_path if @app_path != '.'
|
57
|
+
end
|
58
|
+
|
59
|
+
opts.on('-r', '--run', 'Run the build on the device') do |flavour|
|
60
|
+
android_project = get_android_project_object
|
61
|
+
|
62
|
+
android_project.install
|
63
|
+
system(android_project.get_execute_line)
|
64
|
+
exit
|
65
|
+
end
|
66
|
+
|
67
|
+
opts.on('-c', '--clear', 'Clear app data') do |flavour|
|
68
|
+
android_project = get_android_project_object
|
69
|
+
android_project.clear_app_data
|
70
|
+
end
|
71
|
+
|
72
|
+
opts.on('-h', '--help', 'Displays help') do
|
73
|
+
puts opts.help
|
74
|
+
exit
|
75
|
+
end
|
76
|
+
opts.on('-v', '--version', 'Displays version') do
|
77
|
+
puts Apu::VERSION
|
78
|
+
exit
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def android_home_is_defined
|
86
|
+
sdk = `echo $ANDROID_HOME`.gsub("\n",'')
|
87
|
+
!sdk.empty?
|
88
|
+
end
|
89
|
+
|
90
|
+
def get_android_project_object
|
91
|
+
android_project = AndroidProject.new(@app_path)
|
92
|
+
|
93
|
+
# is a valid android project?
|
94
|
+
unless android_project.is_valid
|
95
|
+
puts "#{@app_path.red} is not a valid android project"
|
96
|
+
exit
|
97
|
+
end
|
98
|
+
return android_project
|
99
|
+
end
|
100
|
+
|
101
|
+
def call
|
102
|
+
unless android_home_is_defined
|
103
|
+
puts "\nWARNING: your #{'$ANDROID_HOME'.yellow} is not defined\n"
|
104
|
+
puts "\nhint: in your #{'~/.bashrc'.yellow} add:\n #{"export ANDROID_HOME=\"/Users/cesarferreira/Library/Android/sdk/\"".yellow}"
|
105
|
+
puts "\nNow type #{'source ~/.bashrc'.yellow}\n\n"
|
106
|
+
exit 1
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'tempfile'
|
4
|
+
require 'pry'
|
5
|
+
|
6
|
+
module Apu
|
7
|
+
class AndroidProject
|
8
|
+
def initialize(path)
|
9
|
+
@base_path = "#{path}/"
|
10
|
+
@settings_gradle_path = settings_gradle_file
|
11
|
+
@modules = find_modules
|
12
|
+
path, @execute_command = sample_project #supa hack
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def execution_line
|
17
|
+
@execute_command
|
18
|
+
end
|
19
|
+
|
20
|
+
# def remove_local_properties
|
21
|
+
# Dir.chdir @base_path
|
22
|
+
# file_name = 'local.properties'
|
23
|
+
#
|
24
|
+
# File.delete(file_name) if File.exist?(file_name)
|
25
|
+
#
|
26
|
+
# system("touch #{file_name}")
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# def remove_application_id
|
30
|
+
# # Open temporary file
|
31
|
+
# tmp = Tempfile.new("extract")
|
32
|
+
#
|
33
|
+
# file = "#{@path_to_sample}/build.gradle"
|
34
|
+
#
|
35
|
+
# # Write good lines to temporary file
|
36
|
+
# open(file, 'r').each { |l| tmp << l unless l.include? 'applicationId' }
|
37
|
+
# tmp.close
|
38
|
+
#
|
39
|
+
# # Move temp file to origin
|
40
|
+
# FileUtils.mv(tmp.path, file)
|
41
|
+
# end
|
42
|
+
|
43
|
+
def settings_gradle_file(path = @base_path)
|
44
|
+
File.join(path, 'settings.gradle')
|
45
|
+
end
|
46
|
+
|
47
|
+
def is_valid(settings_path = @settings_gradle_path)
|
48
|
+
File.exist?(settings_path)
|
49
|
+
end
|
50
|
+
|
51
|
+
def find_modules
|
52
|
+
return [] unless is_valid
|
53
|
+
|
54
|
+
content = File.open(@settings_gradle_path, "rb").read
|
55
|
+
modules = content.scan(/'([^']*)'/)
|
56
|
+
modules.each {|replacement| replacement.first.gsub!(':', '/')}
|
57
|
+
end
|
58
|
+
|
59
|
+
def install
|
60
|
+
Dir.chdir @base_path
|
61
|
+
|
62
|
+
path, @execute_line = sample_project
|
63
|
+
|
64
|
+
if path == false and execute_line == false
|
65
|
+
puts "Couldn't open the sample project, sorry!".red
|
66
|
+
exit 1
|
67
|
+
end
|
68
|
+
|
69
|
+
builder = "gradle"
|
70
|
+
|
71
|
+
if File.exist?('gradlew')
|
72
|
+
system('chmod +x gradlew')
|
73
|
+
|
74
|
+
builder = 'sh gradlew'
|
75
|
+
end
|
76
|
+
|
77
|
+
# Generate the gradle/ folder
|
78
|
+
system('gradle wrap') if File.exist?('gradlew') and !is_gradle_wrapped
|
79
|
+
|
80
|
+
puts "Installing #{@package.green}...\n"
|
81
|
+
system("#{builder} clean installDebug")
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_execute_line
|
86
|
+
@execute_line
|
87
|
+
end
|
88
|
+
|
89
|
+
def is_gradle_wrapped
|
90
|
+
return false if !File.directory?('gradle/')
|
91
|
+
|
92
|
+
File.exist?('gradle/wrapper/gradle-wrapper.properties') and File.exist?('gradle/wrapper/gradle-wrapper.jar')
|
93
|
+
end
|
94
|
+
|
95
|
+
def sample_project
|
96
|
+
|
97
|
+
@modules.each do |child|
|
98
|
+
full_path = File.join(@base_path, child.first)
|
99
|
+
@path_to_sample = full_path
|
100
|
+
|
101
|
+
execution_line_command = get_execution_line_command(full_path)
|
102
|
+
return full_path, execution_line_command if execution_line_command
|
103
|
+
|
104
|
+
end
|
105
|
+
[false, false]
|
106
|
+
end
|
107
|
+
|
108
|
+
def get_clear_app_command
|
109
|
+
"adb shell pm clear #{@package}"
|
110
|
+
end
|
111
|
+
|
112
|
+
def get_uninstall_command
|
113
|
+
"adb uninstall #{@package}"
|
114
|
+
end
|
115
|
+
|
116
|
+
def get_package_name
|
117
|
+
@package
|
118
|
+
end
|
119
|
+
|
120
|
+
def clear_app_data
|
121
|
+
system(get_clear_app_command)
|
122
|
+
end
|
123
|
+
|
124
|
+
def uninstall_application
|
125
|
+
system(get_uninstall_command) # > /dev/null 2>&1")
|
126
|
+
end
|
127
|
+
|
128
|
+
def get_execution_line_command(path_to_sample)
|
129
|
+
path_to_manifest = File.join(path_to_sample, 'src/main/AndroidManifest.xml')
|
130
|
+
|
131
|
+
if !File.exist?(path_to_manifest)
|
132
|
+
return false
|
133
|
+
end
|
134
|
+
|
135
|
+
f = File.open(path_to_manifest)
|
136
|
+
doc = Nokogiri::XML(f)
|
137
|
+
|
138
|
+
@package = get_package(doc)
|
139
|
+
@launcher_activity = get_launcher_activity(doc)
|
140
|
+
|
141
|
+
if !@launcher_activity
|
142
|
+
return false
|
143
|
+
end
|
144
|
+
|
145
|
+
f.close
|
146
|
+
|
147
|
+
"adb shell am start -n \"#{get_launchable_activity}\" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER"
|
148
|
+
end
|
149
|
+
|
150
|
+
def get_launchable_activity
|
151
|
+
full_path_to_launcher = "#{@package}#{@launcher_activity.gsub(@package,'')}"
|
152
|
+
"#{@package}/#{full_path_to_launcher}"
|
153
|
+
end
|
154
|
+
|
155
|
+
def get_package(doc)
|
156
|
+
doc.xpath("//manifest").attr('package').value
|
157
|
+
end
|
158
|
+
|
159
|
+
def get_launcher_activity(doc)
|
160
|
+
activities = doc.css('activity')
|
161
|
+
activities.each do |child|
|
162
|
+
intent_filter = child.css('intent-filter')
|
163
|
+
if intent_filter != nil and intent_filter.length != 0
|
164
|
+
return child.attr('android:name')
|
165
|
+
end
|
166
|
+
end
|
167
|
+
false
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
data/lib/apu/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: apu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cesar ferreira
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry-byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.1'
|
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: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: colorize
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.7'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: nokogiri
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.6.6.2
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.6.6.2
|
97
|
+
description: Android Application Utils
|
98
|
+
email:
|
99
|
+
- cesar.manuel.ferreira@gmail.com
|
100
|
+
executables:
|
101
|
+
- apu
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".ruby-gemset"
|
108
|
+
- ".ruby-version"
|
109
|
+
- ".travis.yml"
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- apu.gemspec
|
115
|
+
- bin/apu
|
116
|
+
- extras/apu.gif
|
117
|
+
- extras/apu2.gif
|
118
|
+
- extras/apu3.gif
|
119
|
+
- lib/apk-utils/android_project.rb
|
120
|
+
- lib/apu.rb
|
121
|
+
- lib/apu/android_project.rb
|
122
|
+
- lib/apu/version.rb
|
123
|
+
homepage: https://apu.com/cesarferreira/apu
|
124
|
+
licenses: []
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 2.0.0
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.4.8
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Android Application Utils
|
146
|
+
test_files: []
|