Maven build error with Android, AspectJ and MonkeyTalk
I'm trying to use the MonkeyTalk to automate the black-box tests in my
Android app. The problem I'm facing is that they don't have anything
documented about using it with Maven.
So, I found this:
http://www.gorillalogic.com/content/maven-aspectj
Then, I started trying the same solution. But, since I want to use the
MonkeyTalk just to create a package for tests and let it out of my
realease, I've created a Maven Profile. So, my pom.xml was as follows:
First, I added the these dependencies:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
<scope>provided</scope>
</dependency>
And I created this profile:
<profile>
<id>monkeytalk</id>
<dependencies>
<dependency>
<groupId>com.gorillalogic.monkeytalk</groupId>
<artifactId>monkeytalk-agent</artifactId>
<version>${monkeytalk-version}</version>
<exclusions>
<exclusion>
<groupId>com.gorillalogic.monkeytalk</groupId>
<artifactId>monkeytalk-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<aspectLibraries>
<aspectLibrary>
<groupId>com.gorillalogic.monkeytalk</groupId>
<artifactId>monkeytalk-agent</artifactId>
</aspectLibrary>
</aspectLibraries>
<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
<Xlint>ignore</Xlint>
<outxml>true</outxml>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
When packaging with this profile (mvn clean package -Pmonkeytalk), I've
got a lot of "cannot find symbol" when compiling. Here are some of them:
[ERROR]
/home/fibo/trabalho/NovaTwitRadio/trunk/SoongzAndroid/target/unpack/apklibs/com.google.android_support-v7-appcompat_apklib_18-patched/src/android/support/v7/internal/view/menu/MenuItemWrapperICS.java:[304,22]
cannot find symbol
[ERROR] symbol : method
setActionProvider(android.support.v7.internal.view.menu.MenuItemWrapperICS.ActionProviderWrapper)
[ERROR] location: interface android.view.MenuItem
[ERROR]
/home/fibo/trabalho/NovaTwitRadio/trunk/SoongzAndroid/target/unpack/apklibs/com.google.android_support-v7-appcompat_apklib_18-patched/src/android/support/v7/internal/view/menu/MenuItemWrapperICS.java:[312,54]
cannot find symbol
[ERROR] symbol : method getActionProvider()
[ERROR] location: interface android.view.MenuItem
[ERROR]
/home/fibo/trabalho/NovaTwitRadio/trunk/SoongzAndroid/target/unpack/apklibs/com.google.android_support-v7-appcompat_apklib_18-patched/src/android/support/v7/internal/view/menu/MenuItemWrapperICS.java:[358,8]
method does not override or implement a method from a supertype
[ERROR]
/home/fibo/trabalho/NovaTwitRadio/trunk/SoongzAndroid/target/unpack/apklibs/com.google.android_support-v7-appcompat_apklib_18-patched/src/android/support/v7/internal/view/menu/MenuItemWrapperICS.java:[363,8]
method does not override or implement a method from a supertype
[ERROR]
/home/fibo/trabalho/NovaTwitRadio/trunk/SoongzAndroid/target/unpack/apklibs/com.google.android_support-v7-appcompat_apklib_18-patched/src/android/support/v7/internal/view/menu/MenuWrapperFactory.java:[34,56]
cannot find symbol
[ERROR] symbol : variable ICE_CREAM_SANDWICH
[ERROR] location: class android.os.Build.VERSION_CODES
[ERROR]
/home/fibo/trabalho/NovaTwitRadio/trunk/SoongzAndroid/target/unpack/apklibs/com.google.android_support-v7-appcompat_apklib_18-patched/src/android/support/v7/internal/view/menu/MenuWrapperFactory.java:[41,56]
cannot find symbol
[ERROR] symbol : variable JELLY_BEAN
[ERROR] location: class android.os.Build.VERSION_CODES
[ERROR]
/home/fibo/trabalho/NovaTwitRadio/trunk/SoongzAndroid/target/unpack/apklibs/com.google.android_support-v7-appcompat_apklib_18-patched/src/android/support/v7/internal/view/menu/MenuWrapperFactory.java:[43,63]
cannot find symbol
[ERROR] symbol : variable ICE_CREAM_SANDWICH
[ERROR] location: class android.os.Build.VERSION_CODES
[ERROR]
/home/fibo/trabalho/NovaTwitRadio/trunk/SoongzAndroid/target/unpack/apklibs/com.google.android_support-v7-appcompat_apklib_18-patched/src/android/support/v7/internal/view/menu/MenuWrapperFactory.java:[50,56]
cannot find symbol
[ERROR] symbol : variable ICE_CREAM_SANDWICH
[ERROR] location: class android.os.Build.VERSION_CODES
[ERROR]
/home/fibo/trabalho/NovaTwitRadio/trunk/SoongzAndroid/target/unpack/apklibs/com.google.android_support-v7-appcompat_apklib_18-patched/src/android/support/v7/internal/view/menu/MenuWrapperFactory.java:[58,56]
cannot find symbol
[ERROR] symbol : variable ICE_CREAM_SANDWICH
[ERROR] location: class android.os.Build.VERSION_CODES
[ERROR]
/home/fibo/trabalho/NovaTwitRadio/trunk/SoongzAndroid/target/unpack/apklibs/com.google.android_support-v7-appcompat_apklib_18-patched/src/android/support/v7/internal/view/menu/MenuWrapperFactory.java:[66,56]
cannot find symbol
[ERROR] symbol : variable JELLY_BEAN
[ERROR] location: class android.os.Build.VERSION_CODES
After searching more about this, I found this:
http://stackoverflow.com/a/5038039
So, I added the process-sources and tried again. Now I have the following
error:
[INFO]
[INFO] trouble processing "javax/xml/namespace/QName.class":
[INFO]
[INFO] Ill-advised or mistaken usage of a core class (java.* or javax.*)
[INFO] when not building a core library.
[INFO]
[INFO] This is often due to inadvertently including a core library file
[INFO] in your application's project, when using an IDE (such as
[INFO] Eclipse). If you are sure you're not intentionally defining a
[INFO] core class, then this is the most likely explanation of what's
[INFO] going on.
[INFO]
[INFO] However, you might actually be trying to define a class in a core
[INFO] namespace, the source of which you may have taken, for example,
[INFO] from a non-Android virtual machine project. This will most
[INFO] assuredly not work. At a minimum, it jeopardizes the
[INFO] compatibility of your app with future versions of the platform.
[INFO] It is also often of questionable legality.
[INFO]
[INFO] If you really intend to build a core library -- which is only
[INFO] appropriate as part of creating a full virtual machine
[INFO] distribution, as opposed to compiling an application -- then use
[INFO] the "--core-library" option to suppress this error message.
[INFO]
[INFO] If you go ahead and use "--core-library" but are in fact
[INFO] building an application, then be forewarned that your application
[INFO] will still fail to build or run, at some point. Please be
[INFO] prepared for angry customers who find, for example, that your
[INFO] application ceases to function once they upgrade their operating
[INFO] system. You will be to blame for this problem.
[INFO]
[INFO] If you are legitimately using some code that happens to be in a
[INFO] core package, then the easiest safe alternative you have is to
[INFO] repackage that code. That is, move the classes in question into
[INFO] your own package namespace. This means that they will never be in
[INFO] conflict with core system classes. JarJar is a tool that may help
[INFO] you in this endeavor. If you find that you cannot do this, then
[INFO] that is an indication that the path you are on will ultimately
[INFO] lead to pain, suffering, grief, and lamentation.
[INFO]
[INFO] 1 error; aborting
[INFO]
------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 31.333s
[INFO] Finished at: Thu Aug 22 15:54:23 BRT 2013
[INFO] Final Memory: 29M/666M
[INFO]
------------------------------------------------------------------------
Before this, I see some log about the AspectJ, for example:
[INFO] Join point 'method-call(void
android.widget.TextView.setText(java.lang.CharSequence))' in Type
'com.devspark.appmsg.AppMsg' (AppMsg.java:144) advised by before advice
from 'com.gorillalogic.fonemonkey.aspects.SetText'
(monkeytalk-agent-1.0.56.jar!SetText.class:26(from SetText.aj))
[INFO] Join point 'method-call(void
com.devspark.appmsg.AppMsg.setText(java.lang.CharSequence))' in Type
'com.devspark.appmsg.AppMsg' (AppMsg.java:286) advised by before advice
from 'com.gorillalogic.fonemonkey.aspects.SetText'
(monkeytalk-agent-1.0.56.jar!SetText.class:26(from SetText.aj))
[INFO] Join point 'method-call(void
android.widget.TextView.setText(java.lang.CharSequence))' in Type
'com.devspark.appmsg.AppMsg' (AppMsg.java:302) advised by before advice
from 'com.gorillalogic.fonemonkey.aspects.SetText'
(monkeytalk-agent-1.0.56.jar!SetText.class:26(from SetText.aj))
If I remove the monkeytalk dependency of my profile and remove the , the
build works with no problem.
One more detail, I'm getting the monkeytalk from this repository:
<repository>
<id>monkeytalk</id>
<name>MonkeyTalk</name>
<url>http://simiiformes.gorillalogic.com:8080/artifactory/release</url>
</repository>
Since I have never tried using AspectJ with Android, I have no idea of
what is the problem.
Does someone have any idea to help me?
UPDATE:
Now the build is working, but I have an exception when I try to open the app.
To solve the last problem I was having, I changed the dependency of
MonkeyTalk to:
<dependency>
<groupId>com.gorillalogic.monkeytalk</groupId>
<artifactId>monkeytalk-agent</artifactId>
<version>${monkeytalk-version}</version>
<exclusions>
<exclusion>
<groupId>com.gorillalogic.monkeytalk</groupId>
<artifactId>monkeytalk-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
</exclusion>
</exclusions>
</dependency>
The problem was that the monkeytalk was adding a dependency to Android
without using the provided scope.
Now, when running the app, I have the following exception:
08-22 16:30:23.583: ERROR/dalvikvm(16334): Could not find class
'org.aspectj.runtime.reflect.Factory', referenced from method
com.soongz.ui.fragment.PlusClientFragment.ajc$preClinit
08-22 16:30:23.583: WARN/dalvikvm(16334): VFY: unable to resolve
new-instance 5999 (Lorg/aspectj/runtime/reflect/Factory;) in
Lcom/soongz/ui/fragment/PlusClientFragment;
08-22 16:30:23.583: INFO/dalvikvm(16334): Could not find method
org.aspectj.runtime.reflect.Factory.makeJP, referenced from method
com.soongz.ui.fragment.PlusClientFragment.onCreate
08-22 16:30:23.583: DEBUG/dalvikvm(16334): DexOpt: unable to opt direct
call 0xb3f2 at 0x06 in
Lcom/soongz/ui/fragment/PlusClientFragment;.ajc$preClinit
08-22 16:30:23.583: WARN/dalvikvm(16334): Exception
Ljava/lang/NoClassDefFoundError; thrown while initializing
Lcom/soongz/ui/fragment/PlusClientFragment;
08-22 16:30:23.583: ERROR/AndroidRuntime(16334): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: org.aspectj.runtime.reflect.Factory
at
com.soongz.ui.fragment.PlusClientFragment.ajc$preClinit(PlusClientFragment.java:1)
at
com.soongz.ui.fragment.PlusClientFragment.<clinit>(PlusClientFragment.java)
at
com.soongz.service.autenticacao.AutenticadorGoogle.prepare(AutenticadorGoogle.java:60)
at
com.soongz.ui.MainActivity.initializeUnretainedInstanceFields(MainActivity.java:57)
at
br.com.cybereagle.androidlibrary.ui.helper.RetainedActivityHelper.onCreate(RetainedActivityHelper.java:34)
at
br.com.cybereagle.androidlibrary.ui.RetainedRoboFragmentActivity.onCreate(RetainedRoboFragmentActivity.java:36)
at android.app.Activity.performCreate(Activity.java:5133)
at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
08-22 16:30:23.593: WARN/ActivityManager(534): Force finishing activity
com.soongz/.ui.MainActivity
No comments:
Post a Comment