Skip to content

Instantly share code, notes, and snippets.

@hsanchez
Created May 30, 2012 16:56
Show Gist options
  • Save hsanchez/2837606 to your computer and use it in GitHub Desktop.
Save hsanchez/2837606 to your computer and use it in GitHub Desktop.
Automatic installation of multiple apk files.
def config
# in this Rakefile we can allow that
$config ||= Hash.new
end
# ADB command to be invoked when installing *.apk
config['adb'] = 'adb'
# Version
config['version'] = '1.0'
# allows printing/logging as the task is running
STDOUT.sync = true
task :default => [ :all ]
desc 'Install all available apks'
task :install => [ :info ] do
# Iterate over all the apks files in the
# next directory level.
Dir['**/*.apk'].each do |apk|
begin
adb '-e', 'install', '-r', "#{apk}"
print 'I.'
rescue
puts "Unable to install #{apk}"
end
end
end
desc 'Run the ADB shell'
task :shell => [ :info ] do
adb 'shell'
end
desc 'Uninstall all available apks'
task :trash => [ :info ] do
Dir['**/*.apk'].each do |apk|
begin
adb 'shell', 'rm', "#{apk}"
print 'U.'
rescue
puts "Unable to uninstall #{apk}"
end
end
end
desc 'Print configuration'
task :info do
puts "APK Installer Configuration: #{config.inspect}"
puts "APK Installer Version: #{config['version']}"
end
# adb command
def adb(*args)
raise unless config['adb']
invoke(config['adb'], args)
end
# Invoke the actual Android's command
def invoke(command, *arguments)
args = arguments.flatten.map {|arg| "'#{arg}'"}.join(' ')
system = "#{command} #{args}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment