DexKnifePlugin


Source link: https://github.com/ceabie/DexKnifePlugin

DexKnife

A simple android gradle plugin to use the patterns of package to smart split the specified classes to multi dex. Also supports android gradle plugin 2.2.0 multidex. Solve android studio enable the native multidex feature, but there will be too many classes in main dex. (See Features 7)

  • Notes: Because instant-run of 2.0.0 above is incompatible with multidex, DexKnife is auto disabled when instant-run mode. It will auto enable when disabled instant-run or in packaging release.(minsdk < 21)

??

Update Log

1.6.1: Compatible with android gradle plugin 2.3.0, auto disable when build with ART-Runtime (See Features 8). 1.6.0: Modify: When only -keep is configured, only keep the specified classes. 1.5.9: Compatible with some ancient version of gradle and android gradle plugin. 1.5.8: Compatible with gradle 3.2, fixed use of only support-split and support-keep resulting in an extra large number of classes. 1.5.7: fixed support-split and support-keep are not work. (??support-split/support-keep???bug) 1.5.6: Experimentally compatible with java 1.7, fix nothing is selected when only -keep. (??????java 1.7,?????keep?????????) 1.5.5: support individual filter for suggest maindexlist. (???maindexlist????) 1.5.5.alpha: Experimentally compatible with android gradle plugin on 2.2.0. (?????? 2.2.0 plugin) 1.5.4: auto disabled when instant run mode.(instant run ???????DexKnife) 1.5.3: add some track logs and skip DexKnife when jarMerging is null.(?????????jarMerging?null????) 1.5.2: fixed the include and exclude path, and supports filtering single class.(??include?exclude, ????????) 1.5.1.exp: Experimentally compatible with android gradle plugin on 2.1.0 ??????? 2.1.0 plugin? 1.5.1: fixed the proguard mode 

