Yamuna
Yamuna

Reputation: 139

Unable to convert app bundle to APK in android

I am using Android studio 3.4.1. I was trying to convert the App bundle to APK using the bundle tool. I was unable to generate the APK file. I tried using Generate Apk file from aab file (android app bundle)

When I run the command

java -jar bundletool.jar build-apks  --bundle=app.aab --output=app.apks

I got the below error. Kindly suggest me a solution to generate the APK.

INFO: The APKs will be signed with the debug keystore found at 'C:\Users\~\
.android\debug.keystore'.
[BT:0.10.2] Error: com.android.tools.build.bundletool.model.Aapt2Command$Aapt2Ex
ception: Command '[C:\Users\~\AppData\Local\Temp\8658885577631656545\output
\windows\aapt2.exe, convert, --output-format, binary, -o, C:\Users\~\AppDat
a\Local\Temp\6789457478435634974\binary.apk, C:\Users\~\AppData\Local\Temp\
6789457478435634974\proto.apk]' didn't terminate successfully (exit code: -10737
41701). Check the logs.
java.lang.RuntimeException: com.android.tools.build.bundletool.model.Aapt2Comman
d$Aapt2Exception: Command '[C:\Users\~\AppData\Local\Temp\86588855776316565
45\output\windows\aapt2.exe, convert, --output-format, binary, -o, C:\Users\Yamu
na\AppData\Local\Temp\6789457478435634974\binary.apk, C:\Users\~\AppData\Lo
cal\Temp\6789457478435634974\proto.apk]' didn't terminate successfully (exit cod
e: -1073741701). Check the logs.
        at com.android.tools.build.bundletool.io.ConcurrencyUtils.waitFor(Concur
rencyUtils.java:59)
        at com.android.tools.build.bundletool.io.ConcurrencyUtils.waitForAll(Con
currencyUtils.java:42)
        at java.util.function.Function.lambda$andThen$1(Unknown Source)
        at java.util.stream.ReferencePipeline.collect(Unknown Source)
        at com.android.tools.build.bundletool.io.ApkSerializerManager.serializeA
pks(ApkSerializerManager.java:180)
        at com.android.tools.build.bundletool.io.ApkSerializerManager.populateAp
kSetBuilder(ApkSerializerManager.java:101)
        at com.android.tools.build.bundletool.commands.BuildApksManager.executeW
ithZip(BuildApksManager.java:229)
        at com.android.tools.build.bundletool.commands.BuildApksManager.execute(
BuildApksManager.java:110)
        at com.android.tools.build.bundletool.commands.BuildApksCommand.execute(
BuildApksCommand.java:524)
        at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain
.java:74)
        at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain
.java:46)
        Suppressed: java.io.UncheckedIOException: java.nio.file.FileSystemExcept
ion: C:\Users\~\AppData\Local\Temp\8658885577631656545: failed to delete on
e or more files; see suppressed exceptions for details
                at com.android.tools.build.bundletool.io.TempDirectory.close(Tem
pDirectory.java:59)
                at com.android.tools.build.bundletool.commands.BuildApksCommand.
execute(BuildApksCommand.java:525)
                ... 2 more
        Caused by: java.nio.file.FileSystemException: C:\Users\~\AppData\Lo
cal\Temp\8658885577631656545: failed to delete one or more files; see suppressed
 exceptions for details
                at com.google.common.io.MoreFiles.throwDeleteFailed(MoreFiles.ja
va:791)
                at com.google.common.io.MoreFiles.deleteRecursively(MoreFiles.ja
va:537)
                at com.android.tools.build.bundletool.io.TempDirectory.close(Tem
pDirectory.java:57)
                ... 3 more
                Suppressed: java.nio.file.DirectoryNotEmptyException: C:\Users\Y
amuna\AppData\Local\Temp\8658885577631656545\output\windows
                        at sun.nio.fs.WindowsFileSystemProvider.implDelete(Unkno
wn Source)
                        at sun.nio.fs.AbstractFileSystemProvider.delete(Unknown
Source)
                        at java.nio.file.Files.delete(Unknown Source)
                        at com.google.common.io.MoreFiles.deleteRecursivelyInsec
ure(MoreFiles.java:665)
                        at com.google.common.io.MoreFiles.deleteDirectoryContent
sInsecure(MoreFiles.java:685)
                        at com.google.common.io.MoreFiles.deleteRecursivelyInsec
ure(MoreFiles.java:658)
                        at com.google.common.io.MoreFiles.deleteDirectoryContent
sInsecure(MoreFiles.java:685)
                        at com.google.common.io.MoreFiles.deleteRecursivelyInsec
ure(MoreFiles.java:658)
                        at com.google.common.io.MoreFiles.deleteRecursively(More
Files.java:526)
                        ... 4 more
