[UTILITY][ANDROID] XZ Utils port to Android - managing .xz archives now possible!

Search This thread

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
16,773
40,451
Halifax
GT-i9250
Google Nexus 4
If you wish to compile xz statically then the following example will do the trick. It's so SIMPLE I about fell out of my seat. Pay attention to what I have in bold:

./configure --build=arm --host=arm-linux-androideabi LDFLAGS="-static"

Then, when you go to run, make, just do the following:

make LDFLAGS=-all-static


Update:

After some tests with @osm0sis we learned that using configure will ultimately overwrite the original flags ordained by the source. Running the configure normally then applying your flags using "+=" will insure the ordained flags do not get overwritten as well as including your own additional flags. This will ultimately be up to the user what they want to do and their ultimate goal at the end of the day.

--- Happy Hunting!!

Can't wait to try that out in the morning. You've just fixed static NDK compiling on anything using Autotools, bro! :D

Let me know how it works out for you. I tried this method on my phone too and it worked like a champ :D

Yup works great! The key is this: You can't add -all-static via ./configure since it'll fail the working compiler test for some reason, but overriding the LDFLAGS on the make command-line works perfectly where even an exported environment variable doesn't. Stroke of genius to force a true static compile by @Modding.MyMind! :D

There's nothing important by default in the LDFLAGS so really all you need to worry about is overriding your own LDFLAGS you may have added with ./configure, and that can be resolved most definitely by adding them in on the make command-line as well (since my tests with += on Cygwin weren't successful). :good:

So to summarize, all you really need to do is:

Code:
./configure --host=<toolchain> --enable-static --disable-shared LDFLAGS=-static
cd src
make LDFLAGS=-all-static

:cool:

(I've also got some workarounds in place to make it all work nicely on Cygwin, which can be found in my build script post.)
 
Last edited:
M

Modding.MyMind

Guest
Here is a true static compiled xz binary for arm. No dynamic links whatsoever and no tampering with the source let alone the toolchain. It's as legit as it can get. Figured I would share for any of those who need it. Based on version 5.0.5.
 

Attachments

  • xz.zip
    143.2 KB · Views: 278
Last edited:
S

SHM

Guest
Yup works great! The key is this: You can't add -all-static via ./configure since it'll fail the working compiler test for some reason, but overriding the LDFLAGS on the make command-line works perfectly where even an exported environment variable doesn't. Stroke of genius to force a true static compile by @Modding.MyMind! :D

There's nothing important by default in the LDFLAGS so really all you need to worry about is overriding your own LDFLAGS you may have added with ./configure, and that can be resolved most definitely by adding them in on the make command-line as well (since my tests with += on Cygwin weren't successful). :good:

So to summarize, all you really need to do is:

./configure --host=<toolchain> --enable-static --disable-shared LDFLAGS=-static
cd src
make LDFLAGS=-all-static

:cool:

