PavelSynek / Dexter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dexter

Control your .dex demons.

A utility to manage MultiDex reached apps (>64k method counts).

Managing multidex manually is a troublesome task in itself, this issue is commonly known as the "Worst nightmare of Android developers". Multiple Dalvik Executables can hinder your app's performance heavily in form of crashes and ANRs. It usually becomes a necessity to control what classes should end up in the primary dex file (classes.dex).

What Dexter does?

Dexter helps in:
  • Managing the class entries to be registered in Primary Dex file, using annotations.
  • Validating what goes in your Primary Dex. You can have print the list of classes which the dex files contain using a simple task

Prerequisites.

Add the multidex support library into your project, as mentioned here : https://developer.android.com/studio/build/multidex

Add the following lines:

In your project level build.gradle:

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
    }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.1.3'
    classpath 'com.github.bobblekeyboard.dexter:dexter:1.0.6'
  }
}

Also:

allprojects {
  repositories {
    google()
    jcenter()
    maven { url 'https://www.jitpack.io' }
  }
}

Add the validationTask in your build.gradle for the debug apk produced to perform the magic:

apply plugin: 'com.bobble.dexter’

import com.bobble.dexter.DexterDefaultTask
import com.bobble.dexter.core.Dexter
import com.bobble.dexter.core.Dexter.BuildVariant

task validationTask(type:DexterDefaultTask){
    Dexter.configure().setBuildVariant(BuildVariant.DEBUG)
}

In you app's build.gradle add support for annotations:

implementation 'com.github.bobblekeyboard.dexter:dexter-annotations:1.0.6’
annotationProcessor 'com.github.bobblekeyboard.dexter:dexter-processors:1.0.6’

Usage.

Registering classes in Primary Dex

Annotate the classes you want to keep in your primary dex, with @PrimaryDex annotation and Dexter will create the multidex.keep file(if not already present) and will also register the annotated classes.

For example, Here we are adding the InitClass.java to primary dex:

@PrimaryDex
public class InitClass {

}

You can also customize the annotations by mentioning extra dependencies you may want to keep in your primary dex as shown in following annotations:

@PrimaryDex(extras = {"android/support/v7/app/AppCompatActivity", "android/os/Bundle"})

Building the project would automatically register the annotated classes to be indexed in the Primary Dex file:

android/support/v7/app/AppCompatActivity
android/os/Bundle
orp/ardnahcimor/test/InitClass

Validating the Dex Files

For validation, Dexter consists of a gradle plugin which gives you an insight to the list of classes going in your multiple dex files. Configuration is very simple:

Sync your project and run a assembleDebug task of gradle.

Run validation task by ./gradlew validationTask command. You will see the total number of class defs, strings and type IDs read in your different Dex files:

alt text

Now go to your project root directory and app/build/outputs you will see a directory created by name of dexter. Here you can find a text file by name of DexClasses of classes.dex which corresponds to your primary dex. If you open this you can see the list of classes in your primary dex and you can validate if any class has entered your primary dex or not.

alt text

You can also see the rest dex Files and there respective text files. You can open the remaining text files to have an insight in the classes entering in them.

Configure for a custom apk path

task validationTask(type:DexterDefaultTask){
  Dexter.configure().setApkPath("/Users/amanjeetsingh150/Desktop/app-debug.apk")
}

Configure for release build

task validationTask(type:DexterDefaultTask){
    Dexter.configure().setBuildVariant(BuildVariant.RELEASE)
}

You can see the output in dexter folder as:

screen shot 2018-07-08 at 1 30 15 am

Show some ❤️ by starring ⭐ the repo. Dexter is open for contributions. You are free to open issues and PRs.

TODOs

  1. Adding the Dexter Task in the gradle task graph
  2. More customizations for the arguments of Primary Dex annotation

About


Languages

Language:Java 91.0%Language:Kotlin 9.0%