工作中的驚喜不斷,今天遇到一個問題,一個客戶的手機升級爲最新的Android 10系統後,原來的我們項目的APP一點擊Icon啓動APP就閃退,根本不能用。
一開始懷疑是App版本兼容問題,查看項目app/build.gradle文件中配置如下:
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
multiDexEnabled true
applicationId "com.huaxing.alpha.apps.apollo" // "com.huaxing.alpha.apps.apollo" 正式的極光推送包名,// "com.astarup.app" 測試報名
minSdkVersion 23
targetSdkVersion 27
versionCode 49
versionName "5.5.3"
manifestPlaceholders = [
JPUSH_APPKEY: "d21c04aa23b0050dea5bf85c", //"d21c04aa23b0050dea5bf85c", // efd166b53c414825b0d3afe7 是測試的key
APP_CHANNEL : "developer-default"
]
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
查閱一堆資料後,發現並不是APP當前Android版本低造成的無法兼容Android10系統手機。
於是嘗試進行重新打包,在Android10手機進行實際測試。打包過程中遇到以下報錯:
Android AAPT: No resource identifier found for attribute 'appComponentFactory' in package 'android'
在解決這個報錯的過程中查到了這個資料issues:
這個報錯應該是google在androidx, google play service的問題,當前APP沒有支持AndroidX,解決方案,在項目android/build.gradle文件中添加如下代碼:
ext {
buildToolsVersion = "26.0.3"
minSdkVersion = 16
compileSdkVersion = 26
targetSdkVersion = 26
supportLibVersion = "26.1.0"
// 添加googlePlayServicesVersion
googlePlayServicesVersion = '16.+'
}
重新打包後,安裝真機測試,完美運行。
進一步查看發現是因爲項目中有react-native-device-info
依賴,查看項目說明中關於對AndroidX的支持,已有文檔說明了😀
This module defaults to AndroidX you should configure your library versions similar to this in your android/build.gradle file’s “ext” block
...
ext {
// dependency versions
We have 3 options for deviceId:
//Option 1 (latest):
firebaseIidVersion = "19.0.1" // default: "19.0.1"
//Option 2 (legacy GooglePlay dependency but using AndroidX):
googlePlayServicesIidVersion = "17.0.0" // default: "17.0.0" - AndroidX
//Option 3 (legacy GooglePlay dependency before AndroidX):
googlePlayServicesIidVersion = "16.0.1"
//include as needed:
compileSdkVersion = "28" // default: 28 (28 is required for AndroidX)
targetSdkVersion = "28" // default: 28 (28 is required for AndroidX)
supportLibVersion = '1.0.2' // Use '28.0.0' or don't specify for old libraries, '1.0.2' or similar for AndroidX
mediaCompatVersion = '1.0.1' // Do not specify if using old libraries, specify '1.0.1' or similar for androidx.media:media dependency
supportV4Version = '1.0.0' // Do not specify if using old libraries, specify '1.0.0' or similar for androidx.legacy:legacy-support-v4 dependency
}
...
總結一下吧,科技不斷髮展,技術也在不斷提升,作爲開發者,在開發的道路上總會遇到各種各樣的問題,也許你會不知所措,但是當你迎着頭皮上,解決這個問題的時候,你也學習成長了。
加油,開發者們。
歡迎關注我的微信公衆號:君偉說。
簡書:君偉說。
我的博客:https://blog.csdn.net/wayne214