Debug Android app with Chrome browser _android

Source: Internet
Author: User
Tags sqlite

The individual has always had a passion for chrome, and Chrome is friendlier to developers in addition to being faster. Built-in powerful developer Tools, I believe that web development simply fondle admiringly! and the chrome store provides a variety of plug-ins, no you can not use, only you can not imagine. Now everything basic chrome has to do, and sometimes think, if you can use Chrome to debug the Android app how convenient, and now Facebook just open up a tool stetho, from this Chrome debugging Android is no longer a dream.

Debugging Tools

In addition to some of the official debugging tools in the Android development, there are two tools I think are necessary.

1. Grab Bag Tool

The best use of Windows platform should be Charles on the Fiddle,mac. This should be a prerequisite for app development, whether it's Android or iOS.

2.Sqlite View

This tool is more, in addition to the Sqlite3 tools, or the need for some GUI tools more convenient, do not enumerate, we find their own favorite tool on the line, there are some browser plug-ins, there are a number of platform clients. What you need to know is that if you want to see the SQLite files in the app, you need root.

Stetho

Grab Bag tool Although easy to use, but every time in the mobile phone set agent, also very troublesome, see SQLite file must be root this more trouble. But with the Stetho, these tools are all self-contained, easy to use, do not need root, below to see the official demo introduction of usage.

1. First gradle to rely on

Copy Code code as follows:

dependencies {
Compile ' com.facebook.stetho:stetho:1.0.1 '
}

2. Then configure it in your app's application class
Copy Code code as follows:

public class MyApplication extends application {
public void OnCreate () {
Super.oncreate ();
Stetho.initialize (
Stetho.newinitializerbuilder (This)
. Enabledumpapp (
Stetho.defaultdumperpluginsprovider (This))
. Enablewebkitinspector (
Stetho.defaultinspectormodulesprovider (This))
. build ());
}
}

Then you can run the app for debugging, basically to meet the requirements of debugging.

3.Chrome debugging

Open Chrome, enter chrome://inspect and then you can see in the list that your app can be debugged with Stetho App,facebook official also provides a basic sample, the following is the debug screenshot provided by its sample

Basic skills can be used

1. Detect Network Status

2. View the app local database and can execute SQL directly

View the app local sharedpreference file and edit it directly

Attention matters

It is worth noting that if you are simply configured to detect the network state is not able to view, there are two ways:

1. Use of Okhttp

This is the simplest way to ask for the okhttp version to be in 2.2.x+, just add the following code, which is also the easiest way to do it now.

Copy Code code as follows:

Okhttpclient client = new Okhttpclient ();
Client.networkinterceptors (). Add (New Stethointerceptor ());

2. Use of HttpURLConnection

If you are using your own written or other HTTP library's bottom layer is implemented with httpurlconnection, you need to use Stethourlconnectionmanager for integration. You must then declare the Accept-encoding:gzip request headers. See the specific use of Facebook Stetho source code sample.

Where you may rely on the following network helpers.

Copy Code code as follows:

dependencies {
Compile ' com.facebook.stetho:stetho-okhttp:1.0.1 '
}

Or
Copy Code code as follows:

dependencies {
Compile ' com.facebook.stetho:stetho-urlconnection:1.0.1 '
}

Finally, provide a download for a Facebook Stetho demo.

Stetho Sample

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.