不知道大家有沒有注意到這么個問題:
在最新創建專案的時候,有了 User androidx.* artifacts 這樣一個選項,可能你還不知道 androidx 的意思,可以這樣理解,androidx 代替了之前的一系列的 support 庫,如果你選擇了 androidx 就表示在你新創建的專案里面使用的支持庫就是 androidx 了而不是之前我們用的 support 型別的支持庫了,
假設這里不勾選那么就說明我們依然使用之前的 android.support.* 這種型別的支持庫,比如implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' 等等,
這個時候你新建的專案如果編譯的時候用的 api 28,也就是在build.gradle 中是 compileSdkVersion 28 這個是你會發現,當你查看 support 庫中的代碼的時候沒法看了,變成下面這樣了
沒法看原始碼了,只能看到 .class 了,這是因為:
在 Android 28.0.0 已經沒有給 Support Library 28.0.0 提供原始碼查看了,即便我們使用了 Android 28 進行編譯專案,用了 Support Library 28.0.0,這個時候當你查看 Support Library 中的類的時候會發現無法查看原始碼,看到的只是 xxx.class ,這是因為在 Android9.0(API 級別 28)發布后,新版本支持庫 AndroidX 隨之誕生了,它屬于 JetPack,除了包含了原先支持庫中的內容,還包含了最新的 JetPack 組件,
在使用 api 28 的時候我們仍然可以繼續使用支持庫,不過所有的新庫的開發都在 androidx 中進行了,因此我們是看不到原始碼的(之前的版本是可以看到原始碼的),Google 建議所有的新專案使用 androidx 庫,
因此解決方案
擁抱 androidx 庫,這也是 Google 所推薦的
另外一個方法就是使用 28 以下的版本來進行編譯:比如:
compileSdkVersion 26
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
這樣是仍然可以查看 support 中類的源代碼的,
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/25163.html
標籤:Android
