Android native C Development 5: zlib porting notes

Source: Internet
Author: User
Tags gz file

Original article: http://blog.sina.com.cn/s/blog_4a0a39c30100b4ao.html

 

 

Zlib (http://www.zlib.net/) is a very popular and open-source compression, decompression library, by Jean-Loup
Gailly and Mark
Developed by Adler, the first version of 0.9 was published in May 1, 1995. Zlib uses the deflate algorithm, which was originally written for the libpng function library. Later, zlib was widely used by many software.

The current zlib version is
1.2.3. It has excellent portability. I have successfully transplanted zlib to Windows, Linux, WinCE, Symbian, and other platforms. Of course, it also includes the platform to be transplanted today: Android.

First, download the source code of zlib from the official website of zlib: zlib123.zip, decompress it to get a directory zlib-1.2.3, Zib has provided a makefile, you can modify several lines (19, 20, 27, 36, and 37) to compile them. The changes are as follows:

......
Cc = arm-None-Linux-gnueabi-gcc

Cflags =
-O2
......
Ldflags = libz. A-s-static
......
AR =
Arm-None-Linux-gnueabi-ar RC
Ranlib = arm-None-Linux-gnueabi-ranlib
......

Go to the zlib-1.2.3 directory and enter: make on the command line.

Finally, two executable Android files are generated: Example and minigzip.

Run the android simulator, enter the command line, push two executable files to the android simulator, and then execute the command as follows:

 

$ ADB push example
/Dev/sample/Example
$ ADB
Push minigzip/dev/sample/minigzip
$ ADB shell chmod 777/dev/sample /*
$ ADB Shell
# Cd/dev/sample
#./Example


Zlib version 1.2.3 = 0x1230, compile flags = 0x55

Uncompress (): Hello, hello!

Gzread (): Hello, hello!

Gzgets () after gzseek: Hello!

Inflate (): Hello, hello!

Large_inflate (): OK

After inflatesync (): Hello, hello!

Inflate with dictionary: Hello, hello!

# Ls-l

Ls-l
-Rwxrwxrwx
Root
Root
513228 minigzip
-Rwxrwxrwx
Root
Root
517640 example
-Rwxrwxrwx
Root
Root
31 foo.gz

# Exit

$ ADB pull/dev/sample/foo.gz D:/foo.gz

"$" Indicates the Linux or cygwin command line prompt, and # indicates the android command line prompt.

Finally, run the LS-l command to view the current directory. A foo.gz file is generated by example and stops ADB.
Shell. Run the command ADB pull/dev/sample/foo.gz D:/foo.gz to run the file foo.gz generated on the simulator.
Pull to the root directory of drive D. You can use WinRAR or 7zip to view the content of this file, which is exactly the "Hello, hello!" file written in the code! "!

 

So far, zlib has been successfully transplanted to the Android platform!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.