android studio 编译后 app-debug.apk 和 app-release.apk 的区别

AS版本:Android studio 3.2.1

app-debug.apk 和 app-release.apk 的核心区别在AndroidManifest.xml 。

生成app-debug.apk时,编译器会自动在该apk的AndroidManifest.xml中添加 android:debuggable="true"
生成app-release.apk时,编译器会自动在该apk的AndroidManifest.xml中去掉 android:debuggable

make project(ctrl+F9) 生成app-debug.apk
run app (shift + F10)生成app-debug.apk

 

adb install Y:\test\debug\app-debug.apk
Y:\test\debug\app-debug.apk: 1 file pushed. 2.0 MB/s (9533549 bytes in 4.548s)
        pkg: /data/local/tmp/app-debug.apk
Failure [INSTALL_FAILED_TEST_ONLY]
 

adb install Y:\test\debug\app-release.apk
Y:\test\debug\app-release.apk: 1 file pushed. 2.0 MB/s (7958040 bytes in 3.748s)
        pkg: /data/local/tmp/app-release.apk
Failure [INSTALL_FAILED_SHARED_USER_INCOMPATIBLE]
 

adb install Y:\test\debug\pt2259_debug.apk   (用platform签过名)
Y:\test\debug\pt2259_debug.apk: 1 file pushed. 2.0 MB/s (8906761 bytes in 4.158s)
        pkg: /data/local/tmp/pt2259_debug.apk
Failure [INSTALL_FAILED_TEST_ONLY]
 

adb install Y:\test\debug\pt2259_release.apk     (用platform签过名)
Y:\test\debug\pt2259_release.apk: 1 file pushed. 2.0 MB/s (7962337 bytes in 3.757s)
        pkg: /data/local/tmp/pt2259_release.apk
Success
 

 

 总结:

1. app-debug.apk只能通过run app运行到目标设备,如果把这个apk通过adb install安装到目标设备,则报错:INSTALL_FAILED_TEST_ONLY

2. adb install只能安装release版apk

3. 系统权限签名:
签名工具存放在系统源码的目录  out/host/linux-x86/framework/signapk.jar
签名文件存放在系统源码的目录  build/target/product/security/
签名方法:java  -jar  signapk.jar  platform.x509.pem  platform.pk8  old.apk  new.apk

4. INSTALL_FAILED_SHARED_USER_INCOMPATIBLE报错是因为没有系统权限签名,即没有用platform.pk8和platform.x509.pem进行权限签名。

5.  android studio中如下签名不是权限签名,是java包名唯一性签名,即为了防止他人反编译用同样包名篡改apk。简而言之,没有同样的.jks签名文件,则同样包名的apk无法覆盖安装同包名的apk。

 

android studio 编译后 app-debug.apk 和 app-release.apk 的区别_第1张图片

 

你可能感兴趣的:(Android,app)