------------ Wellcome bdinfo190.blogspot.com ------------ Wellcome bdinfo190.blogspot.com-------------

Android Studio for beginners, Part 4: Debugging tools and productivity plugins- নতুনদের জন্য অ্যান্ড্রয়েড স্টুডিও, অংশ 4: ডিবাগিং সরঞ্জাম এবং উত্পাদনশীলতা প্লাগইন

Android_Studio_icon.svghttpsbdinfo190.blogspot.com
Android_Studio_icon.svghttpsbdinfo190.blogspot.com
Android Studio offers an upscale palette of inbuilt development tools, and a good additional well endowed plugin system. the primary 3 articles during this series centered on installation and setup and writing and running a straightforward mobile app with automaton Studio. currently you will get conversant in a number of the additional advanced tools: 3 inbuilt tools and 3 plugins for debugging and rising the standard and productivity of your automaton application code.

This article introduce the subsequent tools for automaton Studio:

[ Learn Java from starting ideas to advanced style patterns during this comprehensive 12-part course! ]
Built-in debugging tools

Logcat
Debug
Lint
Plugins for developer productivity

ADB Idea
Codota
Lombok Plugin
What's new in automaton Studio three
Find out what to seem for within the latest version of automaton Studio, together with support for Kotlin, Java 8, and a wealth of recent tools and plugins.

Logging and debugging automaton apps
A buggy app may be a positive thanks to run off potential customers. Logcat and right area unit 2 tools that come back inbuilt to automaton Studio, that you'll use to spot and fix bugs in your automaton code.

Logging Android: Logcat
You might not want or need a full-blown program for each "buggy" situation. In some cases it's spare to log and proper the values of sure variables. automaton Studio's Logcat is ideal for this task.

Logcat may be a command-line tool (integrated into automaton right Bridge -- ADB) that dumps a log of system messages that may assist you realize and fix issues in your code. Messages embrace stack traces for once the device throws a mistake, and log messages that you've got purposefully embedded with the automaton.util.Log class. Logcat is therefore helpful it has been integrated directly into automaton Studio, wherever you'll access it from the read menu or the tool window bar.

figure1
Jeff Friesen
Figure 1. The Logcat window reveals an inventory of date-and-time-stamped system messages (click to enlarge)
The Logcat window is split into a horizontal row of drop-down lists and different controls followed by a message space. From left-to-right, the controls are:

A drop-down list characteristic connected devices and emulators. (See Figure one.)
A drop-down list characteristic put in APK packages on the chosen device.
A drop-down list of work levels:
Verbose: show all messages.
Debug: show right log messages that area unit helpful throughout development solely, yet because the message levels lower within the drop-down list.
Info: show expected log messages for normal usage, yet because the message levels lower within the drop-down list.
Warn: show doable problems that aren't nevertheless errors, yet because the message levels lower within the drop-down list.
Error: show problems that have caused errors -- thrown exceptions, yet because the Assert message level.
Assert: show problems that the developer expects ought to ne'er happen.
A search bar wherever the sole messages that seem area unit those containing the text you kind during this management.
A check box that enables you to use regular expressions within the search bar. as an example, within the context of Figure one, you would possibly specify SystemClock | AlarmManager (i.e., the message should contain either word).
A drop-down list for filtering messages, together with the subsequent options:
No Filters (the default) causes all messages for the chosen device to seem, notwithstanding the chosen APK package.
Show solely designated application presents solely those messages for the chosen APK package on the chosen device, that area unit of the suitable log level or lower.
Edit Filter Configuration enables you to produce a custom filter.
In the ASCII text file, you'll insert calls to varied automaton.util.Log strategies to log messages. as an example, you would possibly decision public static int i(String tag, String msg) to log Associate in Nursing INFO-level message, or public static int w(String tag, String msg) to log a WARN-level message.

For either methodology, the string passed to tag identifies the message's supply (e.g., {the methodology|the tactic|the strategy} during which this work method was called), and therefore the string passed to MSG identifies the message being logged.

Alternatively, you may decision System.out's and System.err's print() and println() strategies. Calls to the System.out strategies accomplish identical factor as log.i() calls; calls to the System.err strategies accomplish identical factor as log.w() calls.

