Skip to content

Latest commit

 

History

History

Android-Studio-Plugin

Plugin for Android Studio

NAPPA plugin for Android Studio

This project contains a plugin for Android Studio to automate the task of enabling NAPPA in an existing Android project. This plugin injects all critical NAPPA dependencies to an Application’s source code.

Getting started

Installation

  • Go to this repository releases page.
  • Download the latest version of the plugin from NAPPA Plugin for Android Studio v1.x.
  • Open Android Studio.
  • Go to File > Settings > Plugins > Cog icon > Install plugin from disk (see figure below).
  • Select the downloaded file.
  • Restart Android Studio.
  • You should see a new entry in the menu bar named Prefetching.

Plugin Installation

To update the plugin, simply download a new version and repeat the process.

Usage

There are four actions to inject NAPPA dependencies in the project source code (see figure below). After the instrumentation process takes place, NAPPA performs the ENG construction dynamically. Prefetching is performed transparently without requiring any intervention from the end-user. As the user navigates an application's activities, the ENG is built and prefetching is performed whenever a suitable candidate is encountered.

Nappa Android Studio Plugin

Instrument Activities

Searches for Android Activity classes to inject navigation probes.

Injected source-code:

@Override
protected void onResume() {
    super.onResume();
    Nappa.setCurrentActivity(this);
}

Instrument Intent Extras

Searches for the usage of Android Intent Extras to inject extra probes.

Injected source-code:

/* Source-code inject before the original source code */
Nappa.notifyExtras(intent.getExtras());

/* Original source-code */
startActivity(intent); 

Instrument OkHttpClient

Searches for usage of OkHttpClient to instantiate a OkHttp Interceptors. NAPPA serve intercepted requests whenever they are stored in the cache. Otherwise, they are rerouted to the origin server.

Injected source-code:

/* Original source-code */
okHttpClient = new OkHttpClient();
okHttpClient = new OkHttpClient.Builder().build;

/* New source-code */
okHttpClient = Nappa.getOkHttp(new OkHttpClient());
okHttpClient = Nappa.getOkHttp(new OkHttpClient.Builder().build);

Instrument Retrofit

Searches for usage of Retrofit to provide an instrumented OkHttpClient.

Injected source-code:

/* Original source-code */
retrofitClient = new Retrofit.Builder().client(new OkHttpClient())

/* New source-code */
retrofitClient = new Retrofit.Builder().client(Nappa.getOkHttp())

Running the plugin in a local environment for development

Required Tools

Configuration

Create the file gradle.properties in the Gradle installation direcctory with the content:

nappaAndroidStudioHome=/absolute/path/to/Android Studio/
nappaAndroidStudioVersion=/build/version/of/Android Studio

To find the installed version of Android Studio, use the Android Studio About dialog screen. An example is shown below. In this case, the (BRANCH. BUILD. FIX) version of the IntelliJ Platform is 191.8026.42. Refer to Android Studio Plugin Development for more details.

Android Studio about dialog screen

Import this project in IntelliJ IDEA.

Info: If no property is defined, Gradle will download the latest build of IntelliJ IDEA Community Edition.

Running the plugin

Running the plugin will open an instance of Android Studio with the plugin installed. A few exceptions might take place when opening the Android Studio stance. The cause of these exceptions are undefined configurations (e.g. SDK) and can be ignored.

Running the plugin from IntelliJ IDEA

  • Open the Gradle tool window.
  • Double click on nappa-plugin-android-studio > Tasks > IntelliJ > runIde.

Running from the IntelliJ IDEA allows the plugin to be executed in debug mode.

Running the plugin from bash

sudo sh ./gradlew runIde

Create a new build

Gradle places new builds in the directory build/distributions.

Create a new build from IntelliJ IDEA

  • Open the Gradle tool window.
  • Double click on nappa-plugin-android-studio > Tasks > IntelliJ > buildPlugin

Create a new build from bash

sudo sh ./gradlew buildPlugin

Development

The official IntelliJ documentation on developing plugins is available here.

Each instrumentation described above is implemented as an Action and are mapped in the plugin.xml file.

There is a set of utility libraries implemented to abstract common logic between the actions.

Changes in the source-code are not automatically pushed to the current instance of Android Studio. The runIde command must be executed again to reflect the changes.