Android涓瑼PK绛惧悕宸ュ叿涔媕arsigner鍜宎pksigner璇﹁В
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android涓瑼PK绛惧悕宸ュ叿涔媕arsigner鍜宎pksigner璇﹁В相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/with' title='with'>with
澶辨晥 art lis 鍏煎 浣嶇疆 tps 甯哥敤 enable涓€.宸ュ叿浠嬬粛
jarsigner鏄疛DK鎻愪緵鐨勯拡瀵筳ar鍖呯鍚嶇殑閫氱敤宸ュ叿,
浣嶄簬JDK/bin/jarsigner.exe
apksigner鏄疓oogle瀹樻柟鎻愪緵鐨勯拡瀵笰ndroid apk绛惧悕鍙婇獙璇佺殑涓撶敤宸ュ叿,
浣嶄簬android SDK/build-tools/SDK鐗堟湰/apksigner.bat
涓嶇鏄痑pk鍖?杩樻槸jar鍖?鏈川閮芥槸zip鏍煎紡鐨勫帇缂╁寘,鎵€浠ュ畠浠殑绛惧悕杩囩▼閮藉樊涓嶅(浠呴檺V1绛惧悕),
浠ヤ笂涓や釜宸ュ叿閮藉彲浠ュAndroid apk鍖呰繘琛岀鍚?
1.V1鍜孷2绛惧悕鐨勫尯鍒?/strong>
鍦ˋndroid Studio涓偣鍑昏彍鍗?Build->Generate signed apk... 鎵撳寘绛惧悕杩囩▼涓?
鍙互鐪嬪埌涓ょ绛惧悕閫夐」 V1(Jar Signature) V2(Full APK Signature),
鍒氬紑濮嬪崌绾S鐪嬪埌杩欎釜鎳典簡,鏃㈢劧鏄疉PK Signature,灏辨斁蹇冨伔鎳掗€変簡V2,缁撴灉瀹夎澶辫触锛燂紵锛熸棤濂?鍙兘鏌ヨ祫鏂?..
浠嶢ndroid 7.0寮€濮? 璋锋瓕澧炲姞鏂扮鍚嶆柟妗?V2 Scheme (APK Signature);
浣咥ndroid 7.0浠ヤ笅鐗堟湰, 鍙兘鐢ㄦ棫绛惧悕鏂规 V1 scheme (JAR signing)
V1绛惧悕:
- 鏉ヨ嚜JDK(jarsigner), 瀵箊ip鍘嬬缉鍖呯殑姣忎釜鏂囦欢杩涜楠岃瘉, 绛惧悕鍚庤繕鑳藉鍘嬬缉鍖呬慨鏀?绉诲姩/閲嶆柊鍘嬬缉鏂囦欢)
- 瀵筕1绛惧悕鐨刟pk/jar瑙e帇,鍦∕ETA-INF瀛樻斁绛惧悕鏂囦欢(MANIFEST.MF, CERT.SF, CERT.RSA),
- 鍏朵腑MANIFEST.MF鏂囦欢淇濆瓨鎵€鏈夋枃浠剁殑SHA1鎸囩汗(闄や簡META-INF鏂囦欢), 鐢辨鍙煡: V1绛惧悕鏄鍘嬬缉鍖呬腑鍗曚釜鏂囦欢绛惧悕楠岃瘉
V2绛惧悕:
- 鏉ヨ嚜Google(apksigner), 瀵箊ip鍘嬬缉鍖呯殑鏁翠釜鏂囦欢楠岃瘉, 绛惧悕鍚庝笉鑳戒慨鏀瑰帇缂╁寘(鍖呮嫭zipalign),
- 瀵筕2绛惧悕鐨刟pk瑙e帇,娌℃湁鍙戠幇绛惧悕鏂囦欢,閲嶆柊鍘嬬缉鍚嶸2绛惧悕灏卞け鏁? 鐢辨鍙煡: V2绛惧悕鏄鏁翠釜APK绛惧悕楠岃瘉
V2绛惧悕浼樼偣寰堟槑鏄?
- 绛惧悕鏇村畨鍏?涓嶈兘淇敼鍘嬬缉鍖?
- 绛惧悕楠岃瘉鏃堕棿鏇寸煭(涓嶉渶瑕佽В鍘嬮獙璇?,鍥犺€屽畨瑁呴€熷害鍔犲揩
娉ㄦ剰: apksigner宸ュ叿榛樿鍚屾椂浣跨敤V1鍜孷2绛惧悕,浠ュ吋瀹笰ndroid 7.0浠ヤ笅鐗堟湰
2.zipalign鍜孷2绛惧悕
浣嶄簬Android SDK/build-tools/SDK鐗堟湰/zipalign.exe
zipalign 鏄zip鍖呭榻愮殑宸ュ叿,浣緼PK鍖呭唴鏈帇缂╃殑鏁版嵁鏈夊簭鎺掑垪瀵归綈,浠庤€屽噺灏慉PP杩愯鏃跺唴瀛樻秷鑰?/p>
1
2
|
zipalign -v 4 in.apk out.apk //4瀛楄妭瀵归綈浼樺寲 zipalign -c -v 4 in.apk //妫€鏌PK鏄惁瀵归綈 |
zipalign鍙互鍦╒1绛惧悕鍚庢墽琛?/p>
浣唞ipalign涓嶈兘鍦╒2绛惧悕鍚庢墽琛?鍙兘鍦╒2绛惧悕涔嬪墠鎵ц锛侊紒锛?/p>
浜?绛惧悕姝ラ
1.鐢熸垚瀵嗛挜瀵?宸叉湁瀵嗛挜搴?鍙拷鐣?
Eclipse鎴朅ndroid Studio鍦―ebug鏃?瀵笰pp绛惧悕閮戒細浣跨敤涓€涓粯璁ょ殑瀵嗛挜搴?
- 榛樿鍦–:Users鐢ㄦ埛鍚峔.androiddebug.keystore
- 瀵嗛挜搴撳悕: debug.keystore
- 瀵嗛挜鍒悕: androiddebugkey
- 瀵嗛挜搴撳瘑鐮? android
1.鐢熸垚瀵嗛挜瀵?/strong>
杩涘叆JDK/bin, 杈撳叆鍛戒护
keytool -genkeypair -keystore 瀵嗛挜搴撳悕 -alias 瀵嗛挜鍒悕 -validity 澶╂暟 -keyalg RSA
鍙傛暟:
-genkeypair 鐢熸垚涓€鏉″瘑閽ュ(鐢辩閽ュ拰鍏挜缁勬垚)
-keystore 瀵嗛挜搴撳悕瀛椾互鍙婂瓨鍌ㄤ綅缃?榛樿褰撳墠鐩綍)
-alias 瀵嗛挜瀵圭殑鍒悕(瀵嗛挜搴撳彲浠ュ瓨鍦ㄥ涓瘑閽ュ,鐢ㄤ簬鍖哄垎涓嶅悓瀵嗛挜瀵?
-validity 瀵嗛挜瀵圭殑鏈夋晥鏈?鍗曚綅: 澶?
-keyalg 鐢熸垚瀵嗛挜瀵圭殑绠楁硶(甯哥敤RSA/DSA,DSA鍙敤浜庣鍚?榛樿閲囩敤DSA)
-delete 鍒犻櫎涓€鏉″瘑閽?/p>
鎻愮ず: 鍙噸澶嶄娇鐢ㄦ鏉″懡浠?鍦ㄥ悓涓€瀵嗛挜搴撲腑鍒涘缓澶氭潯瀵嗛挜瀵?/p>
渚嬪:
鍦╠ebug.keystore涓柊澧炰竴瀵瑰瘑閽?鍒悕鏄痳elease
1
|
keytool -genkeypair -keystore debug.keystore -alias release -validity 30000 |
2.鏌ョ湅瀵嗛挜搴?/strong>
杩涘叆JDK/bin, 杈撳叆鍛戒护
keytool -list -v -keystore 瀵嗛挜搴撳悕
鍙傛暟:
-list 鏌ョ湅瀵嗛挜鍒楄〃
-v 鏌ョ湅瀵嗛挜璇︽儏
渚嬪:
1
|
keytool -list -v -keystore debug.keystore |
鐜板湪debug.keystore瀵嗛挜搴撲腑鏈変袱瀵瑰瘑閽? 鍒悕鍒嗗埆鏄痑ndroiddebugkey release
2.绛惧悕
1.鏂规硶涓€(jarsigner,鍙敮鎸乂1绛惧悕)
杩涘叆JDK/bin, 杈撳叆鍛戒护
jarsigner -keystore 瀵嗛挜搴撳悕 xxx.apk 瀵嗛挜鍒悕
浠嶫DK7寮€濮? jarsigner榛樿绠楁硶鏄疭HA256, 浣咥ndroid 4.2浠ヤ笅涓嶆敮鎸佽绠楁硶,
鎵€浠ラ渶瑕佷慨鏀圭畻娉? 娣诲姞鍙傛暟 -digestalg SHA1 -sigalg SHA1withRSA
jarsigner -keystore 瀵嗛挜搴撳悕 -digestalg SHA1 -sigalg SHA1withRSA xxx.apk 瀵嗛挜鍒悕
鍙傛暟:
-digestalg 鎽樿绠楁硶
-sigalg 绛惧悕绠楁硶
渚嬪:
鐢↗DK7鍙婁互涓妀arsigner绛惧悕,涓嶆敮鎸丄ndroid 4.2 浠ヤ笅
1
|
jarsigner -keystore debug.keystore MyApp.apk androiddebugkey |
鐢↗DK7鍙婁互涓妀arsigner绛惧悕,鍏煎Android 4.2 浠ヤ笅
1
|
jarsigner -keystore debug.keystore -digestalg SHA1 -sigalg SHA1withRSA MyApp.apk androiddebugkey |
2.鏂规硶浜?apksigner,榛樿鍚屾椂浣跨敤V1鍜孷2绛惧悕)
杩涘叆Android SDK/build-tools/SDK鐗堟湰, 杈撳叆鍛戒护
apksigner sign --ks 瀵嗛挜搴撳悕 --ks-key-alias 瀵嗛挜鍒悕 xxx.apk
鑻ュ瘑閽ュ簱涓湁澶氫釜瀵嗛挜瀵?鍒欏繀椤绘寚瀹氬瘑閽ュ埆鍚?/p>
apksigner sign --ks 瀵嗛挜搴撳悕 --ks-key-alias 瀵嗛挜鍒悕 xxx.apk
绂佺敤V2绛惧悕
1
|
apksigner sign --v2-signing-enabled false --ks 瀵嗛挜搴撳悕 xxx.apk |
鍙傛暟:
--ks-key-alias 瀵嗛挜鍒悕,鑻ュ瘑閽ュ簱鏈変竴涓瘑閽ュ,鍒欏彲鐪佺暐,鍙嶄箣蹇呴€?br /> --v1-signing-enabled 鏄惁寮€鍚疺1绛惧悕,榛樿寮€鍚?br /> --v2-signing-enabled 鏄惁寮€鍚疺2绛惧悕,榛樿寮€鍚?/p>
渚嬪:
鍦╠ebug.keystore瀵嗛挜搴撳彧鏈変竴涓瘑閽ュ
1
|
apksigner sign --ks debug.keystore MyApp.apk |
鍦╠ebug.keystore瀵嗛挜搴撲腑鏈夊涓瘑閽ュ,鎵€浠ュ繀椤绘寚瀹氬瘑閽ュ埆鍚?/p>
1
|
apksigner sign --ks debug.keystore --ks-key-alias androiddebugkey MyApp.apk |
3.绛惧悕楠岃瘉
1.鏂规硶涓€(keytool,鍙敮鎸乂1绛惧悕鏍¢獙)
杩涘叆JDK/bin, 杈撳叆鍛戒护
1
|
keytool -printcert -jarfile MyApp.apk (鏄剧ず绛惧悕璇佷功淇℃伅) |
鍙傛暟:
-printcert 鎵撳嵃璇佷功鍐呭
-jarfile <filename> 宸茬鍚嶇殑jar鏂囦欢 鎴朼pk鏂囦欢
2.鏂规硶浜?apksigner,鏀寔V1鍜孷2绛惧悕鏍¢獙)
杩涘叆Android SDK/build-tools/SDK鐗堟湰, 杈撳叆鍛戒护
1
|
apksigner verify -v --print-certs xxx.apk |
鍙傛暟:
-v, --verbose 鏄剧ず璇︽儏(鏄剧ず鏄惁浣跨敤V1鍜孷2绛惧悕)
--print-certs 鏄剧ず绛惧悕璇佷功淇℃伅
渚嬪:
1
|
apksigner verify -v MyApp.apk |
Verifies
Verified using v1 scheme (JAR signing): true
Verified using v2 scheme (APK Signature Scheme v2): true
Number of signers: 1
以上是关于Android涓瑼PK绛惧悕宸ュ叿涔媕arsigner鍜宎pksigner璇﹁В的主要内容,如果未能解决你的问题,请参考以下文章