termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.3k stars 3.06k forks source link

[Bug]: apktool build does not work #11521

Closed ravener closed 2 years ago

ravener commented 2 years ago

Problem description

~/love  apktool b -o game.apk test
32 bit support is deprecated. Apktool will not support 32bit on v3.0.0.
I: Using Apktool 2.6.1-dirty
I: Checking whether resources has changed...
I: Building resources...
W: First type is not attr!
brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 134): [/data/data/com.termux/files/usr/tmp/brut_util_Jar_180353324009176398335618267416584824288.tmp, p, --min-sdk-version, 16, --target-sdk-version, 31, --version-code, 30, --version-name, 11.4, --no-version-vectors, -F, /data/data/com.termux/files/usr/tmp/APKTOOL14738061755206897523.tmp, -0, resources.arsc, -0, png, -0, arsc, -I, /data/data/com.termux/files/home/.local/share/apktool/framework/1.apk, -S, /data/data/com.termux/files/home/love/test/res, -M, /data/data/com.termux/files/home/love/test/AndroidManifest.xml]

What steps will reproduce the bug?

apktool b -o game.apk somedirectory

What is the expected behavior?

Builds apk successfully

System information

termux-info:

Termux Variables:
TERMUX_API_VERSION=0.50.1
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=14456
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
Packages CPU architecture:
arm
Subscribed repositories:
# sources.list
deb https://grimler.se/termux-main stable main
# x11-repo (sources.list.d/x11.list)
deb https://grimler.se/termux/termux-x11 x11 main
Updatable packages:
0verkill/stable 0.16-git-3 arm [upgradable from: 0.16-git-1]
ant/stable,stable 1.10.12 all [upgradable from: 1.10.11-2]
apt/stable 2.5.1 arm [upgradable from: 2.2.0]
asciinema/stable,stable 2.2.0 all [upgradable from: 2.0.2-5]
autoconf/stable,stable 2.71-2 all [upgradable from: 2.69]
automake/stable,stable 1.16.5 all [upgradable from: 1.16.1]
bash/stable 5.1.16-1 arm [upgradable from: 5.0.7-1]
bastet/stable 0.43.2-8 arm [upgradable from: 0.43.2-6]
bat/stable 0.21.0 arm [upgradable from: 0.18.3-1]
bftpd/stable 6.1 arm [upgradable from: 5.7]
binutils/stable 2.38 arm [upgradable from: 2.37-5]
busybox/stable 1.35.0-2 arm [upgradable from: 1.35.0-1]
bzip2/stable 1.0.8-6 arm [upgradable from: 1.0.8-5]
ca-certificates/stable,stable 1:2022.07.19 all [upgradable from: 20211001]
clang/stable 14.0.6-1 arm [upgradable from: 14.0.4]
command-not-found/stable 2.0-1 arm [upgradable from: 1.67]
coreutils/stable 9.1 arm [upgradable from: 8.32-6]
cups/stable 2.3.3-9 arm [upgradable from: 2.3.3-7]
curl/stable 7.84.0 arm [upgradable from: 7.83.1]
curseofwar/stable 1.3.0-3 arm [upgradable from: 1.3.0-1]
dash/stable 0.5.11.5-1 arm [upgradable from: 0.5.10.2-1]
debianutils/stable 5.7 arm [upgradable from: 4.11.2]
dialog/stable 1.3-20220526-0 arm [upgradable from: 1.3-20210117-0]
diffutils/stable 3.8 arm [upgradable from: 3.7-2]
dns2tcp/stable 0.5.2-1 arm [upgradable from: 0.5.2]
dnsutils/stable 9.16.27 arm [upgradable from: 9.14.7]
dopewars/stable 1.6.1-4 arm [upgradable from: 1.6.1-2]
dos2unix/stable 7.4.3 arm [upgradable from: 7.4.0-1]
dpkg/stable 1.21.9 arm [upgradable from: 1.20.9-5]
elfutils/stable 0.187 arm [upgradable from: 0.186]
ffmpeg/stable 5.0.1-2 arm [upgradable from: 5.0.1-1]
file/stable 5.42 arm [upgradable from: 5.39-1]
findutils/stable 4.9.0-1 arm [upgradable from: 4.6.0-4]
fish/stable 3.5.1 arm [upgradable from: 3.1.2]
fontconfig-utils/stable 2.14.0 arm [upgradable from: 2.13.1-6]
fontconfig/stable 2.14.0 arm [upgradable from: 2.13.1-6]
freetype/stable 2.12.1 arm [upgradable from: 2.11.0]
fzf/stable 0.32.1 arm [upgradable from: 0.28.0]
gawk/stable 5.1.1-1 arm [upgradable from: 5.0.1-4]
gdb/stable 10.1-6 arm [upgradable from: 8.3-3]
gdbm/stable 1.23 arm [upgradable from: 1.18.1]
germanium/stable 1.2.3 arm [upgradable from: 1.2.2]
git/stable 2.37.1 arm [upgradable from: 2.36.1]
gnupg/stable 2.3.7 arm [upgradable from: 2.2.20-3]
gpgv/stable 2.3.7 arm [upgradable from: 2.2.15-1]
gradle/stable,stable 1:7.5 all [upgradable from: 1:7.3.1]
grep/stable 3.7-2 arm [upgradable from: 3.3-1]
gzip/stable 1.12 arm [upgradable from: 1.10-2]
harfbuzz-icu/stable 5.1.0 arm [upgradable from: 4.3.0]
harfbuzz/stable 5.1.0 arm [upgradable from: 4.3.0]
hexedit/stable 1.6 arm [upgradable from: 1.5]
hugo/stable 0.101.0 arm [upgradable from: 0.92.0]
inetutils/stable 2.3 arm [upgradable from: 1.9.4-12]
jo/stable 1.6 arm [upgradable from: 1.4-2]
kotlin/stable,stable 1.7.0 all [upgradable from: 1.5.30]
less/stable 590 arm [upgradable from: 563]
libandroid-spawn/stable 0.3 arm [upgradable from: 0.2-4]
libaom/stable 3.4.0 arm [upgradable from: 3.3.0]
libasm/stable 0.187 arm [upgradable from: 0.186]
libassuan/stable 2.5.5 arm [upgradable from: 2.5.3-1]
libbz2/stable 1.0.8-6 arm [upgradable from: 1.0.8-5]
libc++/stable 23c arm [upgradable from: 23b-3]
libcaca/stable 0.99.beta20 arm [upgradable from: 0.99.beta19-6]
libcanberra/x11 0.30-5 arm [upgradable from: 0.30-3]
libcompiler-rt/stable 14.0.6-1 arm [upgradable from: 14.0.4]
libcrypt/stable 0.2-5 arm [upgradable from: 0.2-2]
libcurl/stable 7.84.0 arm [upgradable from: 7.83.1]
libdb/stable 18.1.40-3 arm [upgradable from: 18.1.32-1]
libdebuginfod/stable 0.187 arm [upgradable from: 0.186]
libdw/stable 0.187 arm [upgradable from: 0.186]
libedit/stable 20210910-3.1-0 arm [upgradable from: 20190324-3.1-0]
libelf/stable 0.187 arm [upgradable from: 0.186]
libevent/stable 2.1.12-1 arm [upgradable from: 2.1.11-1]
libexpat/stable 2.4.8 arm [upgradable from: 2.2.6]
libffi/stable 3.4.2 arm [upgradable from: 3.2.1-4]
libgcrypt/stable 1.10.1 arm [upgradable from: 1.8.5-1]
libgit2/stable 1.5.0 arm [upgradable from: 1.4.3]
libgmp/stable 6.2.1-1 arm [upgradable from: 6.1.2-2]
libgnutls/stable 3.7.6 arm [upgradable from: 3.6.8-1]
libgpg-error/stable 1.45 arm [upgradable from: 1.36]
libidn2/stable 2.3.2 arm [upgradable from: 2.2.0]
libidn/stable 1.38 arm [upgradable from: 1.36-1]
libksba/stable 1.6.0 arm [upgradable from: 1.3.5-2]
libllvm/stable 14.0.6-1 arm [upgradable from: 14.0.4]
libltdl/stable 2.4.6-8 arm [upgradable from: 2.4.6-6]
liblua53/stable 5.3.5-10 arm [upgradable from: 5.3.5-9]
libluajit/stable 1:2.1.0-beta3-3 arm [upgradable from: 1:2.1.0-beta3-2]
liblz4/stable 1.9.3-1 arm [upgradable from: 1.9.3]
liblzma/stable 5.2.5-1 arm [upgradable from: 5.2.4-7]
libmpfr/stable 4.1.0-1 arm [upgradable from: 4.0.2-1]
libnettle/stable 3.7.3 arm [upgradable from: 3.5.1-1]
libnghttp2/stable 1.48.0 arm [upgradable from: 1.38.0]
libpaper/stable 1.2.2 arm [upgradable from: 1.2.0]
libpcap/stable 1.10.1-1 arm [upgradable from: 1.10.0]
libpng/stable 1.6.37-3 arm [upgradable from: 1.6.37-1]
libpopt/stable 1.18-1 arm [upgradable from: 1.16-2]
libsasl/stable 2.1.28 arm [upgradable from: 2.1.27-1]
libsodium/stable 1.0.18-3 arm [upgradable from: 1.0.18-2]
libtalloc/stable 2.3.3 arm [upgradable from: 2.1.14-1]
libtool/stable 2.4.6-8 arm [upgradable from: 2.4.6-6]
libunistring/stable 1.0 arm [upgradable from: 0.9.10-2]
libuuid/stable 1.0.3-5 arm [upgradable from: 1.0.3-4]
libvpx/stable 1:1.12.0 arm [upgradable from: 1.11.0]
libwebp/stable 1.2.4 arm [upgradable from: 1.2.2]
libx11/stable 1.7.2-1 arm [upgradable from: 1.7.2]
libxcb/stable 1.15 arm [upgradable from: 1.14-3]
libxml2/stable 2.9.14 arm [upgradable from: 2.9.12-1]
libxslt/stable 1.1.35 arm [upgradable from: 1.1.33-3]
libzip/stable 1.9.2 arm [upgradable from: 1.7.3-1]
lighttpd/stable 1.4.64-3 arm [upgradable from: 1.4.61-1]
lld/stable 14.0.6-1 arm [upgradable from: 14.0.4]
llvm/stable 14.0.6-1 arm [upgradable from: 14.0.4]
lua53/stable 5.3.5-10 arm [upgradable from: 5.3.5-9]
luajit/stable 1:2.1.0-beta3-3 arm [upgradable from: 1:2.1.0-beta3-2]
luarocks/stable,stable 3.8.0 all [upgradable from: 3.1.3-5]
luv/stable 1.44.2-0-0 arm [upgradable from: 1.43.0-0-0]
lz4/stable 1.9.3-1 arm [upgradable from: 1.9.3]
m4/stable 1.4.19-3 arm [upgradable from: 1.4.18-1]
make/stable 4.3-2 arm [upgradable from: 4.3-1]
man/stable 1.14.5-3 arm [upgradable from: 1.14.5-2]
manpages/stable,stable 5.13-1 all [upgradable from: 5.10]
mdbook/stable 0.4.21 arm [upgradable from: 0.4.18]
memcached/stable 1.6.12 arm [upgradable from: 1.6.9]
miniserve/stable 0.20.0 arm [upgradable from: 0.19.5]
moon-buggy/stable 1.0.51-5 arm [upgradable from: 1.0.51-4]
nano/stable 6.3 arm [upgradable from: 5.8]
navi/stable 2.20.1 arm [upgradable from: 2.18.0]
ncurses-ui-libs/stable 6.3-2 arm [upgradable from: 6.2.20200725-2]
ncurses-utils/stable 6.3-2 arm [upgradable from: 6.2.20200725-2]
ncurses/stable 6.3-2 arm [upgradable from: 6.2.20200725-2]
ndk-sysroot/stable 23c arm [upgradable from: 23b-7]
neovim/stable 0.7.2 arm [upgradable from: 0.7.0-1]
net-tools/stable 2.10.0 arm [upgradable from: 1.60.2017.02.21-2]
nethack/stable 3.6.6-6 arm [upgradable from: 3.6.6-3]
no-more-secrets/stable 1.0.1-1 arm [upgradable from: 1.0.1]
nodejs/stable 18.4.0 arm [upgradable from: 18.3.0-1]
nudoku/stable 2.1.0 arm [upgradable from: 2.0.0-1]
oniguruma/stable 6.9.8 arm [upgradable from: 6.9.7.1]
pcre2/stable 10.40 arm [upgradable from: 10.37]
pcre/stable 8.45-1 arm [upgradable from: 8.45]
perl/stable 5.36.0 arm [upgradable from: 5.30.0]
pinentry/stable 1.2.0 arm [upgradable from: 1.1.0-4]
pkg-config/stable 0.29.2-2 arm [upgradable from: 0.29.2]
procps/stable 3.3.17-2 arm [upgradable from: 3.3.16-2]
psmisc/stable 23.5 arm [upgradable from: 23.2-1]
pulseaudio/stable 16.1-1 arm [upgradable from: 14.2-10]
pv/stable 1.6.20 arm [upgradable from: 1.6.6]
python/stable 3.10.6 arm [upgradable from: 3.10.5]
qemu-user-x86-64/stable 1:7.0.0-3 arm [upgradable from: 1:7.0.0-1]
radare2/stable 5.7.6 arm [upgradable from: 5.7.0]
readline/stable 8.1.1 arm [upgradable from: 8.0]
resolv-conf/stable 1.3 arm [upgradable from: 1.2]
rsync/stable 3.2.4-1 arm [upgradable from: 3.1.3-5]
rust/stable 1.62.1 arm [upgradable from: 1.61.0]
screenfetch/stable,stable 3.9.1-1 all [upgradable from: 3.8.0]
sdl2-image/x11 2.6.1 arm [upgradable from: 2.6.0]
sdl2/x11 2.0.22-2 arm [upgradable from: 2.0.22]
sed/stable 4.8-2 arm [upgradable from: 4.7]
strace/stable 5.18 arm [upgradable from: 5.4]
swig/stable 4.0.2-1 arm [upgradable from: 4.0.0-1]
termux-am-socket/stable 1.5.0 arm [upgradable from: 1.4.0]
termux-create-package/stable,stable 0.12.0 all [upgradable from: 0.10]
termux-elf-cleaner/stable 2.1.1 arm [upgradable from: 1.10]
termux-keyring/stable,stable 3.8-1 all [upgradable from: 2.3]
termux-licenses/stable,stable 2.0-3 all [upgradable from: 2.0-1]
termux-tools/stable,stable 1.26.0 all [upgradable from: 1.0-1]
texinfo/stable 6.8-1 arm [upgradable from: 6.7]
tidy/stable 5.8.0-1 arm [upgradable from: 5.7.28-1]
tig/stable 2.5.6 arm [upgradable from: 2.5.1]
tmux/stable 3.3-1 arm [upgradable from: 3.1c]
tracepath/stable 20211215 arm [upgradable from: 20190709]
ttf-dejavu/stable,stable 2.37-8 all [upgradable from: 2.37-7]
tty-solitaire/stable 1.3.1 arm [upgradable from: 1.3.0-4]
unzip/stable 6.0-8 arm [upgradable from: 6.0-5]
util-linux/stable 2.38 arm [upgradable from: 2.33.1-3]
valgrind/stable 3.19.0-2 arm [upgradable from: 3.19.0-1]
weechat/stable 3.6 arm [upgradable from: 3.0.1-5]
xxhash/stable 0.8.1 arm [upgradable from: 0.8.0-1]
xz-utils/stable 5.2.5-1 arm [upgradable from: 5.2.4-7]
yarn/stable,stable 1.22.19 all [upgradable from: 1.22.10]
termux-tools version:
1.0
Android version:
9
Kernel build information:
Linux localhost 4.9.117+ #1 SMP PREEMPT Fri Apr 19 13:20:06 CST 2019 armv8l Android
Device manufacturer:
HUAWEI
Device model:
AMN-LX9
2096779623 commented 2 years ago

