bundletool icon indicating copy to clipboard operation
bundletool copied to clipboard

Unable to sign APK due to FileAlreadyExistsException

Open bengrah-miller opened this issue 4 years ago • 7 comments

Describe the bug Unable to generate APKS file from an AAB bundle, getting an Unable to sign APK error caused by a FileAlreadyExistsException within C:/Users/name/AppData/Local/Temp

Bundletool version(s) affected Version: 1.8.1

Stacktrace

[BT:1.8.1] Error: Unable to sign APK.
com.android.tools.build.bundletool.model.exceptions.CommandExecutionException: Unable to sign APK.
        at com.android.tools.build.bundletool.model.exceptions.InternalExceptionBuilder.build(InternalExceptionBuilder.java:57)
        at com.android.tools.build.bundletool.io.ApkSigner.signApk(ApkSigner.java:84)
        at com.android.tools.build.bundletool.io.ZipFlingerApkSerializerHelper.writeToZipFile(ZipFlingerApkSerializerHelper.java:173)
        at com.android.tools.build.bundletool.io.ZipFlingerApkSerializerHelper.writeToZipFile(ZipFlingerApkSerializerHelper.java:112)
        at com.android.tools.build.bundletool.io.StandaloneApkSerializer.writeToDiskInternal(StandaloneApkSerializer.java:76)
        at com.android.tools.build.bundletool.io.StandaloneApkSerializer.writeToDisk(StandaloneApkSerializer.java:43)
        at com.android.tools.build.bundletool.io.ApkSetBuilderFactory$ApkSetArchiveBuilder.addStandaloneApk(ApkSetBuilderFactory.java:130)
        at com.android.tools.build.bundletool.io.ApkSerializerManager$ApkSerializer.serialize(ApkSerializerManager.java:495)
        at com.android.tools.build.bundletool.io.ApkSerializerManager.lambda$null$4(ApkSerializerManager.java:233)
        at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:125)
        at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:69)
        at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:78)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.nio.file.FileAlreadyExistsException: C:\Users\bengrah\AppData\Local\Temp\ApkSigner2236382018700181045\signed.apk -> C:\Users\bengrah\AppData\Local\Temp\AutoValue_BuildApksCommand3237083126039129873\standalones\standalone-armeabi_mdpi.apk
        at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
        at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
        at sun.nio.fs.WindowsFileCopy.move(Unknown Source)
        at sun.nio.fs.WindowsFileSystemProvider.move(Unknown Source)
        at java.nio.file.Files.move(Unknown Source)
        at com.android.tools.build.bundletool.io.ApkSigner.signApk(ApkSigner.java:75)
        ... 13 more

To Reproduce

  1. Generated an AAB file using command ionic cordova build android --release
  2. New file created successfully, named aab-release.aab
  3. Run the following command: java -jar .\bundletool.jar build-apks --bundle=app-release.aab --output=./app-signed.apks --ks=C:/keystore/location/my.keystore --ks-key-alias=alias_name
  4. I'm prompted to enter the password for the keystore, enter the correct keystore password
  5. Hit Return, nothing happens for about 20s

Expected behavior Generated an APKS file with some sort of successful message on the console.

Known workaround N/A

Environment: Windows 10

bengrah-miller avatar Oct 22 '21 08:10 bengrah-miller

Could you please attach a sample project to reproduce this?

ymakhno avatar Nov 18 '21 15:11 ymakhno

Command line add : --mode=universal

xq48799220 avatar Mar 24 '22 11:03 xq48799220

I have the same problem as you. I solved the problem.

Command line add : --mode=universal

xq48799220 avatar Mar 24 '22 11:03 xq48799220

Hi @xq48799220 - I'll give that a go, what does that flag do?

bengrah-miller avatar Mar 28 '22 06:03 bengrah-miller

The APKS file contains only one APK. I'm only using it for testing. And the test passed.

xq48799220 avatar Mar 28 '22 06:03 xq48799220

I'll give that a go - just don't understand why the original error @xq48799220

bengrah-miller avatar Mar 28 '22 06:03 bengrah-miller

follow the error prompt. XXXXX /standalone-armeabi_mdpi.apk should be delete. but the deletion failed.

xq48799220 avatar Mar 28 '22 07:03 xq48799220

This should be fixed in the latest version.

ymakhno avatar Nov 04 '22 01:11 ymakhno