PHP Auto-signature with exec function for apk

Source: Internet
Author: User
Tags fpm

developed by the company Android application, because the signature files in different platforms, need to be signed separately, this is very troublesome, so require in the company's back-office management system to upload the APK file, automatically use different platform signature file to complete the signature, This will only need to upload a file to get all the platform signed APK , distribution is much more convenient.


specifically how to APK file to sign, there are many articles on the Internet, please search by yourself. Given the number of commands used throughout the signature process, a script was written to complete the signature so that only the exec () function would be required to execute the script in PHP.


The idea is correct, but after writing the script, PHP Executes the script when there is a problem, the script underWindows is not a problem, theLinux script does not, theexec () output parameter returned to {}, viewing background file discovery also did not generate a signature file.


jar , jarsigner command failed, these commands were not executed at all, searched the internet for half a day , the findings are mostly as follows:

1. permissions are not enough, to improve the permissions of PHP exec () to sudo, and to avoid password;

2. PHP exec () can only perform system-native commands and cannot perform commands for third-party applications installed later;

for Argument 1 , try the following:

      1, set php-fpm.conf user parameter is Span lang= "en-us" xml:lang= "en-US" >root , starting lang= with php-fpm–r "en-US" command Lang= "en-us" xml:lang= "en-US" >php , at this time php-fpm process user is root

2. PHP-FPM The default user is Nginx, adding the user to the sudoers , and is set to password-free;

all of the above methods fail validation.

finally Accidental discovery, originally not a permissions issue, nor exec () Only native commands can be executed, originally path problem , which would have jar , jarsigner command added to System Span lang= "en-us" xml:lang= "en" >path parameter, but do not know why, in exec () The function does not seem to recognize the path parameter, also did not find jar , jarsigner command, which causes the signature to fail , the final script is as follows (the red part of the code is intentionally adding a path to a third-party command):

#SOR_NAME =flyingstone-v2.0.4

#SOR_FILE = $SOR _name.apk

#PASS =by51096188

#KEY_STORE =beyondscreen.keystore

#PLAT_FORM =samsung

#KEY_STORE_ALIAS =bygame

Dir= "$"

Sor_name= "$"

Pass= "$"

Key_store= "$4"

Plat_form= "$"

Key_store_alias= "$6"

sor_file= $SOR _name.apk

Java_bin=/usr/local/java/jdk1.8.0_144/bin

# go to the working directory, to be signed APK in this directory

CD $DIR

# Create a temp subdirectory and copy the APK you want to sign to temp Sub-directories

If [-D temp]; Then

RM-RF temp

Fi

mkdir Temp

CP $SOR _file temp/$SOR _file

# go to temp subdirectory, unzip the APK to be signed, and delete the meta-inf the original signature file in the sub-directory

# because a signature file will cause the signature to fail

CD Temp

"$JAVA _bin"/jar -xf $SOR _file

RM $SOR _file

CD Meta-inf

Rm-f *. Rsa

Rm-f *. SF

Cd..

# Repackage files in the temp directory as new APK file, used for signing

"$JAVA _bin"/jar -cvf0. /"$SOR _name" _new.apk.

Cd..

# for the new APK file to sign

"$JAVA _bin"/jarsigner -verbose-storepass $PASS-keystore $KEY _store-signedjar "$SOR _name"-signed-"$PLAT _form". apk "$SOR _name" _ new.apk $KEY _store_alias

RM "$SOR _name" _new.apk

Rm-f-R Temp

This article is from the "Rainman" blog, make sure to keep this source http://lancelot.blog.51cto.com/393579/1969087

PHP Auto-signature with exec function for apk

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.