Why don't you pkg upgr ?😊

ravener commented 2 years ago

On a second thought this might be a bug in apktool itself, i'll do some more research and try opening an issue in their repo instead maybe.

switchroute commented 2 years ago

Try this Apktool work without any error.

ravener commented 2 years ago

@switchroute I just gave it a try, it actually worked, thanks!

That seems to use a newer version 2.6.2-SNAPSHOT so I guess the bug might've been fixed upstream already? Or did he apply any patches?

switchroute commented 2 years ago

I tried build apktool from source but it didn't work. I guess there is a certain patch.

Anonymous2716 commented 2 years ago

This is aapt issue. Apktool from termuxs repos can't build for some reason. But the actual x86 or x64 binaries in the apktools jar file works great. You have to run it through qemu . its statically linked binary . I use it that way. https://github.com/iBotPeaches/Apktool/issues/2772

Anonymous2716 commented 2 years ago

@switchroute check in termux packages . you just have to run ./gradlew build -X test I guess. And this issue is related to the aapt.

ravener commented 2 years ago

Can't we alternatively patch the jar file's aapt binaries to include a working one from termux? @xtkoba

Might get a lil messy though.

TGSMLM commented 2 years ago

这是来自QQ邮箱的假期自动回复邮件。你好,我最近正在休假中,无法亲自回复你的邮件。我将在假期结束后,尽快给你回复。

