8

Has anybody successfully set up MonkeyTalk with Android Studio?

My main problem at this point is I don't see a way to set the java compiler to aspectj

I believe there's some way to do this in custom_rules.xml, but I haven't seen how to do this yet.

This leads to a maybe unrelated problem, but in the newest version of Android Studio that I'm using (0.1.1), I don't see a way to run an ant build from inside Android Studio.

Any suggestions appreciated!

0

4 Answers 4

6

An approach that I have found works well for is to use the the android-gradle-aspject-j plugin found here https://github.com/uPhyca/gradle-android-aspectj-plugin

What I have done is create a new build type (monkeytalk), included the monkey talk jar as a compile dependency for only this build type and applied the above mentioned aspectj plugin. This ensures that the monkey talk weaving occurs for the monkey talk build type.

Here is a snippet of what my build xml looks like

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.5'
  }
}
apply plugin: 'com.android.application'
apply plugin: 'android-aspectj'

android {
  buildTypes {
    monkeytalk.initWith(buildTypes.debug)
    monkeytalk {
      applicationIdSuffix ".monkey"
    }
  }
}

dependencies {
  monkeytalkCompile(files("monkey-talk/monkeytalk-agent-2.0.5.jar"))
}

I also added an AndroidManifest.xml file for the monkey talk build types which adds the required permissions, i.e. GET_TASKS and INTERNET

For a complete sample app, have a look at this github repo https://github.com/georgepapas/android-gradle-monkey-talk-demo/

9
  • could you show your project with configured monkeyTalk, please?
    – Kate Geld
    Jul 16, 2014 at 12:44
  • No probs. consider up voting the answer if you find it helpful. Cheers Jul 17, 2014 at 6:11
  • Thank you for the demo @GeorgePapas. After starting your demo and then going to the MonkeyTalkIDE, it looks like the record button is still disabled. Have you gotten it to work successfully with MonkeyTalk Community?
    – Paul
    Jul 18, 2014 at 21:51
  • @ShyGuy Yes. You'll need to ensure you've connected your ide to the emulator Jul 19, 2014 at 10:26
  • Thank you @GeorgePapas I got it to work. I actually just needed to restart my MonkeyTalkIDE :) I got things working with your sample app, but unfortunately my real app crashes with a VerifyError when trying to load my main activity (something about signature error in the APK file). I know this is beyond the scope of this question now, but have you encountered such a thing before?
    – Paul
    Jul 21, 2014 at 13:36
3

MonkeyTalk (as of version 2.0.1) has now released tools to "instrument" your already built regular apk with MonkeyTalk independent of any IDE. Steps to complete this instrumentation process in OS X:

1.Download MonkeyTalk 2.0.1 Pro Beta

2.Create a new empty folder on desktop titled "example" or whatever you like

3.Copy monkeytalkpro/agents/android/monkeytalk-agent-2.0.1.jar into "example" directory

4.Copy monkeytalkpro/ant/monkeytalkpro-ant-2.0.1.beta.jar into "example" directory

5.Copy your apk file into "example" directory (named myapp.apk for this example)

6.Create a new file called build.xml in "example" directory and fill it with the following:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:mt="antlib:com.gorillalogic.monkeytalk.ant">

    <target name="instru">
        <mt:instrument
            srcfile="myapp.apk"
            destfile="myapp-post-instrumented.apk"
            agent="monkeytalk-agent-2.0.1.jar"
            androidsdk="/path/to/your/sdk"
            androidtarget="android-17"
            log="log.txt"
            verbose="true" />
        </target>

</project>

7.Open terminal and cd into your "example" directory

8.Issue command ant instru -lib monkeytalkpro-ant-2.0.1.beta.jar

9.The command should run and then produce a monkeytalk compatible apk in your "example" directory titled "myapp-post-instrumented.apk"

WARNING: There seems to be a bug where the instrumentation process will also place another file in your "example" directory titled "myapp-instrumented.apk", but this file will be empty. So make sure your destination file is not titled "myapp-instrumented.apk" in your build.xml file or this empty file will overwrite your monkeytalk compatible file.

