Android Debug Bridge (ADB) wrapper using Android SDK Tools Library with Rjb
Android Debug Bridge (ADB) wrapper using Android SDK Tools Library with Rjb
# Install Rjb
$ export JAVA_HOME=<your java home path>
$ gem install rjb
# Install adb-sdklib
$ gem install adb-sdklib
require 'adb-sdklib'
adb = AdbSdkLib::Adb.new
# If 'adb' command-line tool isn't in your $PATH, set adb location to constructor shown as below
# adb = AdbSdkLib::Adb.new('/path/to/adb')
# Get device objects
devices = adb.devices
Adb object is wrapper of com.android.ddmlib.AndroidDebugBridge.
Source code of com.android.ddmlib.AndroidDebugBridge:
https://android.googlesource.com/platform/tools/base/+/master/ddmlib/src/main/java/com/android/ddmlib/AndroidDebugBridge.java
Some methods of AndroidDebugBridge are wrapped for Ruby.
For remaining methods, Adb#method_missing is defined to call
wrapping java object’s same name method using specified parameters.
adb = AdbSdkLib::Adb.new
device = adb.devices.first
# device = adb.devices['xxxxxx'] # get by the device's serial number.
# Display attributes
puts <<"EOS"
serial : #{device.serial}
state : #{device.state}
emulator : #{device.emulator?}
build ver : #{device.build_version}
api level : #{device.api_level}
device model : #{device.device_model}
manufacturer : #{device.manufacturer}
EOS
# Push a file to the device
device.push('local.txt', '/data/local/tmp/')
# Pull a file from the device
device.pull('/system/build.prop', '/path/to/dir/')
# Execute shell
puts device.shell('ps') # display results
device.shell('ls /data/local/tmp/') { |line| # each line
puts line
}
Device object is wrapper of com.android.ddmlib.Device.
Source code of com.android.ddmlib.Device:
https://android.googlesource.com/platform/tools/base/+/master/ddmlib/src/main/java/com/android/ddmlib/Device.java
Some methods of ddmlib.Device are wrapped for Ruby.
For remaining methods, Device#method_missing is defined to call
wrapping java object’s same name method using specified parameters.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)