(I've also got some workarounds in place to make it all work nicely on Cygwin, which can be found in my build script post.)

Been playing around with toolchains over the months and have learned a hard lesson lol. When compiling as static the target (compiler) will typically aim for the shared object first. Using "-static" forces the compiler to ignore any shared objects and go for static libs instead. However, if other resources being compiled within a some what complex program which causes confliction towards a static lib then it will ignore "-static" for that particular case and link to the shared object instead.

A little trick I starting using since I have no need for shared objects is adding an extended extension name to all the .so libs with ".keep" so while compiling statically I can hope to insure that all static libs are targeted.
 

kdar1987

Member
Jul 16, 2010
40
0
After I made it executable:
Code:
chmod 777 pbzip2

I tried several commands:
Code:
./pbzip2 input/stackoverflow.com.tar
./pbzip2 -fc input/stackoverflow.com.tar > /dev/null
./pbzip2 -dc bzip2.cfd/inputCRlow.9.tar.bz2 > /dev/null

I tried to run it on Cyanogenmod 12.1 on OnePlus One
 
S

SHM

Guest
After I made it executable:
Code:
chmod 777 pbzip2

I tried several commands:
Code:
./pbzip2 input/stackoverflow.com.tar
./pbzip2 -fc input/stackoverflow.com.tar > /dev/null
./pbzip2 -dc bzip2.cfd/inputCRlow.9.tar.bz2 > /dev/null

I tried to run it on Cyanogenmod 12.1 on OnePlus One

Ok, I see it on my end as well. Didn't test it prior to sharing. Since it's compiled for arm and Android isn't necessarily linux 100% I will have to make some modifications to the source and recompile. Looking into it now to see if this can be done successfully.
 
S

SHM

Guest
@kdar1987, Almost got it working. Still need to make some more modifications to the source. Will keep you posted and hopefully I can provide you with this tool.
 

Attachments

  • 1433633486754.jpg
    1433633486754.jpg
    95.8 KB · Views: 218
S

SHM

Guest

It is working. However, due to it's coding it unfortunately requires root to work. So when you open up your terminal emulator make sure you type and enter, su, before calling on pbzip2, or else it will fail with three errors (though I could probably fix this lol).

Also, pbzip2 isn't actually bzip2. It just parallelizes bzip2. So, bzip2 must be installed on your device. I tested it with busybox bzip2 being installed and it worked great. Speed differences was amazing. However, busybox bzip2 sucks at compressing stuff. Even if the compression level is set to 9. Could be a bug though with busybox bzip2.

Oh, and one more thing, due to the toolchain I used, the "off_t variable" is only 32 bits in size so this means you can only compress stuff up to 2gb using pbzip2. Anything larger than 2 gigs will be a problem.
 

Attachments

  • pbzip2-static.zip
    465 KB · Views: 72
Last edited:
S

SHM

Guest
I have uploaded the original pbzip2 source as an attachment. The attachment also includes the prebuilt static arm binary.
 

Attachments

  • pbzip2-arm-static-SOURCE.zip
    2.9 MB · Views: 45
Last edited:

kdar1987

Member
Jul 16, 2010
40
0
Thank you a lot! It worked great. I will be using pbzip2 only from rooted adb, so its perfect.
I will check out git.
 
S

SHM

Guest
Thank you a lot! It worked great. I will be using pbzip2 only from rooted adb, so its perfect.
I will check out git.

Glad to here it. One thing I did but didn't notice anything unusual was me commenting out -lpthread since I do not have the static pthread library for my toolchain. However, the makefile still calls for -pthread for support. I'm working on cross compiling the pthread lib right now and then will rebuild pbzip2 to see if there is any differences but the pthread source is all jacked up. Not sure what these maintainers were thinking.

Also, I did notice that if you run pbzip2 without su that it will still work even though the three errors are displayed. I ran a check on the bz2 header of the compressed archive and the check returned ok. Must be a bug in the pbzip2 source. Anyways, enough jibberjabbing on my part lol. Glad it works for you.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 15
    what is XZ Utils

    XZ Utils is free general-purpose data compression software with high compression ratio. XZ Utils were written for POSIX-like systems, but also work on some not-so-POSIX systems. XZ Utils are the successor to LZMA Utils.

    The core of the XZ Utils compression code is based on LZMA SDK, but it has been modified quite a lot to be suitable for XZ Utils. The primary compression algorithm is currently LZMA2, which is used inside the .xz container format. With typical files, XZ Utils create 30 % smaller output than gzip and 15 % smaller output than bzip2.

    Android port

    XZ Utils makes managing .xz and .lzma (LZMA2) archives possible in Android APPs or tools .XZ Utils is easy to use and powerful . you may use it in your app or use it with terminal emulator ( push binary to /system/bin and set permissions to 755 )

    This binaries support ALL Android based devices with Bionic C Library .

    Download

    You may download lastest binaries for Android-ARM here :

    XZ Utils 5.0.5 – ARM – Android

    Development

    Main development of XZ Utils is running by Tukaani .

    And git repo :

    git clone http://git.tukaani.org/xz.git

    Licence

    The most interesting parts of XZ Utils (e.g. liblzma) are in the public domain. You can do whatever you want with the public domain parts.

    Some parts of XZ Utils (e.g. build system and some utilities) are under different free software licenses such as GNU LGPLv2.1, GNU GPLv2, or GNU GPLv3.

    Official XZ Utils and more information HERE
    1
    @alireza7991 Thanks for the work porting/compiling this for Android - exactly what I was looking for since (for some reason..) Busybox only supports xz/lzma decompression. :good:

    The download link is dead now unfortunately - would you please rehost it somewhere?

    Thank you in advance! :)
    Sorry for download link,I'm gonna fix it ASAP.

    UPDATE: fixed (link is available in OP)

    UPDATE2: oh, It seems there 's a problem with new executable, I have to fix it. I just need some time.sorry.
    1
    Try with LDFLAGS
    1
    I had problems with xz and sorry I forgot how I solved them, probably (I think) I have linked with static libc! Or probably (maybe) some of the depended libs was not static which caused me failed xz static compilation so maybe I have compiled staticaly other dependencies and linked with xz! Bionic is realy an sh*t :( Hope this help.
    1
    Tried adding --with-sysroot= to the ./configure command-line and -lc -ldl to the CFLAGS (and LDFLAGS) to try and get it to find/link them all but still no luck. :(

    @munjeni If you ever do remember/recreate what you did to get xz to compile statically, please share it here/somewhere on xda and mention me. It's actually applicable to all autotools (./configure) built sources, so would definitely help a lot of people with a lot projects. Especially with Android L coming along, requiring everything to be static or PIE (with static preferred for backwards-compatibility). :) :good:

    Put your libc.a and libdl.a to the new place. for example put them to new folder caled /tmp/compilationfolder, than try flags:

    LDFLAGS="-L/tmp/compilationfolder" LIBS="-lc -ldl"

    to make sure it get linked with static libs! If compilation fail to find other libs than locate missing libs and move them to these folder and try again until...

    EDIT:
    If I remember corectly I think now I have removed shared libs in sysfolder of the toolchain just for compiling xz!