Issue
Until a few weeks ago, my Android connected tests were working correctly. Now I receive the same error whether connected to a physical device or a VM.
In both cases, adb devices shows that ADB is connected.
I'm running the following command line:
./gradlew --rerun-tasks connectedAndroidTest
If I run one of the connected tests from inside Android Studio, it runs. However, I need the command line for automated testing as part of our nightly builds and our release process.
Here is the failing output:
> 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
The file it is trying to install does in fact exist:
ls -l /home/smm/hcs/orc.trunk.java11/tablet/android/ORConnect/app/build/outputs/apk/debug/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9\$_run_closure1\[email protected]
-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'
At this point, I'm baffled as to why Gradle is failing. Any ideas?
Update 1
Gradle version:
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
I'm trying to run the tests on these devices:
- Samsung Galaxy Tab A 10.1 - (SM-T580) - Android 7.0
- Virtual Box VM (2 CPUs, 2 Gigs Ram - 8 Gigs Hard Drive) - Android 7.1 (from http://www.android-x86.org/)
Update 2
Martin Zeitler suggested trying adb push and see what happens. Oddly, it succeeds:
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\[email protected] /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)
I can access the directory with adb shell too:
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
Update 3
It is worth noting that it isn't just my laptop that experiences the problem, but also I our build system (Jenkins under Windows vs. my laptop under Windows).
Update 4
Additional logging turned on:
> 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)
Running it on my shell prompt gives the same results:
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)
I just noticed that am get-config seems to be failing before the pm install. However, if I run that on the command line, it succeeds:
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
Update 5 I think I'm getting closer. I can see from the last failed build that it failed with:
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
If I use adb shell ls /data/local/tmp/, I can see that the file does exist. However, if I run:
$ adb shell ls "/data/local/tmp/ORConnect-3.1.0-build_st1vdmehqb3wug0ysb60kna9$_run_closure1$_closure5@c92421a-debug.apk"
ls: /data/local/tmp/[email protected]: No such file or directory
Note that the file name passed to ls is not the file name ls claims it can't find. My current theory is that Android is not the escaping the $ correctly in the pm install command. Anyone have any ideas where those $s came from or how to get rid of them?
Solution
So there are a variety of problems that turned out to be working together to make this hard to figure out.
First, the install is using pm and failing, because the APK being generated has $'s in it. That is a problem only because Gradle/Android/Someone is not smart enough to properly escape those out in the pm command (never mind that the upload to the device worked correctly).
So, where did the $'s come from? Well, turns out they are placeholders for versionName it the defaultConfig. Here is a snippet from the app.gradle file:
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"
}
The value for versionString is generated in the top level gradle file:
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 };
The versionString is generated using Lazy Property Evaluation (https://reflectoring.io/gradle-lazy-property-evaluation/).
Why did we do this? Well, it turns out this project is connected to a much bigger project, with a Java Server and traditional Java Client. Naturally, it is useful to share code and version information as we build a Server/Client/Android applications at the same time. So, the version information comes from the older (traditional) Server/Client projects (not Android or Gradle related). We read the major, minor, patch and build (SVN revision number) from files. Unfortunately, the last file is generated by the ant scripts that build the traditional projects and may not be present when Gradle is called to build the Android project.
So, we switched to using the lazy property evaluation, which solved our build problem when the file is not present and created this new problem. Switching away from it resolved this particular problem.
Now my top level Gradle build file looks like:
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
Answered By - Stephen M -on strike-
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.