dengzii / pandora

an android library for debugging what we care about directly in app.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EN | 中文

Pandora is a tool box that allows you to inspect and modify what includes networks, databases, UIs, etc. directly in your application. It is suitable for rapid position of various problems in the development and testing stages.

Demo

Feature

① Network logs

  • Check the detailed logs of network requests, such as headers, body, error messages, and so on.

  • Support all network libraries based on OKHTTP and Android native HttpURLConnection, covering most network development situations.

② Sandbox

  • View the app's private storage directory, and can export files to SDcard.

  • Supports browsing and editing SQLite databases, SharedPref files.

③ UI:Select、Hierarchy、Baseline、Gridline

  • View and modify properties of any Widget, such as the widget's size, color, text content, and so on.

  • Grab and move any widget, view the boundaries and relative distance between widgets, detect alignment, layout and other issues.

  • View the hierarchy of any UI, support Activity, Dialog, PopupWindow, etc.

④ Other tools

  • Show the current Activity in real time.

  • Supports recording crash, compatible with third-party Crash libraries.

  • You can add shortcut to Pandora.

  • You can open any Activity of your app.

  • You can view the lifecycle history of Activities.

Usage

  1. Declare Jitpack repository and add dependencies:

    // android-support
    debugImplementation 'com.github.whataa:pandora:v${RELEASE}'
    // or androidX
    debugImplementation 'com.github.whataa:pandora:androidx_v${RELEASE}'
    
    // No matter android-support or AndroidX
    releaseImplementation 'com.github.whataa:pandora-no-op:v${RELEASE}'
    
    library version
    pandora Release
    pandora-no-op Release
  2. (Optional)If your project use OKHttp as a network library, add the following interceptor to support network logging:

    Pandora.get().getInterceptor();
    
  3. Grant permission to "Overlay Windows" and shake your device.

More feature

1. Add shortcuts to Pandora

Usually, we may hide some debugging switches in some pages to "switch the development environment", "check the Crash log" and so on. If you have similar needs, you can add a shortcut by:

  1. Implement tech.linjiang.pandora.function.IFunc , return the icon, name and the action:

    private IFunc customFunc = new IFunc() {
        @Override
        public int getIcon() {
            return R.drawable.ic_launcher_round;
        }
    
        @Override
        public String getName() {
            return getString(R.string.pandora_click_me);
        }
    
        @Override
        public boolean onClick() {
            toast("I am the custom Function.");
            return false;
        }
    };
    
  2. Call Pandora.get().addFunc() to add it.

2. Let "view properties" support more.

Pandora supports viewing and partially modifying the properties of View, ViewGroup, and common TextView and ImageView by default. If you want to inspect more view attributes, you can expand them in the following ways:

  1. implement tech.linjiang.pandora.inspector.attribute.IParser interface and specify the type of View that you are interested in. Here is an example of an already implemented ImageView:
public class ImageViewParser implements IParser<ImageView> {

    @Override
    public List<Attribute> getAttrs(ImageView view) {
        List<Attribute> attributes = new ArrayList<>();
        // Add the property of interest and return
        Attribute scaleTypeAttribute = new Attribute("scaleType", scaleTypeToStr(view.getScaleType()), Attribute.Edit.SCALE_TYPE);
        attributes.add(scaleTypeAttribute);
        return attributes;
    }
    ...
}
  1. Add new Parser to Pandora:
Pandora.get().getAttrFactory().addParser(new ImageViewParser());

After this, every time you click on the ImageView, the property list will automatically enumerate the values of the properties we are interested in.。

3. Edit the SharedPref located in custom path:

Pandora reads by default the XML file in the default SP path in the application(data/data/<package-name>/shared_prefs/),If there exist other SP files that are not in the default path, they can be extended in the following ways:

  1. implement tech.linjiang.pandora.preference.protocol.IProvider interface,and return the corresponding file list:

(Specific details can refer to the default implementation in the librarySharedPrefProvider)

  1. Add new Provider to Pandora:
Pandora.get().getSharedPref().addProvider(new XXProvider());

Problems

0. Failed when add the dependencies

  1. Check to see if the Jitpack repository is declared.
  2. There exists a 'v' symbol in the start of version number.

1. No data or incomplete data in the network logs

It is recommended that the Pandora interceptor be added as the last of the OKHttp interceptors.

2. Don't want to use shake, which is in conflict with my app

You can call Pandora.get().disableShakeSwitch(); to disable it, and call Pandora.get().open(); to open directly.

3. No react when shaking, or it's hard to open it.

Due to the large number of Android phones, please manually go to the permission center to check whether the permission of "overlay window" is granted.

In cases where it's hard to open, you can change the trigger factor in the "config" modify the value that works best for your phone.

4. proguard-rules

Even though it is recommended to use Pandora only in the dev and test stage, enable minify can be anywhere, so add the following rules if you need it:

-keep class tech.linjiang.pandora.cache.**{*;}

5. android-support or AndroidX ?

Which version to implementation depends on your project, The two versions have completely consistent logic and synchronized updates, except for different dependencies. Although AndroidX is the trend, if your project cannot be migrated to AndroidX, please use android-support.

Thanks

Pandora was developed on the shoulders of giants. Thanks to the following open source projects or person:

  • Logo and Icon are produced by the designer Zularizal.

  • Inspired by Flipboard's open source iOS platform debugging tool FLEX

  • Project database module ideas and part of the source code from Facebook's open source project stetho

  • The idea of selecting views in the UI module of the project and part of the source code from eleme's open source project UETool

  • The request API in the Demo module comes from jgilfelt's open source project chuck

License

Apache-2.0

About

an android library for debugging what we care about directly in app.

License:Apache License 2.0


Languages

Language:Java 99.7%Language:HTML 0.3%