figure2
Jeff Friesen
Figure 2. work messages within the onCreate() methodology of the instance app's main activity (click to enlarge)
In Figure two, the sole displayed messages area unit for the instance app method running on the emulated Nexus 5X device. moreover, these messages should contain onCreate and be accepted by the Show solely designated application filter.

More concerning Logcat
Check out Google's "Write {and view|and consider|and think concerning|and look at|and examine} Logs with Logcat" to find out additional about Logcat. conjointly study the automaton.util.Log class's documentation.

Debugging Android: right
Using Logcat to log and proper code is okay for terribly easy apps. For additional difficult apps, this kind of debugging will be tedious. Instead you will need one thing that enables you to right the app's workable code. automaton Studio's inbuilt right tool offers several capabilities, together with the following:

Select a tool on that to right your app.
Set breakpoints in your application code (Java, Kotlin, or C/C++).
Examine variables and measure expressions at runtime.
There area unit some stipulations before exploitation this debugging tool:

If your app includes C/C++ ASCII text file, you'll have to put in LLDB from the SDK Manager (see Figure 3). luckily, the instance app for this series (W2A) does not contain C/C++ code, therefore we are able to ignore this necessity.

figure3
Jeff Friesen
Figure 3. Check the LLDB check box and click on okay to install LLDB (click to enlarge)
You must modify debugging on a connected device. However, if {you're|you area unit} exploitation Associate in Nursing person (which we tend to are for this example), you'll ignore this necessity. Debugging is enabled by neglect emulated devices.
You must run a debuggable build variant. By default, this is often created for you, therefore in several cases (including this example) you do not ought to worry concerning it.
Let's run through a fast debugging session.

Simple automaton debugging
Assuming you are running automaton Studio with the editor window for the instance app (W2A.java) open, your beginning is to line a breakpoint on the general public void onCreate(Bundle savedInstanceState) line. Set the breakpoint by lightness this line and doing one in every of the following:

Click the gutter space to the left of the road; the line ought to flip pink in response.
Select Toggle Line Breakpoint from the Run menu.
Press Ctrl and F8 at the same time.
Now choose right 'app' from the Run menu, or click the suitable icon on the tool bar. If the person is not running, you may observe the choose readying Target window. I designated Nexus 5X API fifteen and clicked OK.

While you are looking forward to the emulated device to come back on-line, click the right button on the tool-window bar to show the right window. Eventually, you ought to see one thing like Figure four.

figure4
Jeff Friesen
Figure 4. The right window reveals stack frames, current variables with their current values, and additional (click to enlarge)
The right window provides icons for stepping over, into, and out of a way, and more. Figure five shows what happens once we step over a way.

figure5
Jeff FriesenFigure five. you'll step over, into, and out of a way
Click the suitable icon and choose Step Over from the Run menu, or press F8. This lets U.S. proceed deeper into the onCreate() methodology whereas stepping over every methodology decision.

Select the road with the closing } character for the onCreate() methodology, then choose Run to indicator. you may receive a notice that the applying is running. once unlocking the device, you ought to see the instance app's activity window.

figure6
Jeff Friesen
Figure 6. Click the highest 3 icons to the left of the program tab to resume, pause, and stop the app, severally (click to enlarge)
More concerning right
Check out Google's "Debug your app" to find out additional concerning debugging in automaton Studio; as an example, a way to use varied varieties of breakpoints.

Debugging with GAPID
While not lined here, i like to recommend searching for GAPID: Graphics API program, a group of debugging tools that permit you examine, tweak, Associate in Nursingd replay calls from an automaton app to a graphics driver.

Code scrutiny with Lint
No matter however fastidiously you write it, your ASCII text file is probably going to contain bugs, rhetorical problems, and will reference resources that area unit inactive for one reason or another. A linter may be a variety of tool that scans ASCII text file for proof of those and different bits of nasty fluff, that it reports to the developer.

Lint may be a inbuilt linter for automaton SDK. you'll use it to find problems like deprecated components and API calls that are not supported by your target API.

To run Lint from inside automaton Studio, choose examine Code... from the Analyze menu. Doing therefore activates the Specify scrutiny Scope window.

