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.
- 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
.
To update the plugin, simply download a new version and repeat the process.
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.
Searches for Android Activity classes to inject navigation probes.
Injected source-code:
@Override
protected void onResume() {
super.onResume();
Nappa.setCurrentActivity(this);
}
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);
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);
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())
- Gradle v5.6.4
- IntelliJ IDEA
- Android Studio
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.
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 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.
- 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.
sudo sh ./gradlew runIde
Gradle places new builds in the directory build/distributions.
- Open the Gradle tool window.
- Double click on
nappa-plugin-android-studio > Tasks > IntelliJ > buildPlugin
sudo sh ./gradlew buildPlugin
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.