Editor’s note: below is a blog post from Justin Jasmann, Android Application Development Consultant. Follow him on Twitter at JustinJasmann .
<img data-attachment-id="16663" data-permalink="http://devblog.blackberry.com/2013/11/pull-android-logs-from-your-blackberry/log_cat/" data-orig-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/log_cat.jpg" data-orig-size="410,410" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":""}" data-image-title="log_cat" data-image-description="" data-medium-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/log_cat.jpg?w=300" data-large-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/log_cat.jpg?w=410" class="aligncenter size-full wp-image-16663" alt="log_cat" src="http://rimdevblog.files.wordpress.com/2013/11/log_cat.jpg?w=800" srcset="http://rimdevblog.files.wordpress.com/2013/11/log_cat.jpg 410w, http://rimdevblog.files.wordpress.com/2013/11/log_cat.jpg?w=150 150w, http://rimdevblog.files.wordpress.com/2013/11/log_cat.jpg?w=300 300w" sizes="(max-width: 410px) 100vw, 410px" />
Imagine this: You’ve got your Android app running well on BlackBerry 10 (that’s awesome by the way), but there’s a small piece that’s not working quite right. How exactly do you go about diagnosing the problem?
As James Dreher pointed out in his post about the 2.0 Command-Line Tools, you can connect your BlackBerry device to whichever IDE you’re most comfortable with. In order to gain access to the LogCat information from there, you can simply debug the Android project, as you would during normal development.
Now I know what you’re thinking: “What if you no longer have the project source?” That’s what I’m here to show you. Today, we’re going to pull the Android logs from your BlackBerry device directly. There are a few things that you’ll need before we start, so make sure you have these ready:
Android SDK Command-Line Tools v2.0 An SSH public-key which will represent the host computer that you’re connecting your device to Note: The easiest way to get a public key created for you is to use Momentics to setup an SSH connection. The rest of the tutorial will use a key that was created for the device via Momentics.
Also note: If you’re having problems creating a public key, you can follow this tutorial .
Let’s get started!
Establish a secure connection to your device using blackberry-connect <img data-attachment-id="16664" data-permalink="http://devblog.blackberry.com/2013/11/pull-android-logs-from-your-blackberry/establish-a-secure-connection-to-your-device-using-blackberry-connect/" data-orig-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/establish-a-secure-connection-to-your-device-using-blackberry-connect.jpg" data-orig-size="600,286" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":""}" data-image-title="establish a secure connection to your device using blackberry connect" data-image-description="" data-medium-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/establish-a-secure-connection-to-your-device-using-blackberry-connect.jpg?w=300" data-large-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/establish-a-secure-connection-to-your-device-using-blackberry-connect.jpg?w=600" class="aligncenter size-full wp-image-16664" alt="establish a secure connection to your device using blackberry connect" src="http://rimdevblog.files.wordpress.com/2013/11/establish-a-secure-connection-to-your-device-using-blackberry-connect.jpg?w=800" srcset="http://rimdevblog.files.wordpress.com/2013/11/establish-a-secure-connection-to-your-device-using-blackberry-connect.jpg 600w, http://rimdevblog.files.wordpress.com/2013/11/establish-a-secure-connection-to-your-device-using-blackberry-connect.jpg?w=150 150w, http://rimdevblog.files.wordpress.com/2013/11/establish-a-secure-connection-to-your-device-using-blackberry-connect.jpg?w=300 300w" sizes="(max-width: 600px) 100vw, 600px" />
With blackberry-connect running, open a new terminal or command-prompt <img data-attachment-id="16665" data-permalink="http://devblog.blackberry.com/2013/11/pull-android-logs-from-your-blackberry/with-blackberry-connect-running-open-a-new-terminal-or-command-prompt/" data-orig-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/with-blackberry-connect-running-open-a-new-terminal-or-command-prompt.jpg" data-orig-size="600,297" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":""}" data-image-title="with blackberry connect running open a new terminal or command prompt" data-image-description="" data-medium-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/with-blackberry-connect-running-open-a-new-terminal-or-command-prompt.jpg?w=300" data-large-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/with-blackberry-connect-running-open-a-new-terminal-or-command-prompt.jpg?w=600" class="aligncenter size-full wp-image-16665" alt="with blackberry connect running open a new terminal or command prompt" src="http://rimdevblog.files.wordpress.com/2013/11/with-blackberry-connect-running-open-a-new-terminal-or-command-prompt.jpg?w=800" srcset="http://rimdevblog.files.wordpress.com/2013/11/with-blackberry-connect-running-open-a-new-terminal-or-command-prompt.jpg 600w, http://rimdevblog.files.wordpress.com/2013/11/with-blackberry-connect-running-open-a-new-terminal-or-command-prompt.jpg?w=150 150w, http://rimdevblog.files.wordpress.com/2013/11/with-blackberry-connect-running-open-a-new-terminal-or-command-prompt.jpg?w=300 300w" sizes="(max-width: 600px) 100vw, 600px" />
Navigate to the platform-tools directory of your Android SDK. We will be using the adb utility that’s included with the SDK. <img data-attachment-id="16666" data-permalink="http://devblog.blackberry.com/2013/11/pull-android-logs-from-your-blackberry/navigate-to-the-platform-tools-directory-of-your-android-sdk/" data-orig-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/navigate-to-the-platform-tools-directory-of-your-android-sdk.jpg" data-orig-size="600,297" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":""}" data-image-title="navigate to the platform tools directory of your android sdk" data-image-description="" data-medium-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/navigate-to-the-platform-tools-directory-of-your-android-sdk.jpg?w=300" data-large-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/navigate-to-the-platform-tools-directory-of-your-android-sdk.jpg?w=600" class="aligncenter size-full wp-image-16666" alt="navigate to the platform tools directory of your android sdk" src="http://rimdevblog.files.wordpress.com/2013/11/navigate-to-the-platform-tools-directory-of-your-android-sdk.jpg?w=800" srcset="http://rimdevblog.files.wordpress.com/2013/11/navigate-to-the-platform-tools-directory-of-your-android-sdk.jpg 600w, http://rimdevblog.files.wordpress.com/2013/11/navigate-to-the-platform-tools-directory-of-your-android-sdk.jpg?w=150 150w, http://rimdevblog.files.wordpress.com/2013/11/navigate-to-the-platform-tools-directory-of-your-android-sdk.jpg?w=300 300w" sizes="(max-width: 600px) 100vw, 600px" />
Connect to the Android Runtime on BlackBerry 10 using adb connect 169.254.0.1 <img data-attachment-id="16667" data-permalink="http://devblog.blackberry.com/2013/11/pull-android-logs-from-your-blackberry/connect-to-the-android-runtime-on-blackberry-10/" data-orig-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/connect-to-the-android-runtime-on-blackberry-10.jpg" data-orig-size="600,297" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":""}" data-image-title="connect to the android runtime on blackberry 10" data-image-description="" data-medium-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/connect-to-the-android-runtime-on-blackberry-10.jpg?w=300" data-large-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/connect-to-the-android-runtime-on-blackberry-10.jpg?w=600" class="aligncenter size-full wp-image-16667" alt="connect to the android runtime on blackberry 10" src="http://rimdevblog.files.wordpress.com/2013/11/connect-to-the-android-runtime-on-blackberry-10.jpg?w=800" srcset="http://rimdevblog.files.wordpress.com/2013/11/connect-to-the-android-runtime-on-blackberry-10.jpg 600w, http://rimdevblog.files.wordpress.com/2013/11/connect-to-the-android-runtime-on-blackberry-10.jpg?w=150 150w, http://rimdevblog.files.wordpress.com/2013/11/connect-to-the-android-runtime-on-blackberry-10.jpg?w=300 300w" sizes="(max-width: 600px) 100vw, 600px" />
If you want to output the current contents of the log buffer to a file, use: adb logcat –d > logfile.log <img data-attachment-id="16668" data-permalink="http://devblog.blackberry.com/2013/11/pull-android-logs-from-your-blackberry/if-you-want-to-output-the-current-contents-of-the-log-file/" data-orig-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/if-you-want-to-output-the-current-contents-of-the-log-file.jpg" data-orig-size="600,310" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":""}" data-image-title="if you want to output the current contents of the log file" data-image-description="" data-medium-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/if-you-want-to-output-the-current-contents-of-the-log-file.jpg?w=300" data-large-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/if-you-want-to-output-the-current-contents-of-the-log-file.jpg?w=600" class="aligncenter size-full wp-image-16668" alt="if you want to output the current contents of the log file" src="http://rimdevblog.files.wordpress.com/2013/11/if-you-want-to-output-the-current-contents-of-the-log-file.jpg?w=800" srcset="http://rimdevblog.files.wordpress.com/2013/11/if-you-want-to-output-the-current-contents-of-the-log-file.jpg 600w, http://rimdevblog.files.wordpress.com/2013/11/if-you-want-to-output-the-current-contents-of-the-log-file.jpg?w=150 150w, http://rimdevblog.files.wordpress.com/2013/11/if-you-want-to-output-the-current-contents-of-the-log-file.jpg?w=300 300w" sizes="(max-width: 600px) 100vw, 600px" />
If you’d rather watch the logs live, you can use: adb logcat <img data-attachment-id="16669" data-permalink="http://devblog.blackberry.com/2013/11/pull-android-logs-from-your-blackberry/if-youd-rather-watch-the-logs-live/" data-orig-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/if-youd-rather-watch-the-logs-live.jpg" data-orig-size="600,461" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":""}" data-image-title="if you’d rather watch the logs live" data-image-description="" data-medium-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/if-youd-rather-watch-the-logs-live.jpg?w=300" data-large-file="/content/dam/devblog-blackberry-com/images/blogs/2013/11/if-youd-rather-watch-the-logs-live.jpg?w=600" class="aligncenter size-full wp-image-16669" alt="if you'd rather watch the logs live" src="http://rimdevblog.files.wordpress.com/2013/11/if-youd-rather-watch-the-logs-live.jpg?w=800" srcset="http://rimdevblog.files.wordpress.com/2013/11/if-youd-rather-watch-the-logs-live.jpg 600w, http://rimdevblog.files.wordpress.com/2013/11/if-youd-rather-watch-the-logs-live.jpg?w=150 150w, http://rimdevblog.files.wordpress.com/2013/11/if-youd-rather-watch-the-logs-live.jpg?w=300 300w" sizes="(max-width: 600px) 100vw, 600px" />
And that’s it! Simple, right? Let us know if you have any questions in the comments below!