Anonymous2716 commented 1 year ago

@ravener that's how it was managed but but wasn't working well with the termux provided aapt. it had to use the aapt binary it came with. I made a little workaround tho.

xtkoba commented 1 year ago

Yes, that is the point.

Anonymous2716 commented 1 year ago

@xtkoba well hope they add the arm/arm64 binary with the package in the future. And are the patches the aapt workaround this repo had got completely removed? Or still I can find somewhere?

xtkoba commented 1 year ago

@Anonymous2716 IIRC aapt binaries included in the upstream JAR is for GNU/Linux which do not execute on Termux regardless of architectures. Hence the QEMU workaround. You can find our build recipe preserved under /disabled-packages/.

[EDIT] Ah, statically linked, including libc?

xtkoba commented 1 year ago

IIRC upstream does not provide the source files for aapt binary bundled in the JAR file. aapt binary from our aapt package does not work with apktool. Thus wontfix.

Anonymous2716 commented 1 year ago

@xtkoba thanks for the info.

ravener commented 1 year ago

I've been using https://github.com/rendiix/termux-apktool and it works fine, maybe worth inspecting the aapt in there and what they did?

Anonymous2716 commented 1 year ago

@ravener arm eabi5 / arm64 binary (dynamically linked) provided.

ravener commented 1 year ago

@ravener arm eabi5 / arm64 binary (dynamically linked) provided.

Yeah so what's stopping us to have an apk tool package like them?

Grimler91 commented 1 year ago

Yeah so what's stopping us to have an apk tool package like them?

We build packages from source, we do not re-package binaries from elsewhere

Anonymous2716 commented 1 year ago

I asked the author of that project and he says he also packages aapt from source with cmake. And I have just a guess not sure that the problem is in the aapts jar file. Tests will be needed to confirm.

ravener commented 1 year ago

Yeah so what's stopping us to have an apk tool package like them?

We build packages from source, we do not re-package binaries from elsewhere

I think you misunderstood me, I didn't mean to package their debs here, but to find out what they are doing and replicating it in our build.

JeffreyO commented 1 year ago

IBotPeaches' aapt tool is modified and looks like it's based on Cyanogenmod's aapt. It had stuff like the --forced-package-id option and MIUI support added by M1cha. https://github.com/iBotPeaches/android_frameworks_base/commit/76fb330762c3d204f9ae45e444e18a2f82535bc0 https://github.com/iBotPeaches/android_frameworks_base/commit/ef6019690754fd0aea3aa080d1b2776a8cad72cf

It also looks like, by proxy they're using a lot of stuff from the TMobile themes platform framework: https://github.com/tmobile/themes-platform-frameworks-base/tree/44ffc93b4d3ab81bf4df569839e409bae0c8695a/tools/aapt

