hi,粉丝朋友:
近期又粉丝朋友聊到了如果做aosp系统应用开发,有什么工具或者方式来导入代码可以正常跳转和代码提示等?
更多内容: https://blog.csdn.net/learnframework/article/details/130016893
Android Studio导入系统源码
针对这个问题其实我课程里面的[入门课就有有讲解android studio导入整套系统源码]的详细说明,这里就再次补充一下android studio导入android系统源码
1、生成对应的android.ipr和android.iml文件
make idegen -j4
“development/tools/idegen/idegen.sh” (报错find: ‘out/target/product/generic_x86_64/root/d’: Permission denied没有关系不影响ipr和iml文件生成)
sudo chmod 777 android.iml android.ipr
2、有了ipr和iml,删减一部分android.iml的内容,主要原因源码太多,要排除部分没用项目,还有就是依赖部分只留下自己moudle就可以
把android.iml中的excludeFolder标签都删除用以下标签
<excludeFolder url="file://$MODULE_DIR$/art" />
<excludeFolder url="file://$MODULE_DIR$/bionic" />
<excludeFolder url="file://$MODULE_DIR$/bootable" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/compatibility" />
<excludeFolder url="file://$MODULE_DIR$/cts" />
<excludeFolder url="file://$MODULE_DIR$/dalvik" />
<excludeFolder url="file://$MODULE_DIR$/developers" />
<excludeFolder url="file://$MODULE_DIR$/developers/samples" />
<excludeFolder url="file://$MODULE_DIR$/development" />
<excludeFolder url="file://$MODULE_DIR$/device" />
<excludeFolder url="file://$MODULE_DIR$/device/google" />
<excludeFolder url="file://$MODULE_DIR$/device/sample" />
<excludeFolder url="file://$MODULE_DIR$/docs" />
<excludeFolder url="file://$MODULE_DIR$/external" />
<excludeFolder url="file://$MODULE_DIR$/flashing-files" />
<excludeFolder url="file://$MODULE_DIR$/frameworks/base/docs" />
<excludeFolder url="file://$MODULE_DIR$/hardware" />
<excludeFolder url="file://$MODULE_DIR$/kernel" />
<excludeFolder url="file://$MODULE_DIR$/libcore" />
<excludeFolder url="file://$MODULE_DIR$/libnativehelper" />
<excludeFolder url="file://$MODULE_DIR$/out" />
<excludeFolder url="file://$MODULE_DIR$/out/soong/.intermediates" />
<excludeFolder url="file://$MODULE_DIR$/pdk" />
<excludeFolder url="file://$MODULE_DIR$/platform_testing" />
<excludeFolder url="file://$MODULE_DIR$/prebuilt" />
<excludeFolder url="file://$MODULE_DIR$/prebuilts" />
<excludeFolder url="file://$MODULE_DIR$/sdk" />
<excludeFolder url="file://$MODULE_DIR$/shortcut-fe" />
<excludeFolder url="file://$MODULE_DIR$/system" />
<excludeFolder url="file://$MODULE_DIR$/test" />
<excludeFolder url="file://$MODULE_DIR$/toolchain" />
<excludeFolder url="file://$MODULE_DIR$/tools" />
把orderEntry标签都删除,只剩下如下两个即可以,这样跳转时候就不会跳其他jar
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="jdk" jdkName="Android API 33 Platform" jdkType="Android SDK" />
这样android studio就完全可以进行相关的跳转了,同时各个app其实也可以进行跳转,如下图的Settings:
这种其实也有一些androidx库依赖标红啥的,这个相对比较少影响不是太大,不过这个也可能是很多同学不喜欢的点,那么有啥更好办法解决么?当然有,那就是今天主题AIDEGen
AIDEGen导入各个模块代码
AIDEGen相关文档:
tools/asuite/aidegen/README.md
首先看它的相关官方readme,英文的,其实也比较好懂,这里就不做翻译了,我相信也完全可以看懂
AIDEGen
AIDEGen aims to automate the project setup process for developers to work on
Java or C/C++project in popular IDE environment. Developers no longer need to manually
configure an IntelliJ project, such as all the project dependencies. It’s a
command line tool that offers the following features:
-
Configure Android Studio or IntelliJ project files with the relevant module
dependencies resolved. -
Launch IDE for a specified sub-project or build target, i.e. frameworks/base
or Settings. -
Launch IDE for specified folder(s) which contains build targets, i.e. cts.
-
Auto configure JDK and Android coding style for IntelliJ.
(上面其实就是说明了一下AIDEGen是干啥的,大概意思就是它是一个自动生成项目配置文件,针对不同的主流ide都是可以的,比如 Android Studio or IntelliJ project等,就不需要我们自己针对不同ide来搞对应项目)
1. Prerequisites:
-
IDE installation, choose one of prefer IDE, including Android Studio,
IntelliJ IDEA, Eclipse, CLion and VS Code. -
Setup Android development environment.
$ source build/envsetup.sh && lunch <TARGET>
(以上是预备条件,配置好aosp的env和lunch,而且要本身系统安装好了的对应的ide,比如Android Studio,IntelliJ IDEA, Eclipse, CLion and VS Code)
2. Basic Usage:
Example 1: Launch IDE with module name
Example to generate and launch IntelliJ project for framework and Settings:
可以直接使用module name来进行对应的启动
$ aidegen Settings framework
Example 2: Launch IDE with module path
Example to generate and launch IntelliJ project for framework and Settings:
可以直接使用module path来进行对应的启动
$ aidegen packages/apps/Settings frameworks/base
Example 3: Launch IDE with build skipped
Example to generate and launch IntelliJ project for framework and Settings and
skip build time:
这里可以用-s来跳过编译,一般使用这种如果已经编译了的话
$ aidegen Settings framework -s
Example 4: Launch IDE with native module
Example to generate and launch CLion project:
$ aidegen <module> -i c
The native projects will be launched in CLion and you have to select,
Tools > CMake > Change Project Root
Change project root to the source directory: the relative path which is the directory shown in CLion’s project view. For example, if frameworks/base/media is your project, please change project root directly to frameworks/base/media.
3. Optional arguments:
Developers can also use the following optional arguments with AIDEGen commands.
Option | Long option | Description |
---|---|---|
-d | --depth | The depth of module referenced by source. |
-i | --ide | Launch IDE type, j=IntelliJ s=Android Studio e=Eclipse c=CLion v=VS Code |
-p | --ide-path | Specify user’s IDE installed path. |
-n | --no_launch | Do not launch IDE. |
-r | --config-reset | Reset all AIDEGen’s saved configurations. |
-s | --skip-build | Skip building jars or modules. |
-v | --verbose | Displays DEBUG level logging. |
-a | --android-tree | Generate whole Android source tree project file for IDE. |
-e | --exclude-paths | Exclude the directories in IDE. |
-l | --language | Launch IDE with a specific language,j=java c=C/C++ r=Rust |
-h | --help | Shows help message and exits. |
4. Troubleshooting tips:
If you get an error like: “Dependent modules dictionary is empty.” or other errors, try a make
clean.
5. FAQ:
Q1. If I already have an IDE project file, and I run command AIDEGen to generate
the same project file again, what’ll happen?
A1: The former IDEA project file will be overwritten by the newly generated one
from the aidegen command.
Q2: When do I need to re-run AIDEGen?
A2: Re-run AIDEGen after repo sync.
6. Hint:
-
In IntelliJ, uses [File] > [Invalidate Caches / Restart…] to force
project panel updated when your IDE didn’t sync. -
If you run aidegen on a remote desktop, make sure there is no IntelliJ
running in a different desktop session.
6. Feedback:
If you have any questions or feedback, contact aidegen_tnn@google.com.
If you have any bugs or feature requests email them to buganizer-system+429701@google.com.
实战体验Settings
命令:
aidegen packages/apps/Settings -i s -s
针对androidx等也不会报错
相对系统app来说确实体验还是很不错,比源码整体导入那种相对更好一些,也非常简单,不需要为了Setting导入整套代码,跳转framework部分的代码也是正常的: