/android-studio-dynamic-apk-name

Test case for an issue with Android Studio and Gradle dynamic apk naming.

Primary LanguageJava

Missing/Old Apk. Test Case

Background

When executing a run configuration from Android Studio, external changes to apk names are not taken into consideration. It will use the name that was current at the last Gradle sync.

For example: if output apk naming based on the contents of an external file then Android Studio will attempt to install an apk based on the contents of that file at the last sync, not the one generated by this run. This will either install an incorrect apk, or present an error that the expected apk path does not exist.

Installing from the command line does not produce the same result. Running ./gradlew :app:installDebug works as expected.

Versions

This has been found with Android Studio versions 1.0.2, and 1.1.0.

Steps to Reproduce

  1. Import into Android Studio.
  2. Run the application, noting the apk filename and the version name displayed in the application.
  3. Change the contents of the version file in the root directory of the project.
  4. Run the application, noting that it runs the previously built apk, and displayed the previous version name.

Alternative: Delete the apk file from app/build/outputs/apk after step 2. This will cause step 4 to fail with an I/O Error (No such file or directory).

As previously noted running ./gradlew :app:installDebug will install the expected version.


License

The MIT License (MIT)

Copyright (c) 2015 Dave Spanton

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.