Caused by: java.util.concurrent.ExecutionException: com.android.tools.build.bund
letool.model.Aapt2Command$Aapt2Exception: Command '[C:\Users\~\AppData\Loca
l\Temp\8658885577631656545\output\windows\aapt2.exe, convert, --output-format, b
inary, -o, C:\Users\~\AppData\Local\Temp\6789457478435634974\binary.apk, C:
\Users\~\AppData\Local\Temp\6789457478435634974\proto.apk]' didn't terminat
e successfully (exit code: -1073741701). Check the logs.
        at com.google.common.util.concurrent.AbstractFuture.getDoneValue(Abstrac
tFuture.java:502)
        at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.j
ava:481)
        at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(Ab
stractFuture.java:83)
        at com.android.tools.build.bundletool.io.ConcurrencyUtils.waitFor(Concur
rencyUtils.java:49)
        ... 10 more
Caused by: com.android.tools.build.bundletool.model.Aapt2Command$Aapt2Exception:
 Command '[C:\Users\~\AppData\Local\Temp\8658885577631656545\output\windows
\aapt2.exe, convert, --output-format, binary, -o, C:\Users\~\AppData\Local\
Temp\6789457478435634974\binary.apk, C:\Users\~\AppData\Local\Temp\67894574
78435634974\proto.apk]' didn't terminate successfully (exit code: -1073741701).
Check the logs.
        at com.android.tools.build.bundletool.model.Aapt2Command$CommandExecutor
.execute(Aapt2Command.java:62)
        at com.android.tools.build.bundletool.model.Aapt2Command$1.convertApkPro
toToBinary(Aapt2Command.java:36)
        at com.android.tools.build.bundletool.io.ApkSerializerHelper.writeToZipF
ile(ApkSerializerHelper.java:159)
        at com.android.tools.build.bundletool.io.ApkSerializerHelper.writeToZipF
ile(ApkSerializerHelper.java:144)
        at com.android.tools.build.bundletool.io.SplitApkSerializer.writeToDisk(
SplitApkSerializer.java:75)
        at com.android.tools.build.bundletool.io.SplitApkSerializer.writeSplitTo
Disk(SplitApkSerializer.java:53)
        at com.android.tools.build.bundletool.io.ApkSetBuilderFactory$ApkSetArch
iveBuilder.addSplitApk(ApkSetBuilderFactory.java:105)
        at com.android.tools.build.bundletool.io.ApkSerializerManager$ApkSeriali
zer.serialize(ApkSerializerManager.java:376)
        at com.android.tools.build.bundletool.io.ApkSerializerManager.lambda$nul
l$3(ApkSerializerManager.java:184)
        at com.google.common.util.concurrent.TrustedListenableFutureTask$Trusted
FutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:117)
        at com.google.common.util.concurrent.InterruptibleTask.run(Interruptible
Task.java:38)
        at com.google.common.util.concurrent.TrustedListenableFutureTask.run(Tru
stedListenableFutureTask.java:77)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

Upvotes: 4

Views: 5816

Answers (3)

Martin Zeitler
Martin Zeitler

Reputation: 76579

Fix permissions or take ownership of C:\\Users\~\Appdata\Local\Temp... it cannot delete there. That profile path with a ~ is even quite strange for Windows, because ~ indicates the current user's home directory on Linux. Actually, ~ would have to be the current Windows user name, so that it would inherit the permissions from the current user's profile directory ...which it doesn't, and that's exactly why it fails.

Linking C:\\Users\~ to C:\\Users\username might be an easy way to work around the problem, when not being able to change the ~ for temporary storage.

Fell free to file an issue on GitHub, if the latest version of bundletool still picks up the user profile directory wrongfully. Could image that the Linux sub-system might interfere, because that ~ is not "normal" for Windows.

Upvotes: 0

Mani
Mani

Reputation: 11

Hi Your using Android Studio, My Theme is why don't you follow traditional Approach in Android Studio.

Step 1 --> Open Android Studio and Select Build. Step 2 --> Select Build Bundle/ APK Then you can see 2 Options Build APK and Build Bundle. Step 3 --> Select Build APK for APK (It is for Normal APK).

For signed APK also same theme

You might know this things but I don't your requirement to use Commands and conversion from .aab to .apk

Upvotes: -2

Sanjay Bhalani
Sanjay Bhalani

Reputation: 2464

You need to download the latest bundletool.jar, After downloading bundle tool you need to open a terminal with the same path as bundle tool located. perform below command you can generate APKS.

1 Below command creates a set of unsigned APKs.

java -jar bundletool.jar build-apks  --bundle=app.aab --output=unsigned.apks

2 Below command creates a set of Signed APKs.

java -jar bundletool.jar build-apks  --bundle=app.aab --output=signed.apks --ks=test.jks --ks-key-alias=replaceyouralieas

Above command will ask you to enter your Keystore password, you need to enter your Keystore password.

3 Below command will find correct apk for your device & install into the device

java -jar bundletool.jar install-apks --apks=signed.apks 

For more detail

Upvotes: 7

Related Questions