有時候我們在寫Android APP 安裝到實體機測試的時候
會出現「未安裝應用程式。 發生衝突,安裝套件所使用的簽名與現有套件的簽名相同」
有別的文章有提到說,可能是因為先前安裝的程式沒有刪除,需要先把程式完全移除
但是今天遇到的問題是並非上述所提及的「同一個程式衝突」而是「不同程式衝突」
問題產生的流程是這樣
複製舊程式,修改程式碼與更改package名稱後,安裝程式發生衝突問題
原因可以出在更改名稱之後Gradle沒有同步更改
我們更改package名稱操作可能會如下圖所示
但是在Gradle底下卻不會一起更動
所以需要自己手動更改成新的名稱
另外一個問題是我們在產生APK的時候,可能會選擇「Build APK」這個選項
他會產生APK檔案沒有錯,但是Android在辨別APP的時候會比對「package名稱」跟「簽名」
使用這個選項是Android Studio 幫你使用預設的 Debug 簽名
在安裝的時候發現package名稱不一樣,但是簽名一樣,然後跳出錯誤訊息
所以當你有很多個不同的APP的時候,需要使用「Generate Signed APK」
原則上問題應該可以解決
至於簽名可不可以多個APP用同一個簽名,答案是可以的,而且Android官方也如此建議
為什麼要使用同一個簽名的原因如下
1. 升級:package名稱和簽名相同時,系統會判定兩者為同一個APP所以會更新程式
2. 模組:Android可以讓相同簽名的程式跑在同一個程序裡面,這樣可以個別升級
3. 共享:Android可以用相同簽名的程式在permission與許的情況下共享程式碼與數據
You should sign all of your APKs with the same certificate throughout the expected lifespan of your apps. There are several reasons why you should do so:
- App upgrade: When the system is installing an update to an app, it compares the certificate(s) in the new version with those in the existing version. The system allows the update if the certificates match. If you sign the new version with a different certificate, you must assign a different package name to the app—in this case, the user installs the new version as a completely new app.
- App modularity: Android allows APKs signed by the same certificate to run in the same process, if the apps so request, so that the system treats them as a single app. In this way you can deploy your app in modules, and users can update each of the modules independently.
- Code/data sharing through permissions: Android provides signature-based permissions enforcement, so that an app can expose functionality to another app that is signed with a specified certificate. By signing multiple APKs with the same certificate and using signature-based permissions checks, your apps can share code and data in a secure manner.
Golden Nugget Hotel Casino & Spa - Mapyro
回覆刪除Golden Nugget 경상남도 출장샵 Hotel Casino & 서산 출장샵 Spa is a casino 대구광역 출장안마 in 강원도 출장마사지 Las Vegas, Nevada and is open daily 24 hours. The casino has an outdoor pool 순천 출장샵 and an outdoor