ASFP Study
The first IDE developed by AOSP in history (supports Java/Kotlin/C++/Jni/Native/Shell/Python)
Similar to Android Studio, it can be used to develop Android system source code.
Android studio for platform, referred to as asfp (Falling in Love with a Rich Woman).
Background & amp;Download & amp;Use
Background
Because the Android system source code is too large, for example, the Android14 source code is 400G.
Friends who develop AOSP are often stuck with tools for changing code. Previously, the mainstream IDEs mainly included:
-
Generate the corresponding android.ipr and android.iml files through idgen, and then use Android Studio to load the entire source code.
The disadvantages are obvious: file permission issues, very resource consuming, very stuck, unable to compile, and Gradle causing trouble at regular intervals.
-
Compile the corresponding module through AIDEGen, and then load it using Idea, which has the functions of jump and completion.
It’s complicated and cumbersome to use, it can’t be compiled, and it doesn’t seem to support kt.
-
Use Eclipse to load the source code module and pour into framework.jar and other libraries.
The UI cannot keep up with the times and is difficult to use.
-
Use Source Insight/Visual Code/Sublime tools for bare development, and use other IDEs to complete some syntax verification and completion work.
There is no completion function. The advantage is that it does not consume system resources so much.
Basic situation
Now Google has officially launched Android Studio for Platform, a special version for system development, which should be able to solve the troubles of most Android system development practitioners.
Let’s talk about the general situation first:
-
advantage:
- It can load several modules you care about, supports separate compilation, and has its own Soong build system.
- Supports jump/completion/derivation relationships in multiple languages.
- Supports flexible text search, file search, flexible configuration, JetBrain family features, and a very familiar taste.
- Supports single point debugging, but must base official source code and official image
-
shortcoming:
- Currently only supports Linux systems and can be used under Ubuntu
- The computer configuration requirements are also a bit high
- There is still something lacking about the jump of JNI C++
Let’s get started!
Download
https://developer.android.com/studio/platform?hl=zh-cn
Currently only Ubuntu is supported, and the operating system type will be automatically identified. If it is not Ubuntu, it will be displayed as unavailable.
From my understanding, Windows will not be supported in the future. Anyone who develops Android systems understands this.
If it is inconvenient for you to download the resources, I have uploaded them to
netdisc:
Baidu Netdisk:
Link: https://pan.baidu.com/s/1g82vNLN2jFH3dWrS2gY_Pg?pwd=asfp Extraction code: asfp
CSDN download:
https://download.csdn.net/download/dengtonglong/88516673
Getting Started
Google official teaching video tutorial address: https://www.bilibili.com/video/BV1U
-
If you haven’t installed Repo yet, follow the instructions in Installing Repo.
If you want to know more about repo, you can refer to this article:
https://blog.csdn.net/dengtonglong/article/details/133365006?spm=1001.2014.3001.5502
-
If you haven’t already initialized and synced your Repo checkout branch, follow the instructions in Initializing the Repo Client.
Nowadays, most android source code projects are managed through repo, which is also the officially recommended method.
-
Download ASfP to Ubuntu.
-
Install ASfP:
sudo dpkg -i /path/to/asfp-2023.1.1.19-linux.deb
-
After asfp is installed, it will be in this directory by default:
/opt/android-studio-for-platform/bin/studio.sh
You can also create desktop icons:
[Desktop Entry] Version=1.0 Encoding=UTF-8 Name=Android Studio Exec=/opt/android-studio-for-platform/bin/studio.sh TryExec=/opt/android-studio-for-platform/bin/studio.sh Comment=Android Studio For Platform Terminal=false Categories=Qt;Development; Icon=/opt/android-studio-for-platform/bin/studio.png Type=Application
You can also mv this installation directory to your commonly used directory.
-
Import the project via:
You can choose a theme style:
Point to your Repo checkout directory
Specify
lunch
targetThen select the module to build
-
Click Done and your projects will begin syncing.
-
Operations such as creating a new project, IDE settings, adding modules, dependencies, configuration files, storage paths, etc. are the same as other JetBrain software, and even the shortcut keys are the same, familiar recipes.
For those who are used to Android Studio, this should be familiar to engineers.
Compile
When I join the project for the first time, it will be automatically compiled. Since the code I added contains some customizations and there are often problems with the test directory, the compilation reaches 99%, which is generally considered complete.
Essentially the compilation instructions are:
Syncing targets: [frameworks/base] Preparing for sync... Updating MAX_ARG_STRLEN to 131072 Generating Soong artifacts... /bin/bash -c "source build/envsetup.sh & amp; & amp; lunch xxxx-userdebug & amp; & amp; echo ANDROID_PRODUCT_OUT=$ANDROID_PRODUCT_OUT & amp; & amp; refreshmod" including device/mediatek/build/vendorsetup.sh
refreshmod should be very powerful!
After compilation, various project configuration iml files will be generated.
dependencies.iml
Dependent configuration directories
frameworks.base.iml
Source code configuration directory
frameworks.base-gen.iml
Directory of files generated by source code
After compilation, various intermediate versions of jars will be generated.
These classes.jar are actually the same as those usually compiled and generated in the out directory.
classes.jar generated by frameworks.base.core
- core-android-libraries
classes.jar for all dependencies
- dependencies-jars
classes.jar generated by frameworks.base
- frameworks.base-jars
Although ASFP supports soong compilation, it is not very easy to use. In project practice, it is still recommended to use m/mm/mmm compilation and debugging!
Configuration
Project configuration location:
Experience features
Features can provide convenience.
Java Kotlin jump completion derivation relationship
-
Supports java jump, completion, and derivation relationships
Check where it is called:
-
Support kotlin jump, completion, and derivation relationships
-
Support mutual jump between java and kotlin
You can try it yourself.
-
scratch function
When writing Android source code, such as some complex calculations, string processing, and some data processing algorithms, you need to verify its syntax and operation through Java code or kt code.
At this time, the scratch function is very useful.
Click to create scratch
Create a scratch class
Click the green arrow to run directly:
Run successfully!
JNI jump
I take com/android/server/alarm/AlarmManagerService.java as an example,
I found that the native method setKernelTime cannot jump to the corresponding jni method. This is somewhat contrary to the statement of some bloggers.
For the replacement method, you can use ctrl + shift + R to find
Native language support
In the Native environment, completion can be performed. This is very good and helps us solve a major problem in writing native code:
C/C++ language support
Adding the servicemanager module, there seems to be a lot of red reporting points. I think C and C++ depend on the entire environment. If it lacks this or that, it is impossible to run smoothly.
Therefore, you need to join the corresponding environment. If you are a full-time kernel developer, you can try to adjust it.
But it supports code completion, which is already very good.
Therefore, it is recommended to develop a large amount of C C++ code, and it is recommended to switch to clion.
C++ also supports scratch
You can experiment with the syntax and feasibility of running C++ code.
Python language support
Just install the python plug-in.
Shell language support
Just click the green arrow to run it. It is essentially run using bash.
mk/bp support
These two syntaxes are not supported, but if modifications are detected, you will be prompted to re-edit.
Single point debugging experience
Theoretically, the environmental requirements for single-point debugging are relatively strict and require the use of official code + official images;
I tried debugging on my local code, but failed.
The error “debug info can be unavailable” occurs and the running AS needs to be shut down.
In the end, there was no way to successfully debug a single point. Let’s try it again if we have the opportunity in the future!
Experience summary
I briefly give my personal experience and do not represent the official website.
Jump | Complete | Relationship | |
---|---|---|---|
java | Y | Y | Y |
kt | Y | Y | Y |
C/C + + | N | Y | N |
JNI/Native | N | Y | N |
Python | Y | Y | Y |
Shell | Y | Y | N/A |
mk/bp | N | N | N |
- It is very suitable for partners in Framework development, that is, the system team in mobile phone factories.
- If the company has its own components, it can be compatible by adding them to realize jump and completion.
- I hope to enhance the development experience of C C++ native. Maybe it can be adjusted. If you specialize in the development of a certain area, you can definitely integrate the Linux C suite.
- It is recommended to wait and see and wait for a more stable version to come out!