Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Android-8 Imran Shafi. Lecture Contents  Debugging Android Projects  Java/XML Errors  Debugger  Logcat Utility  Android Debug Bridge (adb) 

Similar presentations


Presentation on theme: "Java Android-8 Imran Shafi. Lecture Contents  Debugging Android Projects  Java/XML Errors  Debugger  Logcat Utility  Android Debug Bridge (adb) "— Presentation transcript:

1 Java Android-8 Imran Shafi

2 Lecture Contents  Debugging Android Projects  Java/XML Errors  Debugger  Logcat Utility  Android Debug Bridge (adb)  Dalvik Debug Monitor Service(DDMS)  Traceview

3 New Project  Create a new project  Provide project configuration  Everything goes fine (nothing wrong with configuration)

4 New Project Window

5 Oops Something Went Wrong (What?)

6 Error Identification

7 Xml Error

8 Fixing Given Error

9 Take Care of Imports

10 Coding Problems

11 Correcting Source Code

12 Output…. Whats Wrong Now?

13 Check Manifest

14 Check Again

15 Output…. Problem Still There….

16 Try This …

17 Output

18 What did we learn?  XML Problems  Source Code Problems  Manifest Entries  API Problems  Protocols  ….

19 Exception While navigating through any application one can come across some exception Exception screen with force close option

20 Logcat Eclipse IDE  Window (Menu)  Show View  Other  Android  Logcat Information Shown: Time, pid, tag, Message

21 Logcat Commands V (Verbose) Shows everything D (Debug) Shows debug info, warnings, errors I (Information) Shows information, warnings, errors W (Warning) Shows warnings and errors E (Error) Shows errors

22 How to Log?  To write your own entries from your application into logcat, Android provides methods corresponding to the different entry priorities. The methods are all of the form: Log.x(String tag, String message, [Throwable exception]) Where x can be either v,d,I,w,e Example: try { mc.animateTo(mMyLocationOverlay.getMyLocation()); } catch (Exception e) { Log.i("MicroJobs", "Unable to animate map", e); } mvMap.invalidate();

23 Android Debug Bridge (ADB)  Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device. It is a client- server program that includes three components: 1) A client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients. 2) A server, which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device. 3) A daemon, which runs as a background process on each emulator or device instance.

24 ADB Client/Server Modules  Find adb tool in /platform-tools/  An adb client when starts first checks whether there is an adb server process already running. If not, it starts the server process. Server binds itlself to local TCP port 5037 and listens for commands sent from adb clients  Server then sets up connections to all running emulator/device instances. It locates emulator/device instances by scanning odd- numbered ports in the range 5555 to 5585 (the range used by emulators/devices). Where the server finds an adb daemon, it sets up a connection to that port. Note: Each emulator/device instance acquires a pair of sequential ports — an even-numbered port for console connections and an odd-numbered port for adb connections. For example: Emulator 1, console: 5554; Emulator 1, adb: 5555 Emulator 2, console: 5556; Emulator 2, adb: 5557 …

25 ADB Commands adb [-d|-e|-s ]

26 List Devices adb devices Displays a list of devices and emulators that the adb server knows about. This is a good way to find the TCP/IP port for an emulator or device if you don't already know it. The port number is also displayed in the title of each emulator at the top of its window.

27 Device Prompt adb shell This connects you with a shell running on the target and gives you a # prompt. The shell is a simplified Unix-like shell, so you can use the usual shell commands (ls, cat, rm, ps, etc.) to explore the target and make changes as appropriate. Ctrl-D or exit will get you out of the shell and back to your environment on the host.

28 Install New Package  adb install [-l] [-r] package This can be used to install or reinstall an application i. The -l option forward-locks the installation (preventing the application from being copied later to another device) ii. The -r option reinstalls the application without overwriting the existing application data. iii. The package must be a valid, signed.apk file for the application to be installed.

29 Uninstall a package adb uninstall [-k] package  This uninstalls the application with the given package name. The package parameter needs to be the full name of the package, without the ".apk" extension. So to uninstall TestProject, for example, you'd type: adb uninstall com.test.mytestproject If you want to keep the application's associated data, you include the -k option

30 Push to Device  adb pushlocal remote This command copies a file from the local name on the host to the remote name on the target.

31 Pull from Device  adb pullremote local This is the counterpart to the previous command, and copies a file from the target to the host.

32 DDMS: Dalvik Debug Monitor Service

33

34

35 Traceview  Maybe the problem you're trying to debug isn't about functionality  Maybe your application does exactly what it's supposed to do, but takes too long to do it  Wouldn't it be nice to have a way of seeing how the methods within your classes are interacting, and even to keep track of the relative time spent executing in each method?  Traceview is a utility that allow you just that kind of visibility.  It consists of two parts, one that you enable before running your program and one that you work with after the run in order to diagnose your findings:

36 Runtime Data Collection  One can enable and disable logging for his application  While enabled, routines are linked into application that create a binary trace file on the target  The trace file records every method instantiation and the time spent in each method

37 Trace Analysis  If you copy the binary trace file from the target to your host, you can run a trace analysis program that displays all the information from the file in graphical form  You can easily observe which methods are consuming most of the runtime, and drill down into those methods to find out which methods they in turn call and which of them consume the most time.

38 Collecting Trace Data  The routines to perform trace data collection are provided in the Android Software Development Kit  All you have to do is: 1. Import the Debug package (android.os.Debug) into your application. 2. Call startMethodTracing when you want to start collecting trace information. 3. Call stopMethodTracing when you're done.

39 Collecting Trace Data  The tracing routines always write their trace information to a file on the target's SD card. If you're running on a real device, you need to plug in an SD card. If you're debugging on the emulator, you need to create a virtual SD card and tell the emulator to use it:  Create a virtual SD card with mksdcard.

40 Create SD Card  From the host command prompt, use the mksdcard utility to create a file that the emulator can use as a virtual SD card:  $ mksdcard -l ANDROID 1024M filename You can create the file anywhere you like, but the root directory for your project is a good place. The utility will allocate a file as big as the size you've given in the mksdcard command (1 GB in the example shown).

41 Use SD Card  Tell the emulator to use the virtual SD card.  In Eclipse, choose Window Preferences Android Launch. You'll see a box there for emulator options. Add the following option:  -sdcard filename Use the complete path to the file, so the emulator can always find it, no matter where it's running from.


Download ppt "Java Android-8 Imran Shafi. Lecture Contents  Debugging Android Projects  Java/XML Errors  Debugger  Logcat Utility  Android Debug Bridge (adb) "

Similar presentations


Ads by Google