Using AspectJ .aj file with Android Studio, weaving appears to not be happening -


i new aspectj, , working on migrating third-party application written using eclipse use android studio 1.1.0 , gradle instead. have taken external library app needs , created library module in project, , library has aspectj .aj file need compile , have work main app field-level observable pattern. using plugin found here, have been able .aj file compile .class file, verified looking in intermediates folder.

the problem coming in 'weaving' step, code supposed injected bytecode of necessary classes. not appear happening, listeners supposed notified when field changes, aren't. below build files.

project build.gradle:

buildscript {     repositories {         jcenter()     }     dependencies {         classpath 'com.android.tools.build:gradle:1.1.0'         classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.12'     } }  allprojects {     repositories {         jcenter()     } } 

app module build.gradle:

apply plugin: 'com.android.application'  android {     compilesdkversion 19     buildtoolsversion "22.0.1"      defaultconfig {         applicationid "com.example.myapp"         minsdkversion 14         targetsdkversion 19     }      buildtypes {         release {             minifyenabled false             proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.txt'         }     } }  dependencies {     compile project(':blahblah')     compile 'com.android.support:support-v4:19.1.0'     compile 'com.google.code.gson:gson:2.2.4'     compile 'com.google.android.gms:play-services:6.1.11'     compile files('libs/commons-lang3-3.3.2.jar') } 

'blahblah' library module build.gradle:

import com.android.build.gradle.libraryplugin import org.aspectj.bridge.imessage import org.aspectj.bridge.messagehandler import org.aspectj.tools.ajc.main  apply plugin: 'com.android.library' apply plugin: 'android-aspectj'  def gsonversion = '2.2.4' def aspectjversion = '1.8.5'  dependencies {     compile filetree(dir: 'libs', include: ['*.jar'])     compile "com.google.code.gson:gson:${gsonversion}"     compile "org.aspectj:aspectjrt:${aspectjversion}" }  android {     compilesdkversion 19     buildtoolsversion "22.0.1"      defaultconfig {         minsdkversion 14         targetsdkversion 19         versioncode 1         versionname "1.0"     }     buildtypes {         release {             minifyenabled false             proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro'         }     } }  android.libraryvariants.all { variant ->      libraryplugin plugin = project.plugins.getplugin(libraryplugin)      variant.javacompile.dolast {         string[] args = ["-showweaveinfo",                          "-1.5",                          "-inpath", javacompile.destinationdir.tostring(),                          "-aspectpath", javacompile.classpath.aspath,                          "-d", javacompile.destinationdir.tostring(),                          "-classpath", javacompile.classpath.aspath,                          "-bootclasspath", plugin.project.android.bootclasspath.join(                 file.pathseparator)]          messagehandler handler = new messagehandler(true);         new main().run(args, handler)          def log = project.logger         (imessage message : handler.getmessages(null, true)) {             switch (message.getkind()) {                 case imessage.abort:                 case imessage.error:                 case imessage.fail:                     log.error message.message, message.thrown                     break;                 case imessage.warning:                 case imessage.info:                     log.info message.message, message.thrown                     break;                 case imessage.debug:                     log.debug message.message, message.thrown                     break;             }         }     } } 

what missing?

after more research, have been able working expected. here final build.gradle files:

project build.gradle:

buildscript {     repositories {         jcenter()     }     dependencies {         classpath 'com.android.tools.build:gradle:1.1.0'     } }  allprojects {     repositories {         jcenter()     } } 

app module build.gradle:

import org.aspectj.bridge.imessage import org.aspectj.bridge.messagehandler import org.aspectj.tools.ajc.main  buildscript {      repositories {         mavencentral()     }      dependencies {         classpath 'org.aspectj:aspectjtools:1.8.1'     }  }  apply plugin: 'com.android.application'  repositories {     mavencentral() }  def gsonversion = '2.2.4' def aspectjversion = '1.8.1'  dependencies {     compile project(':blahblah')     compile "org.aspectj:aspectjrt:${aspectjversion}"     compile 'com.android.support:support-v4:19.1.0'     compile "com.google.code.gson:gson:${gsonversion}"     compile 'com.google.android.gms:play-services:6.1.11'     compile files('libs/commons-lang3-3.3.2.jar') }  android {     compilesdkversion 19     buildtoolsversion "22.0.1"      defaultconfig {         applicationid "com.example.myapp"         minsdkversion 14         targetsdkversion 19     }      lintoptions {         abortonerror true     }      buildtypes {         release {             minifyenabled false             proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.txt'         }     } }  // section below performs aop "weaving" (injecting aop code // appropriate classes).  please not remove.  final def log = project.logger final def variants = project.android.applicationvariants  variants.all { variant ->     if (!variant.buildtype.isdebuggable()) {         log.debug("skipping non-debuggable build type '${variant.buildtype.name}'.")         return;     }     javacompile javacompile = variant.javacompile     javacompile.dolast {         string[] args = ["-showweaveinfo",                          "-1.5",                          "-inpath", javacompile.destinationdir.tostring(),                          "-aspectpath", javacompile.classpath.aspath,                          "-d", javacompile.destinationdir.tostring(),                          "-classpath", javacompile.classpath.aspath,                          "-bootclasspath", project.android.bootclasspath.join(file.pathseparator)]         log.debug "ajc args: " + arrays.tostring(args)         messagehandler handler = new messagehandler(true);         new main().run(args, handler);         (imessage message : handler.getmessages(null, true)) {             switch (message.getkind()) {                 case imessage.abort:                 case imessage.error:                 case imessage.fail:                     log.error message.message, message.thrown                     break;                 case imessage.warning:                     log.warn message.message, message.thrown                     break;                 case imessage.info:                     log.info message.message, message.thrown                     break;                 case imessage.debug:                     log.debug message.message, message.thrown                     break;             }         }     }  } 

'blahblah' library module build.gradle:

def gsonversion = '2.2.4'  buildscript {      repositories {         mavencentral()     }      dependencies {         classpath "com.android.tools.build:gradle:1.1.0"         classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.12'     }  }  apply plugin: 'com.android.library' apply plugin: 'android-aspectj'  repositories {     mavencentral() }  dependencies {     compile "com.google.code.gson:gson:${gsonversion}" }  android {     compilesdkversion 19     buildtoolsversion "22.0.1"     lintoptions {         abortonerror true     } } 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -