lib/acouchi/apk_modifier.rb in acouchi-0.0.2 vs lib/acouchi/apk_modifier.rb in acouchi-0.0.3
- old
+ new
@@ -3,14 +3,13 @@
module Acouchi
class ApkModifier
def initialize apk
@apk = apk
- @apk_tool = `which apktool`.strip
@output_path = "#{Dir.tmpdir}/#{SecureRandom.uuid}/"
- if @apk_tool.empty?
+ unless apktool
puts "Couldn't find a valid apktool. Please install apktool from http://code.google.com/p/android-apktool/"
exit
end
end
@@ -27,25 +26,40 @@
throw "modify_manifest takes a block"
end
end
private
- def apktool command
- puts "#{@apk_tool} #{command}"
- system "#{@apk_tool} #{command}"
+ def apktool
+ @apktool ||= Which.find_executable("apktool.bat", "apktool")
end
+ def execute_apktool command
+ ProcessLauncher.new(apktool, command)
+ end
+
def decompile_apk
- apktool "d #{@apk} #{@output_path}"
+ ProcessLauncher.new(apktool, "d", @apk, @output_path).start_and_crash_if_process_fails
end
def compile_apk
- apktool "b #{@output_path}"
+ ProcessLauncher.new(apktool, "b", @output_path).start_and_crash_if_process_fails
end
def sign_apk_in_debug_mode
@new_apk = File.join(@output_path, "dist", File.basename(@apk))
- system "jarsigner -keystore ~/.android/debug.keystore -storepass android -keypass android #{@new_apk} androiddebugkey"
+ jarsigner = Which.which?("jarsigner.exe") || Which.which?("jarsigner")
+ debug_keystore = File.join(ENV["HOME"], ".android", "debug.keystore")
+ ProcessLauncher.new(
+ jarsigner,
+ "-keystore",
+ debug_keystore,
+ "-storepass",
+ "android",
+ "-keypass",
+ "android",
+ @new_apk,
+ "androiddebugkey"
+ ).start_and_crash_if_process_fails
end
def overwrite_original_apk
FileUtils.mv(@new_apk, @apk)
end