Features

  1. DexKnife just converts the wildcards of class path to maindexlist.txt, does not participate in other compilation process. It is not automatic tools, you need to have a understanding of the maindexlist features.

  2. If the class can not be found (ie class no def / found) at runtime, enable DexKnife's log function, debug the config of dexKnife and check the config ProGuard. Verify the generated maindexlist.txt match your config. Do not split the classes in the Application class into second dex. (Even if you manually configure the maindexlist will be such a problem.)

  3. DexKnife can only explicitly specify the classes of main dex, can not specify the classes of after the second dex (limitation of dex's param maindexlist). If you need to completely configure the main dex manually, use: -donot-use-suggest
    -split **
    -keep android.support.multidex.** # keep multidex lib
    -keep # wildcards of other keeping classes, and the count of idx don't overflow 65535

  4. DexKnife does not have dependency detection and requires you to configure it manually because DexKnife does not know your project requirements.

  5. DexKnife uses the original classpath as the configuration, not the obfuscated classpath.

  6. the count of ID that generated by -keep can not overflow 65535, otherwise there will be error of too many class.

  7. If you use the android gradle plugin's native multidex, but the declaration in the manifest is too much, resulting in the number of methods and variables are still overflow, or can not be packaged. You can simply use -suggest-split to move some of the classes in the suggest list out of the main dex.

  8. minsdk < 21. If minsdk >= 21, the android gradle plugin will build with ART-Runtime, MainDexList isn't necessary, DexKnife is auto disable. In debug mode with Android Gradle plugin >= 2.3.0, minsdk is associated with min(Target running device, TargetSdk). Make sure your MinSdkVersion < 21, DexKnife will auto enable in release mode if conditions are compatible.

Usage

1.In your project's build.gradle, buildscript.


 buildscript {

 ....

dependencies {

 ....

 classpath 'com.android.tools.build:gradle:2.3.0'  // or other

 classpath 'com.ceabie.dextools:gradle-dexknife-plugin:1.6.1'

}

  
}
 

please make sure gradle version is compatible with the android gradle plugin, otherwise it can causes some sync error, such as:
Gradle sync failed: Unable to load class 'com.android.builder.core.EvaluationErrorReporter'.

2.Create a 'dexknife.txt' in your App's module, and config the patterns of classes path that wants to put into sencond dex.
(The rest of any classes that is not marked split will be in miandexlist)


 Patterns may include:

'*' to match any number of characters
  '?' to match any single character
  '**' to match any number of directories or files
  Either '.' or '/' may be used in a pattern to separate directories.
  Patterns ending with '.' or '/' will have '**' automatically appended. 

Also see: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/util/PatternFilterable.html

Other config key:

'#' is the comment, config is disabled when '#' adds on line start.  # Global filter, don't apply with suggest maindexlist if -filter-suggest is DISABLE. # this path will to be split to second dex. android.support.v?.**  # if you want to keep some classes in main dex, use '-keep'. -keep android.support.v4.view.**  # you can keep single class in main dex, end with '.class', use '-keep'. -keep android.support.v7.app.AppCompatDialogFragment.class  # do not use suggest of the maindexlist that android gradle plugin generate. -donot-use-suggest  # the global filter apply with maindexlist, if -donot-use-suggest is DISABLE. -filter-suggest  # Notes: Split dex until the dex's id > 65536. --minimal-main-dex is default. -auto-maindex  # default is not used.  # dex additional parameters, such as --set-max-idx-number=50000 # if number is too small, it will cause DexException: Too many classes in --main-dex-list, main dex capacity exceeded -dex-param --set-max-idx-number=50000  # log the main dex classes. -log-mainlist  # log the filter classes of suggest maindexlist, if -filter-suggest is enabled.. -log-filter-suggest  #the filter log?Recommend?Global?true?false -log-filter  # if you only filter the suggest maindexlist, use -suggest-split and -suggest-keep. # Global filter will merge into them if -filter-suggest is ENABLE at same time. -suggest-split **.MainActivity2.class -suggest-keep android.support.multidex.** 

Note: if you want to filter the inner classes, use $*, such as: SomeClass$*.class

3.add to your app's build.gradle, add this line:

apply plugin: 'com.ceabie.dexnkife' 

and then, set your app

multiDexEnabled true 
  • Notes: You want to set 'multiDexEnabled true' in 'defaultConfig' or 'buildTypes', otherwise ineffective.

4.run your app

DexKnife??

?????????????????????dex?gradle???(?????? ??) ???? android gradle plugin 2.2.0 multidex. ???? android studio ?? multidex??????dex???????(?? ?? 7)

  • ??????? 2.0.0 ? instant-run ? ART-Runtime ??? multidex????DexKnife???????instant-run?????release?????????(minsdk < 21)

????

1.6.1: ?? Android gradle plugin 2.3.0?? ART-Runtime?????????????????(?? ?? 8) 1.6.0: ??????keep?????keep???? 1.5.9: ??????? gradle ? android gradle plugin?? 1.5.8: ??gradle 3.2???????support-split/support-keep????????? 1.5.7: ??support-split/support-keep???bug 1.5.6: ??????java 1.7,?????keep????????? 1.5.5: ?????maindexlist???? 1.5.5.alpha: ?????? 2.2.0 plugin 1.5.4: instant run ???????DexKnife 1.5.3: ?????????jarMerging?null????? 1.5.2: ??include?exclude, ???????? 1.5.1.exp: ?????? 2.1.0 plugin 1.5.1: ?? proguard mode 

??????

  1. DexKnife??????? ?????? -> maindexlist ????????maindexlist.txt? ????????????????????????maindexlist?????????

  2. ????????????i.e. class no def/found?????DexKnife?log????????DexKnife?ProGuard?????????maindexlist????????? ????Application????????????dex????????DexKnife?????maindexlist??????????

  3. DexKnife?????????dex?????????????dex?????dex?maindexlist?????????????????dex???
    -donot-use-suggest
    -split **
    -keep android.support.multidex.** # ?? multidex ????????multidex
    -keep # ????keep?????????????

  4. DexKnife??????????????????DexKnife???????????

  5. DexKnife????????????????????????

  6. -keep ??????ID??????65535?????? Too many classes ????

  7. ????android gradle plugin???multidex????manifest???????????????????????????????dex???????????????????-suggest-split???????????????dex?????????????

  8. minsdk < 21??? minsdk >= 21??????ART??????????MainDexList?DexKnife??????Android Gradle plugin >= 2.3.0???debug????minsdk????? min(??????, TargetSdk)??? minsdk < 21?Release?????????

????

1.?????? build.gradle ? buildscript:


 buildscript {

 ....

dependencies {

 ....

 classpath 'com.android.tools.build:gradle:2.3.0'  // or other

 classpath 'com.ceabie.dextools:gradle-dexknife-plugin:1.6.1'

}

  
}
 

?????????gradle???android gradle plugin????????????????
Gradle sync failed: Unable to load class 'com.android.builder.core.EvaluationErrorReporter'.

2.?App????? dexknife.txt??????????dex??????????.????????????split?????miandexlist?


 Patterns may include:

'*' to match any number of characters
  '?' to match any single character
  '**' to match any number of directories or files
  Either '.' or '/' may be used in a pattern to separate directories.
  Patterns ending with '.' or '/' will have '**' automatically appended. 

????: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/util/PatternFilterable.html

?????

?? # ????, ?????? #, ???????.  # ????, ????? -filter-suggest ?????? ???maindexlist. # ????????????????maindex????? -keep ???????????????. # ?????split??keep??miandexlist????keep????? -keep android.support.v4.view.**  # ????????????????dex?.???????????????maindexlist?? android.support.v?.**  # ??.class????????. -keep android.support.v7.app.AppCompatDialogFragment.class  # ???Android gradle ???????miandex??. -donot-use-suggest  # ? ????????? ???maindexlist?, ? -donot-use-suggest ???. -filter-suggest  # ???dex??? ?? dex ?id???? 65536. -auto-maindex  # dex ????, ?? --set-max-idx-number=50000 # ???? DexException: Too many classes in --main-dex-list, main dex capacity exceeded???????? -dex-param --set-max-idx-number=50000  # ??miandex???. -log-mainlist  #?????Recommend??maindexlist???????????Global??maindexlist??????????true?????????false???maindexlist? -log-filter  # ??????? ???maindexlist, ?? -suggest-split ? -suggest-keep. # ?????? -filter-suggest, ???????????. -suggest-split **.MainActivity2.class -suggest-keep android.support.multidex.** 

??:

  1. ?????????????
  2. ????split(??????????)? ???????split???????maindex?????????????maindex???? ???keep?????keep????maindexlist?????????????????
  3. suggest-split?suggest-keep???? ?2??
  4. ??????????????suggest-xxx?????????????????????maindexlist???????suggest-split?ADT???????????
  5. ?????????, ??$*???: SomeClass$*.class?

3.???App???build.gradle ???

apply plugin: 'com.ceabie.dexnkife' 

????app??????

multiDexEnabled true 
  • ????? defaultConfig ?? buildTypes??? multiDexEnabled true????????

4.??????

??

?Terminal??? gradleDebug?????? http://blog.csdn.net/ceabie/article/details/55271161

License

Copyright (C) 2017 ceabie (http://blog.csdn.net/ceabie)  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

The goal of this library is to allow your app to support Facebooks Rebound effect on all views, with circular reveal effect and also provides bottom bar with circular reveal effect. ram size depending animation play support.

Makes it easy to create a beautiful about screen for your app.

Micro-Transitions for Smooth Android To-Do List Animations.

A set of EditTexts with built-in support for Date and TimePicker's using fragments.

Mobile Test Automation Tool

  • Run the same test on different mobile devices and operating systems with a mobile test automation tool that allows tests portability
  • Perform mobile test automation using real devices and emulators
  • Create a test on one device and run it on any other device model or operating system
  • Increase coverage with full peripheral testing capabilities
  • Start your mobile test automation quickly with a simple plug, record and play tool
  • Enhance your mobile test automation by Integrating into all your major ALM environments
  • Integrate with any continuous integration environment
  • Recorder for quick test creation

This example is basically used for simple using of data binding for Views and RecyclerView using model.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes