The first IDE developed by AOSP in history (supports Java/Kotlin/C++/Jni/Native/Shell/Python)

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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

image-20231108224251683

image-20231108224330263

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

image-20231023120651551

Getting Started

Google official teaching video tutorial address: https://www.bilibili.com/video/BV1U

  1. 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

  2. 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.

  3. Download ASfP to Ubuntu.

  4. Install ASfP:

    sudo dpkg -i /path/to/asfp-2023.1.1.19-linux.deb

  5. 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
    

    image-20231108165501869

    You can also mv this installation directory to your commonly used directory.

  6. Import the project via:

    You can choose a theme style:

    image-20231107182239873

    image-20231107182536908

    Point to your Repo checkout directory

    Specify lunch target

    Then select the module to build

    image-20231107183116309

  7. Click Done and your projects will begin syncing.

  8. 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!

image-20231108092959039

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

image-20231108102839175

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.

image-20231108172411187

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:

image-20231108103909927

image-20231108104925002

Experience features

Features can provide convenience.

Java Kotlin jump completion derivation relationship

  • Supports java jump, completion, and derivation relationships

    Check where it is called:

    image-20231108093617436

  • Support kotlin jump, completion, and derivation relationships

    image-20231108104033476

  • 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

image-20231108174349402

Create a scratch class

image-20231108100426729

Click the green arrow to run directly:

image-20231108100518523

Run successfully!

image-20231108100624168

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.

image-20231108100130378

For the replacement method, you can use ctrl + shift + R to find

image-20231108100101965

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:

image-20231108113459863

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.

image-20231108105127375

image-20231108095757328

But it supports code completion, which is already very good.

image-20231108175204604

Therefore, it is recommended to develop a large amount of C C++ code, and it is recommended to switch to clion.

image-20231108105149878

C++ also supports scratch

image-20231108105332754

image-20231108105450772

You can experiment with the syntax and feasibility of running C++ code.

Python language support

image-20231108174759835

image-20231108175826022

Just install the python plug-in.

Shell language support

Just click the green arrow to run it. It is essentially run using bash.

image-20231108114344688

mk/bp support

These two syntaxes are not supported, but if modifications are detected, you will be prompted to re-edit.

image-20231108114842773

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.

image-20231108094500252

image-20231108094522417

image-20231108094635353

image-20231108094730166

image-20231108095114798

The error “debug info can be unavailable” occurs and the running AS needs to be shut down.

image-20231108095546936

image-20231108095735584

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!