5
  • I have problem with this approach on windows. Dont know if it is platform specific, but ant task says "BUILD SUCCESSFUL" but no apk is created. When I look to log.txt file, i can see a few thousand lines in this style - [aapt] path\res\values-xxhdpi\drawables.xml:16: error: Resource entry apptheme_textfield_focused_holo_light is already defined. [aapt] res\drawable-xhdpi\apptheme_textfield_focused_holo_light.9.png:0: Originally defined here. then "BUILD FILED" error is printed and some stacktrace from instrumentor. Do i have to specify some libraries or something?
    – Billda
    Feb 11, 2014 at 13:03
  • Did you copy both jar files into your example directory? Also did you specify the jar with the -lib command line argument?
    – Adam Johns
    Feb 11, 2014 at 14:26
  • Hmmm I'm not sure what the issue could be. I would start a new topic on the monkey talk forums and explain your issue and paste the stack trace. Usually a member of the monkey talk staff will comment.
    – Adam Johns
    Feb 11, 2014 at 16:13
  • Thumbs up this approach! You may find however the instrumentation process fails due to issues with unresolvable styles if you are using an app compat library. It looks like an older version of apktool is being used which does not contain references to newer styles as specified in app compat. A workaround for this is to specifiy these styles in your app, although that will most likely leave your app looking weird. Jun 26, 2014 at 1:18
  • I got everything right it build successfully, i got the log file but the only thing that i needed is an instrumented APK which i didn't. Why is that and why did it say build successful then? Can somebody help me here.
    – ashim888
    Aug 11, 2014 at 5:48
1

Android studio is built off of Intellij community edition, which, to my knowledge does not have AspectJ support built in.

You could try adding the Intellij AspectJ plugin - it looks like this should make it possible to setup AspectJ in Android Studio, although I haven't actually tried to get MonkeyTalk working with this yet.

2
  • Thanks Ben, it turns out the aspectJ plugin is available directly from Preferences->Plugin->Browse repositories. I installed it, but it I don't see an option in Preferences->Java Compiler->Use compiler to pick an ajc compiler, which is a necessary step for MonkeyTalk. Any other ideas? May 30, 2013 at 22:33
  • 1
    AFAIK AspectJ support in IDEA is only available in commercial editions, but then out of the box with plug-ins directly supported by JetBrains.
    – kriegaex
    May 31, 2013 at 14:44
0

If your Android Studio project is Maven type, than all you need to do is add some AspectJ dependencies, MonkeyTalk-Agent dependency and make maven profile with configuration for those dependencies.

At first you will need to deploy downloaded previously (available here) jar file with MonkeyTalk-Agent for Android to you local Maven repo. If you have proper configuration of maven you can do it with following command:

mvn install:install-file -Dfile=monkeytalk-agent-2.0.4.jar -DgroupId="com.gorillalogic.monkeytalk" -DartifactId="monkeytalk-agent" -Dversion="2.0.4" -Dpackaging="jar" 

When you successfully complete this part, you can edit existing POM file of you project and add following to your project dependencies:

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.6.2</version>
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>1.6.2</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.gorillalogic.monkeytalk</groupId>
            <artifactId>monkeytalk-agent</artifactId>
            <version>2.0.4</version>
        </dependency>

Next step is to create maven profile that could add MonekyTalk during build:

<profile>
        <id>monkeytalk</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>aspectj-maven-plugin</artifactId>
                    <version>1.4</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                        <aspectLibraries>
                            <aspectLibrary>
                                <groupId>com.gorillalogic.monkeytalk</groupId>
                                <artifactId>monkeytalk-agent</artifactId>
                            </aspectLibrary>
                        </aspectLibraries>
                        <showWeaveInfo>true</showWeaveInfo>
                        <verbose>true</verbose>
                        <Xlint>ignore</Xlint>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>compile</goal>
                                <goal>test-compile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

Next step is to edit your app Manifest file giving following permission:

<!-- Monkeytalk permission -->
<uses-permission android:name="android.permission.GET_TASKS"/>

Now you project is set and ready to make MonkeyTalk app build. To to this you just need to use during project maven build process your new monkeytalk profile. Example of use in command line:

clean install android:deploy android:run -Pmonkeytalk

Now you can connect with you app trough MonkeyTalk IDE available here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.