Class: DeviceAPI::Android::Signing
- Inherits:
-
Execution
- Object
- Execution
- DeviceAPI::Android::Signing
- Defined in:
- lib/device_api/android/signing.rb
Overview
Namespace for all methods encapsulating adb calls
Class Method Summary collapse
-
.generate_keystore(options = {}) ⇒ Boolean, Exception
Creates a keystore used for signing apks.
-
.is_apk_signed?(apk_path) ⇒ Boolean
Checks to see if an apk has already been signed.
-
.sign_apk(options = {}) ⇒ Boolean, Exception
Signs an apk using the specified keystore.
-
.unsign_apk(apk_path) ⇒ Boolean, Exception
Removes any previous signatures from an apk.
Class Method Details
.generate_keystore(options = {}) ⇒ Boolean, Exception
Creates a keystore used for signing apks
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/device_api/android/signing.rb', line 15 def self.generate_keystore( = {}) keystore = [:keystore] || '~/.android/debug.keystore' alias_name = [:alias] || 'androiddebugkey' dname = [:dname] || 'CN=hive' password = [:password] || 'android' result = execute("keytool -genkey -noprompt -alias #{alias_name} -dname '#{dname}' -keystore #{keystore} -storepass #{password} -keypass #{password} -keyalg RSA -keysize 2048 -validity 10000") raise SigningCommandError.new(result.stderr) if result.exit != 0 true end |
.is_apk_signed?(apk_path) ⇒ Boolean
Checks to see if an apk has already been signed
56 57 58 59 60 |
# File 'lib/device_api/android/signing.rb', line 56 def self.is_apk_signed?(apk_path) result = execute("aapt list #{apk_path} | grep '^META-INF\/.*'") return false if result.stdout.empty? true end |
.sign_apk(options = {}) ⇒ Boolean, Exception
Signs an apk using the specified keystore
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/device_api/android/signing.rb', line 35 def self.sign_apk( = {}) apk = [:apk] alias_name = [:alias] || 'androiddebugkey' keystore = [:keystore] || '~/.android/debug.keystore' keystore_password = [:keystore_password] || 'android' resign = [:resign] # Check to see if the APK has already been signed if is_apk_signed?(apk) return false unless resign unsign_apk(apk) end generate_keystore({ keystore: keystore, password: keystore_password, alias_name: alias_name }) unless File.exists?(File.(keystore)) result = execute("jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore #{File.(keystore)} -storepass #{keystore_password} #{apk} #{alias_name}") raise SigningCommandError.new(result.stderr) if result.exit != 0 true end |
.unsign_apk(apk_path) ⇒ Boolean, Exception
Removes any previous signatures from an apk
65 66 67 68 69 70 |
# File 'lib/device_api/android/signing.rb', line 65 def self.unsign_apk(apk_path) file_list = execute("aapt list #{apk_path} | grep '^META-INF\/.*'") result = execute("aapt remove #{apk_path} #{file_list.stdout.split(/\s+/).join(' ')}") raise SigningCommandError.new(result.stderr) if result.exit != 0 true end |