由于主项目的复杂库项目依赖关系,Jenkins 服务器上的自动化 Android UI 测试失败 [英] Failed automated Android UI-Tests on Jenkins-Server due to complex lib-project dependencies of the main project(s)

查看:24
本文介绍了由于主项目的复杂库项目依赖关系,Jenkins 服务器上的自动化 Android UI 测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短总结,我的项目结构如下:
- AB 是 android 库项目,其中 B 依赖于 A
- C(普通的android项目)依赖于B
- TC

Shortly summerized, my project structure is like follows:
- A and B are android lib-projects, where B depends on A
- C (normal android project) depends on B
- T is test-project of C

我的 jenkins 服务器上有相应的两个项目,一个用于 C,一个用于 T,它们有自己的构建脚本,实际上只使用 android 和 ant 命令.所以C的构建没有问题,但我无法获得T的工作构建.

I have correspondingly two projects on my jenkins server, one for C and one for T, which have their own script for build, using actually just android and ant commands. So there is no problem with the build of C, but i can't get work build of T.

工作"应该意味着,根据脚本,它要么不编译,要么在运行时由于某些缺少的类而失败,实际上不可能,或者不通过 dexing 阶段,因为添加重复项.

"Work" should there mean, that, depending on the script, it either don't compile or do fail at runtime because of some missing classes, that actually could't be, or don't pass the dexing phase because of adding duplicates.

所以很明显,依赖项有问题,但有趣的是,它在本地机器上运行非常好,使用 eclipse &在模拟器上.

So it's clear, that there is something wrong with the dependencies, but the interesting thing is that it works very nice on local machine with eclipse & on emulator.

这里是一个示例 shell 脚本代码,它实际上应该可以工作并创建一个 apk 文件:

So here an example shell-script code, that actually should work and create an apk-file:

cd project-test
android update test-project -m ../projectC -p .
ant clean debug

不幸的是,这导致来自 B 的一些类,我也将要测试,无法从 java 编译器中找到,我总是得到这样的错误:

This causes unfortunately that some classes from from B, that i'm also going to test, couldn't be found from the java compiler and i get always error like this:

...
[javac] Compiling 14 source files to /home/mehmed/git/project/test-project/bin/classes
[javac] SomeActivityTest.java:8: package com.mydomain.portal.android.project.activity does not exist
[javac] import com.mydomain.portal.android.project.activity.SomeClass1;
[javac]                                                        ^
[javac] SomeActivityTest.java:9: package com.mydomain.portal.android.project.data does not exist
[javac] import com.mydomain.portal.android.project.data.SomeClass2;
[javac]                                                    ^
[javac] SomeActivityTest.java:10: package com.project.portal.android.project.util does not exist
[javac] import com.mydomain.portal.android.project.util.SomeClass3;
[javac]                                                    ^
...

我确实尝试了几乎所有可能的方法来解决这个问题,甚至手动编辑 project.properties 文件并在 lib 的同时仅包含 BB 和 C-像这样的项目:

I did try almost everything possible to fix that, even manually editing the project.properties file and including just B or B and C at the same time as lib-projects like this:

cd project-test
android update test-project -m ../projectC -p .
echo "android.library.reference.1=../projectB" >> project.properties
# or even also projectA:
echo "android.library.reference.2=../projectA" >> project.properties
ant clean debug

这一次由于重复添加了来自 lib-projects 的类而导致 dexing 错误.

which results this time in dexing errors because of duplicate adding of the classes from lib-projects.

有人对解决这个问题有什么想法吗?提前感谢您的帮助!

Does somebody have any ideas about fixing this? Thanks for help in advance!

推荐答案

在您的测试项目 T 中,如果您有 SomeActivityTest 明确导入/使用库项目中的某些包/类 B 和/或 C,您必须将库项目添加为测试项目的依赖项,因为在项目构建时需要引用的包/类.如果不这样做,编译测试项目时会出现以下错误:

In your Test Project T, if you have SomeActivityTest that explicitly import/use some package/class from Library Project B and/or C, you have to add the Library Project as a dependency of Test project, as the referenced package/class is required at project build time. if you don't, you will get the following error when compile you Test Project:

[javac] SomeActivityTest.java:8: package com.mydomain.portal.android.project.activity does not exist
[javac] import com.mydomain.portal.android.project.activity.SomeClass1;
[javac]                                                        ^
[javac] SomeActivityTest.java:9: package com.mydomain.portal.android.project.data does not exist

如果您在主项目和测试项目中都添加了库项目作为依赖项,并使用 Ant 构建您的测试项目,则会导致在 dexing 步骤中出现重复条目​​.Eclipse ADT 插件知道如何正确处理这种情况,因此在使用 Eclipse 构建时不会遇到这种麻烦:

If you add Library Project as dependency in both Main Project and Test Project, and use Ant build you test project, it cause duplicate entries at dexing step. Eclipse ADT plugin knows how to hanlde this situation properly so you don't get this trouble when build with Eclipse:

[dx] UNEXPECTED TOP-LEVEL EXCEPTION:
[dx] java.lang.IllegalArgumentException: already added: Lcom/mydomain/...;
[dx]     at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[dx]     at com.android.dx.dex.file.DexFile.add(DexFile.java:163)

目前,有一个解决方法(ant 脚本中的脏修复),请查看我的答案 此处了解详情.

Currently, there is a workaround (dirty fix in ant script), check out my answer here for details.

请注意,最新的 SDK 版本 r17 获得了许多错误修复和改进.根据 changelog,它声称现在 SDK 可以更智能地处理重复依赖项,尽管我还没有厌倦测试项目.也许你可以试一试,看看它是否有效.希望这会有所帮助.

Note that the most recent SDK release r17 which got many bug fix and improvement. According to the changelog, it claims that now SDK can deal with duplicate dependencies more smarter, although I haven't tired myself with Test Project yet. Probably you can give it a shot and see if it works. Hope this helps.

这篇关于由于主项目的复杂库项目依赖关系,Jenkins 服务器上的自动化 Android UI 测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