figure7
Jeff Friesen
Figure 7. Setting to examine the complete project (click to enlarge)
From the window, choose the specified scope (entire project, during this case), then click okay to begin the scrutiny. The results can seem within the scrutiny Results window, wherever they are organized by class.

figure8
Jeff Friesen
Figure 8. Not shown area unit 2 writing system mistakes: Lint does not like 'javajeff' (click to enlarge)
True to its nature, Lint has picked out many items of fluff that might otherwise litter the applying code. Once noticed, it is simple to mend the 3 Java warnings shown in Figure 8: merely declare androidAnimation personal and take away the casts from the 2 findViewById() methodology calls.

More concerning Lint
Check out "Improve your code with lint checks" to find out additional concerning exploitation Lint in automaton Studio, and to find out concerning the automaton SDK's standalone Lint tool.

Installing and exploitation automaton Studio plugins
While inbuilt tools have their advantage, several different tools area unit offered as plugins. during this section, we'll check out 3 plugins for rising the productivity of your writing in automaton Studio:

ADB Idea
Codota
Lombok Plugin
Android Studio plugins manager
Android Studio's plugins manager makes it terribly straightforward to search out and install plugins. Activate the plugins manager by choosing File > Settings followed by Plugins from the Settings dialog box:

figure9
Jeff Friesen
Figure 9. The Settings window shows all put in plugins (click to enlarge)
Next, click Browse repositories... to activate the Browse Repositories window, that presents a full list of supported plugins. We'll use this dialog to pick our 1st plugin, ADB Idea.

figure10
Jeff Friesen
Figure 10. The pane on the proper presents elaborate data concerning the chosen plugin (click to enlarge)
Boost your automaton productivity
Code shortcuts: ADB plan
ADB plan quickens every day automaton development by providing quick access to ordinarily used ADB commands, like beginning Associate in Nursingd uninstalling an app.

Select ADB plan within the repository list of plugins, then click the Install button. automaton Studio takings to transfer and install the plugin. It then relabels Install to Restart automaton Studio. for every plugin, I had to reselect the plugin once clicking Restart automaton Studio, then click this button a second time so as to restart automaton Studio.

figure11
Jeff Friesen
Figure 11. Install ADB plan (click to enlarge)
Once put in, automaton Studio enables you to access ADB plan from its Tools menu. choose Tools > ADB plan and opt for the suitable command from the ensuing pop-up menu.

figure12
Jeff Friesen
Figure 12. choose the suitable ADB command from the pop-up menu (click to enlarge
After I designated ADB Restart App, I determined the subsequent messages within the Event Log window yet because the restarted app on my Amazon Kindle device.

figure13
Jeff FriesenFigure thirteen. every message identifies the app, operation, and device
Find usable code: Codota
You can use the Codota plugin to access the Codota computer programme, that enables you to peruse several in public offered Java ASCII text file snippets for solutions to automaton writing issues.

figure14
Jeff Friesen
Figure 14. Install Codota (click to enlarge)
Select Codota within the repository list of plugins then click the Install button. once automaton Studio has downloaded and put in the plugin, it'll re-label the Install button to Restart automaton Studio. Restarting activates Codota.

Upon restart, you may encounter the Codota Authentication window. Click the link and follow directions to receive the token. Then, paste the token into the same window and click on Go.


figure15
Jeff Friesen
Figure 15. Enter the authentication token and click on OK (click to enlarge)
Android Studio enables you to access Codota by right-clicking on Java code within the editor window and choosing the Get relevant examples menu item, as shown in Figure sixteen.

figure16
Jeff Friesen
Figure 16. Click 'Get relevant examples' (click to enlarge)
Clicking this menu item leads to the browser presenting a page with relevant code examples. as an example, the subsequent page presents examples that area unit relevant to findViewById:


figure17
Jeff Friesen
Figure 17. The browser presents relevant examples for the highlighted findViewById text (click to enlarge)
Autogenerate Java code: Lombok
Project Lombok offers a group of annotations that you just will use in situ of boilerplate code, so saving you time writing out this code by hand.

No comments

Powered by Blogger.