发表文章

[最新] Android 8.0系统给第三方apk进行系统签名(未使用Andriod Studio,在Android系统编译环境下签名)

sunny8994420 3月前 2

转载:http://blog.csdn.net/sinat_24946363/article/details/79934086

 

今天组长突然让我给第三方应用系统签名,按照网上搜索的常规方法,没一个奏效,还报错,贼郁闷,最后在龙哥的指导下搞定。

现在将方法整理出来,希望对大家有所帮助~

 

首先该应用一定要在AndroidManifest中加入系统级权限

android:sharedUserId="android.uid.system"

直接安装会报错提示没有系统签名,需要把该应用系统签名

Failure [INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: Package couldn't be installed in /data/app/com.heyzqt.translationdemo-r7KmIstNnpWKc5auFnisUA==: Package com.heyzqt.translationdemo has no signatures that match those in shared user android.uid.system; ignoring!]

 

根据网上搜索出的命令尝试进行系统签名,失败

找到Android源码目录android/o-base/build/target/product/security下的platform.pk8和platform.x509.pem文件,以及out/host/linux-x86/framework/signapk.jar文件置于统一目录下,使用cmd执行以下命令:

 

signapk.jar platform.x509.pem platform.pk8 app.apk new.apk

执行成功,但是没有生成新的签名apk,没有作用

 

signapk platform.x509.pem platform.pk8 app.apk app1.apk

提示signapk既不是内部或外部命令,也不是可执行的batch文件

 

java -jar signapk.jar platform.x509.pem platform.pk8 app.apk app.apk

报错:类库conscrypt_openjdk_jni-windows-x86_64和conscrypt_openjdk_jni加载失败,无法签名


 
  1. Exception in thread "main" java.lang.ExceptionInInitializerError

  2. at org.conscrypt.OpenSSLBIOInputStream.<init>(OpenSSLBIOInputStream.java:37)

  3. at org.conscrypt.OpenSSLX509Certificate.fromX509PemInputStream(OpenSSLX509Certificate.java:129)

  4. at org.conscrypt.OpenSSLX509CertificateFactory$1.fromX509PemInputStream(OpenSSLX509CertificateFactory.java:226)

  5. at org.conscrypt.OpenSSLX509CertificateFactory$1.fromX509PemInputStream(OpenSSLX509CertificateFactory.java:222)

  6. at org.conscrypt.OpenSSLX509CertificateFactory$Parser.generateItem(OpenSSLX509CertificateFactory.java:100)

  7. at org.conscrypt.OpenSSLX509CertificateFactory.engineGenerateCertificate(OpenSSLX509CertificateFactory.java:278)

  8. at java.security.cert.CertificateFactory.generateCertificate(Unknown Source)

  9. at com.android.signapk.SignApk.readPublicKey(SignApk.java:184)

  10. at com.android.signapk.SignApk.main(SignApk.java:1007)

  11. Caused by: java.lang.IllegalArgumentException: Failed to load any of the given libraries: [conscrypt_openjdk_jni-windows-x86_64, conscrypt_openjdk_jni]

  12. at org.conscrypt.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:176)

  13. at org.conscrypt.NativeCryptoJni.init(NativeCryptoJni.java:49)

  14. at org.conscrypt.NativeCrypto.<clinit>(NativeCrypto.java:57)

  15. ... 9 more

 

成功的签名方法

在终端上执行source build/envsetup.sh,再执行lunch

新建android/o-base/vendor/test目录,在该目录中放入未签名的app.apk文件和Android.mk文件

Android.mk文件参考源码vendor/google/apps/Android.mk文件,因为该目录下都是apk文件,一部分是需要系统签名的apk(LOCAL_CERTIFICATE := platform),而另一部分是不需要签名的apk(LOCAL_CERTIFICATE := PRESIGNED)

具体内容如下


 
  1. LOCAL_PATH := $(call my-dir)

  2. ##############################

  3. include $(CLEAR_VARS)

  4.  
  5. LOCAL_MODULE := app

  6. LOCAL_SRC_FILES := app.apk

  7. LOCAL_MODULE_CLASS := APPS

  8. LOCAL_MODULE_SUFFIX := .apk

  9. LOCAL_BUILT_MODULE_STEM := package.apk

  10. LOCAL_CERTIFICATE := platform

  11. LOCAL_PRIVILEGED_MODULE := true

  12.  
  13. include $(BUILD_PREBUILT)

核心是下面这句话,意思为签署当前的应用名称,实际上也就是用platform.pk8文件和platform.x509.pem来给改应用签名

LOCAL_CERTIFICATE := platform

配置好后,在vendor/app目录下执行mm命令编译apk,

在目录下out/target/product/xxxx/system/priv-app/app/app.apk找到编译好后的apk,此时该apk已经被成功签名

adb install app.apk

success

成功安装,搞定!

 

参考文章:

关于android:sharedUserId="android.uid.system"这个系统级权限

Android.mk详解

Android Studio自动生成带系统签名的apk

相关推荐
最新评论 (0)
返回
发表文章
sunny8994420
文章数
7
评论数
0
注册排名
803413