Android Studio and MonkeyTalk?

試著忘記壹切 提交于 2019-11-29 14:52:14

问题


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!


回答1:


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/




回答2:


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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/16821039/android-studio-and-monkeytalk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!