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)
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
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.
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
Related
as part of a custom Android build chain, I am calling "aapt2 link" in order to link the files generated by a previous call to "aapt2 compile" together. This works fine on Mac, but on Windows it fails with the following error:
failed to open file: The device does not recognize the command.
I'm using the same SDK versions, and the error happens on multiple systems, including my own those of users of our build chain.
I'm calling rapt as follows:
C:\Users\mh\AppData\Local\Android\sdk\build-tools\33.0.1\aapt2.exe
link
-v
-o c:\obj\destination.apk
--manifest c:\Obj\manifest.xml
--java c:\Obj\java
-I C:\obj\android.jar
--proto-format
--min-sdk-version 26
--target-sdk-version 26
#c:\Obj\Aapt2LinkFiles.txt
(paths shortened for clarity here). All files listed in c:\Obj\Aapt2LinkFiles.txt exist, and aapt prints them all out, before emitting the error.
Does anyone have an idea what I could be missing?
As a side question: Is there a way to see, in Android Studio, how and with what parameters aapt2 is called as part of the normal automated build process? Because builds in Android Studio work fine (but I seem to not be able tom find any lace where there is a full build log, in the way that other IDEs such as Xcode or Visual Studio provide a textual overview of what actual tools get executed and with what parameters, as you build.
Thanx!
Update full command line for repro:
C:> C:\Users\mh\AppData\Local\Android\sdk\build-tools\33.0.1\aapt2.exe link -v -o c:\Obj\ForAAB.apk --manifest c:\Obj\m.xml --java c:\Obj\java -I C:\obj\a.jar --proto-format --min-sdk-version 26 --target-sdk-version 26 #c:\Obj\files.txt
Output
note: including C:\obj\a.jar.
note: linking package 'org.me.testapt2' using package ID 7f.
c:\Obj\res-aapt2\drawable-hdpi_icon.png.flat
c:\Obj\res-aapt2\drawable-ldpi_icon.png.flat
c:\Obj\res-aapt2\drawable-mdpi_icon.png.flat
c:\Obj\res-aapt2\drawable-xhdpi_icon.png.flat
c:\Obj\res-aapt2\drawable_icon.png.flat
c:\Obj\res-aapt2\layout_main.xml.flat: error: failed to open file: The device does not recognize the command. (22).
error: failed parsing input.
files can be found at https://www.dropbox.com/s/zuuopmhyzkd271u/Obj.zip?dl=0, unzip to C:\Obj
I am trying to turn an apk into aab, decompile with apktool, and build with aapt2 and bundletool (all in command line, without gradle).
After decompile, aapt2 compile and link looks good, but when I execute build-bundle with bundletool, I got this error. What went wrong? And How ow can i fix it?
F:\>java -jar "F:\tool\common\bundletool.jar" build-bundle --modules="F:\_workspace\20210714\decompile\base.zip" --output="F:\_workspace\20210714\decompile\base.aab"
[BT:1.7.0] Error: com.google.protobuf.InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag.
java.io.UncheckedIOException: com.google.protobuf.InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag.
at com.android.tools.build.bundletool.model.BundleModule$Builder.addEntry(BundleModule.java:357)
at com.android.tools.build.bundletool.model.BundleModule$Builder.addEntries(BundleModule.java:339)
at com.android.tools.build.bundletool.validation.BundleModulesValidator.toBundleModule(BundleModulesValidator.java:94)
at com.android.tools.build.bundletool.validation.BundleModulesValidator.lambda$validate$0(BundleModulesValidator.java:79)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Collections$2.tryAdvance(Collections.java:4719)
at java.util.Collections$2.forEachRemaining(Collections.java:4727)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566)
at com.android.tools.build.bundletool.validation.BundleModulesValidator.validate(BundleModulesValidator.java:80)
at com.android.tools.build.bundletool.commands.BuildBundleCommand.execute(BuildBundleCommand.java:231)
at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:73)
at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:49)
Caused by: com.google.protobuf.InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag.
at com.google.protobuf.InvalidProtocolBufferException.invalidEndTag(InvalidProtocolBufferException.java:106)
at com.google.protobuf.CodedInputStream$StreamDecoder.checkLastTagWas(CodedInputStream.java:2076)
at com.google.protobuf.AbstractParser.parsePartialFrom(AbstractParser.java:217)
at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:232)
at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:237)
at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:48)
at com.google.protobuf.GeneratedMessageV3.parseWithIOException(GeneratedMessageV3.java:347)
at com.android.aapt.Resources$XmlNode.parseFrom(Resources.java:44493)
at com.android.tools.build.bundletool.model.BundleModule$SpecialModuleEntry$1.addToModule(BundleModule.java:386)
at com.android.tools.build.bundletool.model.BundleModule$Builder.addEntry(BundleModule.java:355)
... 15 more
Seems like it's talking about the protobuf format (not sure if I'm right), but I do add "--proto-format" in my command.
Details of what I did:
compile the resources using aapt2:
"F:\tool\common\aapt2.exe" compile --dir "F:\_workspace\20210714\decompile\res" -v -o "F:\_workspace\20210714\decompile\compiled_resources.zip"
then link:
"F:\tool\common\aapt2.exe" link --proto-format "F:\_workspace\20210714\decompile\compiled_resources.zip" -v -o "F:\_workspace\20210714\decompile\base.apk" -I "F:\tool\common\android.jar" --manifest "F:\_workspace\20210714\decompile\AndroidManifest.xml"
unzip the base.apk, move other files into position (I did it according to bundletool's documentation), than zip again, name base.zip.
then do build-bundle, which has been mentioned in the beginning, and got that error:
"F:\tool\common\bundletool.jar" build-bundle --modules="F:\_workspace\20210714\decompile\base.zip" --output="F:\_workspace\20210714\decompile\base.aab"
The code and resources are decompiled from an apk which works well, dependencies should be good, and recompiling these into apk again can be done successfully. By the way, I use smali.jar to convert smali files into dex for bundletool.
The version of tools I am using:
aapt2.exe 7.0.0-beta05-7396180
bundletool.jar 1.7.0
apktool.jar 2.5.0
smali.jar 2.4.0
So the other day i fix this by myself. It is because i put the wrong manifeat file in place. The file in "base.zip/manifest/AndroidManifest.xml" should be proto-format, which is produce by aapt2 in link process, you can find it inside the apk generate by aapt2.
And yes, decompile an apk and use bundletool to turn it into an aab is possible.
My project is a simple game with native C++ code and Java, which uses cmake to compile C/C++ code. I'm using address sanitizer to check my the code. I follow the instruction here
My OS is windows 10 64bit.
However, when I press debug on Android Studio, I got the message as
2020-03-19 13:50:56.946 5152-5152/? E/logwrapper: executing /data/app/com.indie.haiphan.Breakout-ZFFz_f8ETleajrgP6rg9gw==/lib/arm64/wrap.sh failed: No such file or directory
2020-03-19 13:50:56.946 5151-5151/? I/wrap.sh: executing /data/app/com.indie.haiphan.Breakout-ZFFz_f8ETleajrgP6rg9gw==/lib/arm64/wrap.sh failed: No such file or directory
2020-03-19 13:50:56.956 5151-5151/? I/wrap.sh: wrap.sh terminated by exit(255)
2020-03-19 13:50:56.957 873-873/? W/Zygote: Error reading pid from wrapped process, child may have died
I checked on my APK (with Analyze APK of Android Studio) the wrap.sh exist.
So my question is I can't debug with wrap.sh inside the APK?
Thanks
You probably have BOM or an extra carriage return at the end of the first line of your wrap.sh. Which is possible in windows.
To fix it you can use dos2unix tool.
See this: https://unix.stackexchange.com/a/27067/197738
I have search stockoverflow and google with no luck. I recently migrated my app to androidx, after a lot of effort I was able to fix all the build fails. but now I am getting the following error when the app is installing on the emulator or the device. any help will be highly appreciated.
I have tried the following:
invalidate caches/restart
clean build and rebuild project
uninstalled app from the device
restarted my pc
Exception occurred while executing:
java.lang.IllegalArgumentException: Error: Failed to parse APK file: /data/local/tmp/...
at com.android.server.pm.PackageManagerShellCommand.setParamsSize(PackageManagerShellCommand.java:338)
at com.android.server.pm.PackageManagerShellCommand.runInstall(PackageManagerShellCommand.java:906)
at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:158)
at android.os.ShellCommand.exec(ShellCommand.java:103)
at com.android.server.pm.PackageManagerService.onShellCommand(PackageManagerService.java:21328)
at android.os.Binder.shellCommand(Binder.java:634)
at android.os.Binder.onTransact(Binder.java:532)
at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:2821)
at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:3856)
at android.os.Binder.execTransact(Binder.java:731)
Caused by: android.content.pm.PackageParser$PackageParserException: Failed to parse /data/local/tmp/...
at android.content.pm.PackageParser.parseApkLiteInner(PackageParser.java:1590)
at android.content.pm.PackageParser.parseApkLite(PackageParser.java:1575)
at com.android.server.pm.PackageManagerShellCommand.setParamsSize(PackageManagerShellCommand.java:331)
... 9 more
$ adb shell pm uninstall ...
Unknown failure (at android.os.Binder.execTransact(Binder.java:731))
Error while Installing APK
Delete the previous app-release.apk file from the android folder:
\app\build\outputs\apk\release
Then clear all data from the emulator. Finally, rebuild the application.
Clean -> Rebuild -> and try to check both v1 and v2 while generating apk file
You should drop the cache on your mobile.
for example:
1- open your windows terminal on your computer
2 - enter the command >adb shell
you should be insite on your mobile
3 - enter to the tmp/appium_cache/ folder with >cd data/local/tmp/appium_cache
4 - write the command >ls to see all the elements that there is insite of that folder
5 - drop all that elements with the command >rm filename
hope to help you
just delete build folder and run again
android/app/build
I'm quite new to Android native development and lately experimenting with building directly from CLI without Android Studio (really don't like the IDE and find Gradle overly complex, although I can't get my toolchain running yet...)
Using guidance from around the web, particularly this, I have a extremely basic app which successfully builds to a signed and aligned APK (as far as I can tell). I am building against platform 14 with Java 1.8 and I observed no changes when altering this configuration.
I've put the app source on GitHub for reference for this question. It's one activity with one layout.
When it comes to adb install (or manually install from the device), installation always fails with INSTALL_FAILED_INVALID_APK... Package /data/app/net.ilmiont.helloworld-...==/base.apk code is missing (... is some long ID by appearances).
Logcat
Running adb logcat during the installation attempt, I get this:
11-16 10:34:52.729 24742 7402 I Finsky : [9791] com.google.android.finsky.verifier.impl.ea.a(82): Skipping verification. Disabled by user setting
11-16 10:34:52.729 24742 7402 I Finsky : [9791] com.google.android.finsky.verifier.impl.ea.a(43): Skipping anti malware verification due to pre-check failure
11-16 10:34:52.730 24742 24742 I Finsky : [2] com.google.android.finsky.verifier.impl.fs.c(164): Verifying id=132, result=1
11-16 10:34:52.735 24742 24742 I Finsky : [2] com.google.android.finsky.verifier.impl.fs.c(177): Verification complete: id=132, package_name=net.ilmiont.helloworld
11-16 10:34:52.752 1856 27782 E : Couldn't opendir /data/data/net.ilmiont.helloworld: No such file or directory
11-16 10:34:52.753 1856 27782 E installd: Failed to delete /data/data/net.ilmiont.helloworld: No such file or directory
11-16 10:34:52.753 1856 27782 E : Couldn't opendir /data/user_de/0/net.ilmiont.helloworld: No such file or directory
11-16 10:34:52.753 1856 27782 E installd: Failed to delete /data/user_de/0/net.ilmiont.helloworld: No such file or directory
11-16 10:34:52.754 2198 2398 W PackageManager: com.android.server.pm.Installer$InstallerException: android.os.ServiceSpecificException: Failed to delete /data/user_de/0/net.ilmiont.helloworld (code 2)
11-16 10:34:52.756 2198 2398 W PackageManager: Package couldn't be installed in /data/app/net.ilmiont.helloworld-pbDVHiVe6mEghhiOqRUNjg==
11-16 10:34:52.756 2198 2398 W PackageManager: com.android.server.pm.PackageManagerException: Package /data/app/net.ilmiont.helloworld-pbDVHiVe6mEghhiOqRUNjg==/base.apk code is missing
I do not understand why it is trying to open/delete these directories when the app is just getting installed (and has not ever successfully installed) --- I don't know enough about Android internals, but from that trace it does look like the deletion is the problem.
I've looked over my source multiple times and just can't see what I'm missing. The manifest looks OK, the layout looks OK, the Java is all of two lines. So what am I missing? It must be something glaringly obvious.
The device
This may be relevant, so here are all the details.
Nokia 6 (original one) running unrooted Android 8.1.
I opened Android Studio, created the default boilerplate app and hit "Run", and it built and deployed successfully, so clearly there is something wrong with my app/build toolchain which is making this break, and I've out of ideas of where to look.
The build script (excerpts, it does build but will not deploy)
aapt package -v -f -m -J $PROJECT_SOURCE -M $ANDROID_MANIFEST -S $ANDROID_RESOURCES -I $ANDROID_SDK/platforms/android-$ANDROID_API/android.jar;
javac -d $JAVA_COMPILE_DESTINATION -source $JAVA_VERSION -target $JAVA_VERSION_TARGET -classpath "$PROJECT_SOURCE$JAVA_CLASSPATH_LIBS" -bootclasspath $ANDROID_SDK/platforms/android-$ANDROID_API/android.jar $PROJECT_SOURCE/$PROJECT_PACKAGE_SOURCE/*.java;
dx --dex --output=$DX_COMPILE_DESTINATION $JAVA_COMPILE_DESTINATION;
aapt package -f -m -F $APP_APK_UNALIGNED -M $ANDROID_MANIFEST -S $ANDROID_RESOURCES -I $ANDROID_SDK/platforms/android-$ANDROID_API/android.jar;
aapt add $APP_APK_UNALIGNED $DX_COMPILE_DESTINATION;
zipalign -f 4 $APP_APK_UNALIGNED $APP_APK;
apksigner sign --ks /home/jh_walker/.keystore $APP_APK;
Keystore
keytool -genkeypair -validity 365 -keystore $KEYSTORE -alias $KEYSTORE_ALIAS -sigalg SHA1withDSA -keyalg DSA -keysize 1024
What I've tried
Java 1.7/1.8
Compiling against different Android platforms (21/28)
Including additional assets (didn't have icons originally)
Setting use-sdk in the manifest (no impact)
What am I missing?
I got there.
aapt inspect app.apk
And immediately I noticed in the APK, was ./bin/classes.dex, and none of the other files had that ./ prefix.
Digging deeper, and I saw in my build script I was compiling DEX to ./bin/classes.dex, and then adding that path to my APK. But it appears something about that path wasn't liked by aapt (although it's entirely valid for where I was running it from), and it didn't properly add the file --- it seems just some empty ./bin/classes.dex it made up.
(Yes that's a kinda pathetic explanation, and I'll investigate properly later!)
Anyway, it seems you have to add from your current directory: classes.dex. Maybe this is obvious to someone more familiar with the tools.
Anyway,
cp ./bin/classes.dex . && aapt add app.apk.unaligned classes.dex works, but aapt add app.apk.unaligned ./bin/classes.dex does not .
If this somehow happens to you when you want to install a debug (gradle installDebug) version of your App in your device, check that versionCode and versionName are not changed from the last release published to the Play Store.
I was also getting the base.apk code is missing error message when attempting to install the apk on my device. In my case, I had recently upgraded Gradle and Android Gradle tools (naively because Studio recommended it).... So, downgrading to the previous gradle and tools version fixed it for me.
Downgrading can be done by editing the version numbers in 2 locations: android/build.gradle and gradle-wrapper.properties - and then doing a gradle sync in Android Studio.