With APKtool, I also find that using 'sh -x $PREFIX/bin/[Command to run]' is very helpful for tracking down errors. IIRC, it also doesn't do well with spaces in paths either even normally running on a computer.

There also seems to be an issue with the '-e' option, even though it's mentioned in current APKtool sources. EDIT for additional information: This flag is a custom one meant to extend the command line length. According to https://github.com/iBotPeaches/Apktool/blob/50226e50c1a4e2c60a0547427bd9e637c2f35ef9/brut.apktool/apktool-lib/src/main/java/brut/androlib/AaptInvoker.java#L189 and https://github.com/iBotPeaches/Apktool/blob/50226e50c1a4e2c60a0547427bd9e637c2f35ef9/brut.apktool/apktool-lib/src/main/java/brut/androlib/AaptInvoker.java#L311

Also, if it isn't possible to get everything working as the tool expects by bundling APKtool inside of it, there is a workaround. APKtool has the ability to run AAPT from outside the binary with the '--aapt' flag pointing to it. So, we can modify the initial script to incorporate this by default. We'll need the libraries anyways, requiring installation of AAPT and AAPT2, unless static linking is allowed for the bins in the APKtool jar. As a side effect, this will also disable the '--forced-package-id' (and -e) option, which isn't needed unless you're building system and framework apps.

You will also need to use the flag '--use-aapt2' if you get the error 'First type is not attr! Aborted' since there is a possibility the app was originally built with AAPT2 and it contains invalid resource directory names for AAPT. This will use the internal AAPT2 binary within APKtool.

GoLuBnAtAsHa commented 3 months ago

I've been using https://github.com/rendiix/termux-apktool and it works fine, maybe worth inspecting the aapt in there and what they did?

Is there a apktool version 2.9.3?