Migrating to AndroidX
隨著 Android Studio 更新 Gradle Version 到 5.1.1,在 app 層級的 build.gradle 出現了錯誤
把滑鼠移到 com.android.support:support-v4:28.0.0 的紅底線,出現的說明
,老人家有閱讀障礙,所以把說明做了斷行,如下:
Dependencies using groupId com.android.support and androidx.* can not be combined
but found
IdeMavenCoordinates
{
myGroupId='com.android.support',
myArtifactId='asynclayoutinflater',
myVersion='28.0.0',
myPacking='aar',
myClassifier='null'
}
and
IdeMavenCoordinates
{
myGroupId='androidx.localbroadcastmanager',
myArtifactId='localbroadcastmanager',
myVersion='1.0.0',
myPacking='aar',
myClassifier='null'
}
incompatible dependencies less... (Ctrl+F1)
Inspection info:
There are some combinations of libraries,
or tools and libraries,
that are incompatible,
or can lead to bugs.
One such incompatibility is compiling with a version of the Android support libraries that is not the latest version
(or in particular, a version lower than your targetSdkVersion).
Issue id: GradleCompatible
大意好像是說我的專案所相依的函式庫出現衝突!一個是 com.android.support,一個是 androidx.localbroadcastmanager,印象中 androidx. 開頭的函式庫是 jetpack 在用的;可是一來我還不懂 jetpack,所以沒改用 jetpack,二來是我的專案也沒使用 jetpack......
爬了好多文,嘗試加入設定,讓 Android Studio 明確使用來自 com.android.support,或是排除引用 androidx. 開頭的,不過都失敗。
以 Dependencies using groupId com.android.support and androidx.* can not be combined 搜尋,跳出了 Migrating to AndroidX 這一篇,看似要開發者改用這個。
依照指示,在該頁的 Artifact mappings 置換成 AndroidX,
...
...
dependencies {
// implementation 'com.android.support:support-v4:28.0.0'
// implementation "com.android.support:customtabs:28.0.0"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.browser:browser:1.0.0'
就 Sync 成功了,不知道是不是正解,提供遇到同樣問題的朋友參考。
