通过使用Ant的工具(在Android Studio之外)将MonkeyTalk代理集成到APK中

时间:2015-02-11 10:03:27

标签: android ant monkeytalk

我正在使用Android Studio,我尝试将MonkeyTalk代理集成到带有Ant的APK中。

基本上我遵循了以下步骤:

  

1.下载MonkeyTalk 2.0.1 Pro Beta

     

2.在桌面上创建一个名为“example”的新空文件夹或任何你喜欢的文件

     

3.将monkeytalkpro / agents / android / monkeytalk-agent-2.0.1.jar复制到“example”目录中

     

4.将monkeytalkpro / ant / monkeytalkpro-ant-2.0.1.beta.jar复制到“example”目录中

     

5.将你的apk文件复制到“example”目录(本例中名为myapp.apk)

     

6.在“example”目录中创建一个名为build.xml的新文件,并填写以下内容:

     

<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-21"
        log="log.txt"
        verbose="true" />
    </target>
     

  7.打开终端并进入“示例”目录

     

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

     

9.该命令应运行,然后在“示例”目录中生成一个兼容monkeytalk的apk,标题为“myapp-post-instrumented.apk”

     

警告:检测过程似乎存在错误   还会在标题为“example”目录中放置另一个文件   “myapp-instrumented.apk”,但此文件将为空。所以要确保   您的目标文件的标题不是“myapp-instrumented.apk”   build.xml文件或此空文件将覆盖您的monkeytalk   兼容文件。

来源:http://w3facility.org/question/android-studio-and-monkeytalk/#answer-23016422

