简体   繁体   中英

Where can I find the source code for classes in the Android SDK?

I'm trying to find the source code for Android SDK classes such as View, Canvas, and Bundle. Where can I find the source code for these classes and is it even possible?

The source code for built-in classes (those that are part of the Android SDK) can be viewed by downloading the SDK source code using the SDK Manager.

From within Android Studio, navigate to Tools -> Android -> SDK Manager. Once open, you'll need to download the Sources for Android SDK as shown below.

SDK管理器

Once you have the sources downloaded, you can find the source code inside of the "sources" folder of your SDK (wherever that may be on your computer). Below I've added an image to show where you would find the View.java class inside of the SDK source files. To find other classes in the SDK, navigate to them using the package name as a hint to their location in the folder structure. (eg android.app.Activity -> android/app/Activity.java).

查看.java位置

Also, if you download the source code for a specific version, then make that version your compileSdkVersion version in your build.gradle file, you can access source code from directly within Android studio by command clicking on the class name. So if you download the sources for API 21, then set your compileSdkVersion to be API 21 as shown below, you won't have to navigate your file system to find the file.

构建.gradle

Google has a site that provides Android source code. Visit https://android.googlesource.com . I was able to find the source code for view.java on that Google site.

For example you have to view source code for veridex report line: Landroidx/transition/ViewGroupUtilsApi14;->cancelLayoutTransition(Landroid/animation/LayoutTransition;)V

Then you step: Android Studio -> Project -> External Libraries -> Gradle: androidx.transition:1.2.0@aar -> classes.jar -> androidx.transition -> ViewGroupUtilsApi14

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM