直到几周前,我的Android连接测试还正常工作。 现在,无论连接到物理设备还是 VM,我都会收到相同的错误。
在这两种情况下,adb devices
都表明 ADB 已连接。
我正在运行以下命令行:
./gradlew --rerun-tasks connectedAndroidTest
如果我从Android Studio内部运行其中一个连接的测试,它就会运行。 但是,我需要命令行进行自动化测试,作为我们夜间构建和发布过程的一部分。
下面是失败的输出:
> Task :app:connectedDebugAndroidTest
03:55:08 V/ddms: execute: running am get-config
03:55:09 V/ddms: execute 'am get-config' on '52007ba3c0fcb457' : EOF hit. Read: -1
03:55:09 V/ddms: execute: returning
03:55:10 V/ddms: execute: running pm install -r -t "/data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@658c9f0e-debug.apk"
03:55:11 V/ddms: execute 'pm install -r -t "/data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@658c9f0e-debug.apk"' on '52007ba3c0fcb457' : EOF hit. Read: -1
03:55:11 V/ddms: execute: returning
Unable to install /home/smm/hcs/orc.trunk.java11/tablet/android/ORConnect/app/build/outputs/apk/debug/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@658c9f0e-debug.apk
com.android.ddmlib.InstallException: Unknown failure (Error: failed to write; /data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9@658c9f0e-debug.apk (No such file or directory))
at com.android.ddmlib.Device.installRemotePackage(Device.java:1031)
at com.android.ddmlib.Device.installPackage(Device.java:902)
at com.android.ddmlib.Device.installPackage(Device.java:880)
at com.android.ddmlib.Device.installPackage(Device.java:869)
at com.android.builder.testing.ConnectedDevice.installPackage(ConnectedDevice.java:126)
at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:147)
at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:59)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
com.android.builder.testing.ConnectedDevice > runTests[SM-T580 - 7.0] FAILED
com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Unknown failure (Error: failed to write; /data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9@658c9f0e-debug.apk (No such file or directory))
at com.android.builder.testing.ConnectedDevice.installPackage(ConnectedDevice.java:132)
03:55:11 I/XmlResultReporter: XML test result file generated at /home/smm/hcs/orc.trunk.java11/tablet/android/ORConnect/app/build/outputs/androidTest-results/connected/TEST-SM-T580 - 7.0-app-.xml. Total tests 1, failure 1,
> Task :app:connectedDebugAndroidTest FAILED
[no message defined]
java.lang.RuntimeException: com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Unknown failure (Error: failed to write; /data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9@658c9f0e-debug.apk (No such file or directory))
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1431)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Unknown failure (Error: failed to write; /data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9@658c9f0e-debug.apk (No such file or directory))
at com.android.builder.testing.ConnectedDevice.installPackage(ConnectedDevice.java:132)
at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:147)
at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:59)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
... 4 more
Caused by: com.android.ddmlib.InstallException: Unknown failure (Error: failed to write; /data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9@658c9f0e-debug.apk (No such file or directory))
at com.android.ddmlib.Device.installRemotePackage(Device.java:1031)
at com.android.ddmlib.Device.installPackage(Device.java:902)
at com.android.ddmlib.Device.installPackage(Device.java:880)
at com.android.ddmlib.Device.installPackage(Device.java:869)
at com.android.builder.testing.ConnectedDevice.installPackage(ConnectedDevice.java:126)
... 7 more
它尝试安装的文件确实存在:
ls -l /home/smm/hcs/orc.trunk.java11/tablet/android/ORConnect/app/build/outputs/apk/debug/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@658c9f0e-debug.apk
-rw-rw-r-- 1 smm smm 15684152 Sep 11 15:55 '/home/smm/hcs/orc.trunk.java11/tablet/android/ORConnect/app/build/outputs/apk/debug/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@658c9f0e-debug.apk'
在这一点上,我对为什么Gradle失败感到困惑。 有什么想法吗?
更新 1
格拉德尔版本:
smm@smm-HP-ZBook-15-G2:~/hcs/orc.trunk.java11/tablet/android/ORConnect$ ./gradlew --version
------------------------------------------------------------
Gradle 4.6
------------------------------------------------------------
Build time: 2018-02-28 13:36:36 UTC
Revision: 8fa6ce7945b640e6168488e4417f9bb96e4ab46c
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 1.8.0_181 (Oracle Corporation 25.181-b13)
OS: Linux 4.15.0-54-generic amd64
我正在尝试在这些设备上运行测试:
- 三星银河标签A 10.1 - (SM-T580( - 安卓 7.0
- Virtual Box VM(2 个 CPU,2 Gigs Ram - 8 Gigs 硬盘( - Android 7.1(从 http://www.android-x86.org/起(
更新 2
Martin Zeitler建议尝试adb推送,看看会发生什么。 奇怪的是,它成功了:
smm@smm-HP-ZBook-15-G2:~/bin$ adb push /home/smm/hcs/orc.trunk.java11/tablet/android/ORConnect/app/build/outputs/apk/debug/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@2542336c-debug.apk /data/local/tmp/test.apk
/home/smm/hcs/orc.trunk.java11/tablet/android/ORConne...: 1 file pushed. 17.3 MB/s (15684098 bytes in 0.864s)
我也可以使用 adb 外壳访问目录:
smm@smm-HP-ZBook-15-G2:~/bin$ adb shell
gtaxlwifi:/ $ cd /data/local/tmp
gtaxlwifi:/data/local/tmp $ ls
ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@50729ffc-debug.apk
ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@658c9f0e-debug.apk
更新 3
值得注意的是,遇到问题的不仅仅是我的笔记本电脑,还有我的构建系统(Windows下的Jenkins与Windows下的笔记本电脑(。
更新 4
其他日志记录已打开:
> Task :app:installDebug
Task ':app:installDebug' is not up-to-date because:
Executed with '--rerun-tasks'.
02:40:41 V/ddms: execute: running am get-config
02:40:42 V/ddms: execute 'am get-config' on '52007ba3c0fcb457' : EOF hit. Read: -1
02:40:42 V/ddms: execute: returning
Installing APK 'ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@58873f75-debug.apk' on 'SM-T580 - 7.0' for app:debug
02:40:42 D/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@58873f75-debug.apk: Uploading ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@58873f75-debug.apk onto device '52007ba3c0fcb457'
02:40:42 D/Device: Uploading file onto device '52007ba3c0fcb457'
02:40:42 D/ddms: Reading file permision of /home/smm/hcs/orc.trunk.java11/tablet/android/ORConnect/app/build/outputs/apk/debug/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@58873f75-debug.apk as: rw-rw-r--
02:40:43 V/ddms: execute: running pm install -r -t "/data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@58873f75-debug.apk"
02:40:44 V/ddms: execute 'pm install -r -t "/data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@58873f75-debug.apk"' on '52007ba3c0fcb457' : EOF hit. Read: -1
02:40:44 V/ddms: execute: returning
Unable to install /home/smm/hcs/orc.trunk.java11/tablet/android/ORConnect/app/build/outputs/apk/debug/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@58873f75-debug.apk
com.android.ddmlib.InstallException: Unknown failure (Error: failed to write; /data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9@58873f75-debug.apk (No such file or directory))
at com.android.ddmlib.Device.installRemotePackage(Device.java:1031)
at com.android.ddmlib.Device.installPackage(Device.java:902)
at com.android.ddmlib.Device.installPackage(Device.java:880)
at com.android.ddmlib.Device.installPackage(Device.java:869)
在我的 shell 提示符上运行它会给出相同的结果:
smm@smm-HP-ZBook-15-G2:~/hcs/orc.trunk.java11/tablet/android/ORConnect$ adb shell pm install -r -t "/data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@58873f75-debug.apk"
Error: failed to write; /data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9@58873f75-debug.apk (No such file or directory)
我刚刚注意到am get-config
似乎在pm install
之前失败了. 但是,如果我在命令行上运行它,它会成功:
smm@smm-HP-ZBook-15-G2:~/hcs/orc.trunk.java11/tablet/android/ORConnect$ adb shell am get-config
config: en-rUS-ldltr-sw800dp-w1280dp-h776dp-xlarge-notlong-notround-land-notnight-hdpi-finger-keysexposed-nokeys-navhidden-nonav-v24
abi: armeabi-v7a,armeabi
更新 5我想我越来越近了。 我可以从上次失败的构建中看到它失败了:
03:04:25 V/ddms: execute: running pm install -r -t "/data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@c92421a-debug.apk"
03:04:26 V/ddms: execute 'pm install -r -t "/data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@c92421a-debug.apk"' on '52007ba3c0fcb457' : EOF hit. Read: -1
如果我使用adb shell ls /data/local/tmp/
,我可以看到该文件确实存在。 但是,如果我运行:
$ adb shell ls "/data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@c92421a-debug.apk"
ls: /data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9@c92421a-debug.apk: No such file or directory
请注意,传递给ls
的文件名不是ls
声称找不到的文件名。 我目前的理论是,Android 不是在pm install
命令中正确转义$
。 任何人都知道这些$s来自哪里或如何摆脱它们?
可能没有足够的空间来上传包:Error: failed to write; /data/local/tmp/...
从错误消息中不清楚目录或包是否不存在。
当它只存在于本地文件系统中,而不是错误消息所指的目标设备文件系统中时,它是毫无用处的(您仍然可以尝试adb push
看看它抱怨什么(。
确保adb
均匀地在路径上,因为从理论上讲,这可能是另一个可能的原因。
因此,有各种各样的问题共同作用,使这很难弄清楚。
首先,安装正在使用 pm 并且失败,因为生成的 APK 中包含 $。 这只是一个问题,因为 Gradle/Android/Someone 不够聪明,无法在 pm 命令中正确逃脱这些内容(不要介意上传到设备的工作正常(。
那么,美元从何而来? 好吧,事实证明它们是版本的占位符将其命名为默认配置。 以下是 app.gradle 文件中的一个片段:
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 24
//noinspection OldTargetApi
targetSdkVersion 26
// The versionCode and versionName are defined in the top level (android) build.gradle file.
versionCode versionValue
versionName versionString()
buildConfigField "String", "BUILD_TIMESTAMP", """+buildTimeStamp+"""
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
versionString
的值在顶级 gradle 文件中生成:
def major = rootProject.file('../../../nb/major.dat').text.trim()
def minor = rootProject.file('../../../nb/minor.dat').text.trim()
def patch = rootProject.file('../../../nb/patch.dat').text.trim()
versionString = { major + "." + minor + "." + patch + "-" + revnum };
版本字符串是使用惰性属性计算 (https://reflectoring.io/gradle-lazy-property-evaluation/( 生成的。
我们为什么要这样做? 好吧,事实证明这个项目连接到一个更大的项目,具有Java服务器和传统的Java客户端。 当然,在我们同时构建服务器/客户端/Android 应用程序时共享代码和版本信息很有用。 因此,版本信息来自较旧的(传统的(服务器/客户端项目(与Android或Gradle无关(。 我们从文件中读取主要、次要、补丁和构建(SVN 修订版号(。 不幸的是,最后一个文件是由构建传统项目的 ant 脚本生成的,当调用 Gradle 来构建 Android 项目时可能不存在。
因此,我们改用惰性属性评估,当文件不存在时,它解决了我们的构建问题并创建了这个新问题。 远离它解决了这个特殊问题。
现在,我的顶级 Gradle 构建文件如下所示:
def major = rootProject.file('../../../nb/major.dat').text.trim()
def minor = rootProject.file('../../../nb/minor.dat').text.trim()
def patch = rootProject.file('../../../nb/patch.dat').text.trim()
revnumFile = rootProject.file('../../../nb/build.dat')
// Before adding the Revision Number to our Version String, we need to make sure the file exists
def revnum = '';
if (revnumFile.exists()) {
revnum = revnumFile.text.trim()
}
versionString = major + "." + minor + "." + patch + "-" + revnum