0. View Android framework source code

reference

http://kaedea.com/2016/02/09/android-about-source-code-how-to-read/

https://www.zhihu.com/question/19759722

 

View system source code Description

1. You can view the source of most of the framework source code sdk

 

2. If the source of the sdk can not find a class system source code, you can view the official source network

https://android.googlesource.com/?format=HTML

 

Wherein the source framework platform / frameworks / base,

android/platform/frameworks/base/android-xxx/./core/java

 

View hidden API source in the AS

Relations platform and sources directory

AS will platform inside android.jar in class files associated with the corresponding sources in the java file.

That android.jar there is no class in the AS can not see inside, android.jar a corresponding class file to be mapped to sources in the corresponding java file.

If there is no corresponding api of sources, then it will display android.jar resolved in the class file.

 

1 Introduction

Android There are two types of API is not accessible through the SDK.

  • The first is located in the COM. Android .internal package API. I would call internal API.
  • The second type is a set of API classes and methods are labeled as @hide properties.

Internal and hidden API compile time vs runtime

When you use the Android SDK for development, you refer to a very important jar files --android.jar. It is located Android SDK platform folder (SDK_DIR / platforms / platform-X / android.jar). This package com.android.internal android.jar definite displacement of all the classes, also labeled with some definite displacement @hide class, enumeration, fields and methods.

Each simulator or a real machine during operation, there will be an equivalent android.jar thing called framework.jar, it android.jar equivalents, and which is not definite displacement internal API and hidden API. When you launch the application on the device, it will load framework.jar.

But this for developers, and not a friendly visit, therefore, I will show you how to use the API not by reflection.

 

2. Solution

method one

The general process is this: we can from framework.jar, extract the original .class files, and copied to the Android SDK in android.jar.

Note: simulators generally comprise .dex code files, and generally comprise real machine codes --odex optimized version of the file in the file dex. Odex file operations more difficult, and this is the reason why I chose the simulator.

 

  1. adb pull /system/framework/framework.jar

    Or use DDMS in the File Explorer.

  2. Classes.dex extracted from the framework.jar,
  3. Use dex2jar tool to convert it into classes.jar
  4. Then classes.jar All the files in android.jar to replace.
  5. Replace D: \ Android \ sdk \ platforms \ android-xx where you can android.jar

    Note: remember to backup the original android.jar

     

    Note: It may be high version of the system to hide api assigned to multiple jar package, so need to be operating above

  • android.policy.jar
  • framework.jar
  • framework2.jar
  • services.jar

Method Two

In the panacea it has been GitHub remove Android.jar in @hide comment

Address: https://github.com/anggrayudi/android-hidden-api

1. Download the corresponding version of the API Android.jar

2. Replace the SDK / platforms / android- version /Android.jar

3. Re-open IDE can view

 

Direct API calls to hide the shortcomings:

1.Android API is hidden because there is no guarantee that these new API system version, so minimize the use of hidden API!

2. Do not conducive to team work, if someone can not compile as normal Android.jar endCall () like hidden API!

 

 

 

eclipse view Android source code

Just create a project in eclipse,

Right Project - "properties-" java build path- "Libraries-" Add external jars- "select D: \ Android \ sdk \ platforms \ android-xx \ android.jar

 

source attachment at the android.jar

 

Use Idea View Android source code

Before there to see the eclipse of the Android source code framework, but the eclipse look too weak, not too convenient. AS View is convenient but each time had to modify the source code to see Android android.jar platform, very convenient.

IntelliJ IDEA can be used to view it.

Associate Android sdk,

 

It can easily create a java project

Then open the Project Structure of the project, you can see the available sdk in sdks, which contains the Android sdk, you can modify the classpath

 

Then modules tab, when the project dependencies root directory jdk, where you can directly modify the root directory of the reference sdk.

Or you can create a new module, modify dependencies module, so that you can access the Android sdk jdk and the source code at the same time.

 

 

 

In the AS view hidden API source 2

I do not know how it is, not to see the layout of the idea, so after various attempts to use AS View back to the source.

Specifically idea is to mimic the settings in the project structure in. The final fact is a modified C: \ Users \ puppet \ .IdeaIC2019.2 \ config \ options \ jdk.table.xml file.

Since the project structure as modified in the interface 3.4, the sdks removed, then can not modify the ide, the direct manual modification jdk.table.xml.

  1. Open C: \ Users \ puppet \ .AndroidStudio3.4 \ config \ options \ jdk.table.xml file, find the corresponding version of Android, adding the corresponding full version android.jar in <classPath> tag.
  2. Then restart as, you can.

 

 

 

 

Guess you like

Origin www.cnblogs.com/muouren/p/11701664.html