RoboAspectJ


Source link: https://github.com/meituan/RoboAspectJ

RoboAspectJ

RoboAspectJ is a Gradle plugin to introduce AspectJ ( Aspect- Orient Programming) to Android project. It compiles aspects(if needed) and weave them all together in FULL-PROJECT scope. This means project (or subproject) sources, external libraries and local dependencies will all be dealt with by default.

Note: This plugin may change due to the modification of transform-api. So you may keep track of RoboAspectJ to make sure you're using the most recent version.

latest version: v0.9.1

Prerequisite

Android Plugin (application) 2.1.0

Apply

Add plugin dependency in buildscript classpath:

buildscript {

  dependencies {

classpath 'com.meituan.gradle:roboaspectj:0.9.+'
  
}
 
}

Apply plugin:

apply plugin: 'com.meituan.roboaspectj'

Coding

There are basically 2 ways to write your aspects and weave them into production code:

As Source

write aspects in @AspectJ syntax under your project's java source directory. e.g. { $projectDir } /src/main/java/

As Library

compile and bundle your aspects independently using ajc, then make it dependency in build script. For example:

compile 'com.example.myaspects:library:1.0'

This way may be a little bit complicated. But it's suitable for those who want to maintain their aspects as an independent project.

Variant-Specific Concern

While RoboAspectJ is registered globally, we still can do our crosscutting concern under specific variant. Actually, this is already done by Android plugin.

As Source

put variant-specific aspects under corresponding folder.

For example, I want to do some performance monitoring in myflavor, so I will write aspects under ${ projectDir } /src/myflavor/java/.

As Library

add variant-specific aspects dependency to corresponding configuration scope.

myflavorCompile 'com.example.myaspects:library:1.0'

Configuration

There is an extension aspectj for you to do some tweaking.

Exclude

If you want to leave some artifact untouched from AspectJ, using:

aspectj {
  exclude group: 'com.google.android', module: 'support-v4' 
}

Java runtime

When applying rxjava or retrolambda, you may need jrt.jar as classpath. Configure it by:

aspectj {
  javartNeeded true 
}

Disable

For debug or performance use, you can disable weaving:

aspectj {

  enable false
 //by default, it's true and you don't have to add this statement. 
}

alternatively, set roboaspectj.enable property false when run gradle.

$ gradle clean assembleDebug -Droboaspectj.enable=false 

Maybe you want it to be smarter to disable it when it's a debug flavor, then add this to your build script:

aspectj {

  disableWhenDebug true // default is false 
}

or, specify roboaspectj.disableWhenDebug property.

$ gradle clean assembleDebug -Droboaspectj.disableWhenDebug=true 

Though weaving is disabled, Aspects and AspectJ compile dependencies are all still there. It's only the weaving step doesn't happen.

Note: Corresponding property has precedence over config in build script in both of these 2 cases. For instance, weaving will not take effect when your roboaspectj.enable property is false, no matter what you config in build script.

License

Code is under the Apache Licence v2.

Feedback

This plugin is currently a prototype, and it still has much to improve. Feel free to contact: [email protected]

Resources

Gradle Material Design Icons Plugin

This plugin will manage google's official material design icons in your build.gradle.

Record full-resolution video on your Android devices.

Available on Google Play.

BusWear is a simple library for EventBus to support Android Wear devices. Just adding one line of code lets you get synchronized event buses on Wear and mobile platform.

Qachee is a generic cache system to use specially for Android Apps. It is just a LRU Memory cache with policy expiration and lots of useful methods.

RefreshMenuItem is a Menu item that shows an indeterminate progress in the Android ActionBar. It is simple to use, lightweight, scalable and uses intuitive methods names.

What is Android Promise

A library for modular asynchronous calls.

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