我做过和原始步骤有两点不同:

  1. MonkeyTalk代理和ant jar的实际版本是2.0.10,而不是2.0.1

  2. 使用编译工具21.1.2,集成在monkeytalkpro-ant-2.0.10.beta.jar中的APKTool无法提取文件。所以,我已经更新了APKTool并生成了一个新jar。你可以在这里找到它: https://www.dropbox.com/s/qsjaz5g15hy9i7k/monkeytalkpro-ant-2.0.10.beta.mod.jar?dl=0

  3. 但有了这个修复的事件,蚂蚁无法&#34;仪器&#34; APK。 Ant有问题dex文件。

    感谢任何帮助和建议。

    P.d.1:我试图用uphyca(v0.9.7)编译带有facej的gradle android插件的Android工作室,但它不起作用。它会编译项目,但是当我尝试启动它时会崩溃。

    P.d.2:这是一些日志:

      

    -pre编译:

         

    -compile:

         

    -post编译:

         

    -obfuscate:

         

    -dex:         [dex]输入:/ private / var / folders / fb / xhjph6n17sl_tnc7gfs_0ny80000gp / T / tmp_AndroidInstrumentor1423638478563_1 / app-debug / bin / classes         [dex]输入:/private/var/folders/fb/xhjph6n17sl_tnc7gfs_0ny80000gp/T/tmp_AndroidInstrumentor1423638463_1/app-debug/libs/monkeytalk-agent-2.0.10.jar         [dex]输入:/private/var/folders/fb/xhjph6n17sl_tnc7gfs_0ny80000gp/T/tmp_AndroidInstrumentor1423638478563_1/app-debug/libs/weaved.jar         [dex] Pre-Dexing /private/var/folders/fb/xhjph6n17sl_tnc7gfs_0ny80000gp/T/tmp_AndroidInstrumentor1423638478563_1/app-debug/libs/monkeytalk-agent-2.0.10.jar    - &GT; monkeytalk剂-2.0.10-3ffc60da466c609b3dc28c1c7533ad15.jar         [dex] Pre-Dexing /private/var/folders/fb/xhjph6n17sl_tnc7gfs_0ny80000gp/T/tmp_AndroidInstrumentor1423638478563_1/app-debug/libs/weaved.jar    - &GT;编织,0d60e12eb7c45a42662ee42c5398a922.jar          [DX]          [dx]模拟的例外情况:          [dx]本地0005:无效          [DX]          [dx] ...在字节码偏移量0000000b处          [dx] locals [0000]:Landroid / support / v7 / widget / ActionMenuView;          [dx] locals [0001]:Landroid / view / ViewGroup $ LayoutParams;          [dx]当地人[0002]:          [dx]当地人[0003]:          [dx]当地人[0004]:          [dx]当地人[0005]:          [dx] ......在块000b上工作          [dx] ...在处理方法generateLayoutParams时:( Landroid / view / ViewGroup $ LayoutParams;)Landroid / support / v7 / widget / ActionMenuView $ LayoutParams;          [dx] ...同时处理generateLayoutParams(Landroid / view / ViewGroup $ LayoutParams;)Landroid / support / v7 / widget / ActionMenuView $ LayoutParams;          [dx] ...同时处理android / support / v7 / widget / ActionMenuView.class          [DX]          [dx] 1错误;中止

         

    建立失败   /private/var/folders/fb/xhjph6n17sl_tnc7gfs_0ny80000gp/T/tmp_AndroidInstrumentor1423638478563_1/app-debug/build_master.xml:892:   执行此行时发生以下错误:   /private/var/folders/fb/xhjph6n17sl_tnc7gfs_0ny80000gp/T/tmp_AndroidInstrumentor1423638478563_1/app-debug/build_master.xml:894:   执行此行时发生以下错误:   /private/var/folders/fb/xhjph6n17sl_tnc7gfs_0ny80000gp/T/tmp_AndroidInstrumentor1423638478563_1/app-debug/build_master.xml:906:   执行此行时发生以下错误:   /private/var/folders/fb/xhjph6n17sl_tnc7gfs_0ny80000gp/T/tmp_AndroidInstrumentor1423638478563_1/app-debug/build_master.xml:283:   null返回:1

         

    总时间:14秒:错误:进程退出并显示错误:1(退出   价值:1)

         

    已检测的APK文件未在以下位置创建:   /private/var/folders/fb/xhjph6n17sl_tnc7gfs_0ny80000gp/T/tmp_AndroidInstrumentor1423638478563_1/app-debug/bin/app-debug-debug.apk

         

    错误检测apk &Users/monkeyTalk/app-debug.apk':   在以下位置未创建检测的APK文件:   /private/var/folders/fb/xhjph6n17sl_tnc7gfs_0ny80000gp/T/tmp_AndroidInstrumentor1423638478563_1/app-debug/bin/app-debug-debug.apk

         

    com.gorillalogic.monkeytalk.instrumentor.android.AndroidInstrumentor $ InstrumentationException:   在以下位置未创建检测的APK文件:   /private/var/folders/fb/xhjph6n17sl_tnc7gfs_0ny80000gp/T/tmp_AndroidInstrumentor1423638478563_1/app-debug/bin/app-debug-debug.apk     在   com.gorillalogic.monkeytalk.instrumentor.android.AndroidInstrumentor.copyInstrumentedApk(AndroidInstrumentor.java:244)     在   com.gorillalogic.monkeytalk.instrumentor.android.AndroidInstrumentor.beginInstrumentation(AndroidInstrumentor.java:173)     在   com.gorillalogic.monkeytalk.instrumentor.android.AndroidInstrumentor.instrumentApk(AndroidInstrumentor.java:130)     在   com.gorillalogic.monkeytalk.ant.InstrumentTask.execute(InstrumentTask.java:62)     在   org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:606)at   org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)     在org.apache.tools.ant.Task.perform(Task.java:348)at   org.apache.tools.ant.Target.execute(Target.java:390)at   org.apache.tools.ant.Target.performTasks(Target.java:411)at at   org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)     在org.apache.tools.ant.Project.executeTarget(Project.java:1368)at   org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)     在org.apache.tools.ant.Project.executeTargets(Project.java:1251)处   org.apache.tools.ant.Main.runBuild(Main.java:809)at   org.apache.tools.ant.Main.startAnt(Main.java:217)at   org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)at at   org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

    这是完整的日志: https://www.dropbox.com/s/y3mo9ifgalpzf29/log.txt?dl=0

    更新

    这是build.gradle文件的内容。

    apply plugin: 'com.android.application'
    apply plugin: 'robolectric'
    
    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.2"
    
        defaultConfig {
            applicationId "com.jiahaoliuliu.monkeytalk"
            minSdkVersion 14
            targetSdkVersion 19
            versionCode 52
            versionName "1.9999"
    
            multiDexEnabled true
            testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
    
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
    
            monkeytalk.initWith(buildTypes.debug)
            monkeytalk {
                applicationIdSuffix ".monkey"
            }
        }
    
        sourceSets {
            androidTest {
                setRoot('src/test')
            }
        }
    
        dexOptions {
            javaMaxHeapSize "4g"
        }
    
        lintOptions {
            checkReleaseBuilds false
            // Or, if you prefer, you can continue to check for errors in release builds,
            // but continue the build even when errors are found:
            abortOnError false
        }
    
        dependencies {
            compile fileTree(dir: 'libs', include: '*.jar')
            compile 'com.android.support:appcompat-v7:21.+'
            compile 'com.github.chrisbanes.photoview:library:1.2.3'
            compile 'com.etsy.android.grid:library:1.0.5'
            compile 'com.facebook.android:facebook-android-sdk:3.21.1'
            compile 'com.google.android.gms:play-services-base:6.5.+'
            compile 'com.google.android.gms:play-services-wallet:6.5.+'
            compile 'com.google.android.gms:play-services-ads:6.5.+'
            compile 'com.google.android.gms:play-services-maps:6.5.+'
            compile 'com.google.android.gms:play-services-drive:6.5.+'
            compile 'com.google.android.gms:play-services-appindexing:6.5.+'
            compile 'com.google.android.gms:play-services-location:6.5.+'
            compile 'com.google.android.gms:play-services-identity:6.5.+'
            compile 'com.google.android.gms:play-services-plus:6.5.+'
            compile 'com.android.support:multidex:1.0.0'
            compile project(':Adjust')
            compile project(':aFileChooser-cbccac1d1cb74a6d57d25c5ded61e4bf4fc40c91')
            compile 'com.parse.bolts:bolts-android:1.+'
            compile 'com.android.support:recyclerview-v7:+'
    
            androidTestCompile 'org.robolectric:robolectric:2.4'
            androidTestCompile('junit:junit:4.12')
            androidTestCompile('org.mockito:mockito-core:1.10.19')
        }
    }
    
    
    robolectric {
        include '**/*Test.class'
    }
    

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,但现在我能够检测到apk。 你应该在调试模式下有apk。不要在android studio中添加任何monkeytalk libs依赖项。在app / AndroidManifest.xml中添加GET_TASKS权限。在版本21中,这个api被折旧,所以你需要设置较低的目标,例如19。

如果您使用较低版本编译您的sdk,您将能够成功检测到apk。 :)

干杯, 苏曼