程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

AndroidStudio导入Android源码

发布于2021-05-29 22:26     阅读(888)     评论(0)     点赞(20)     收藏(4)


AndroidStudio导入Android源码

简介

development/tools/idegen/目录下有个README文件

IDEGen automatically generates Android IDE configurations for IntelliJ IDEA
and Eclipse. Your IDE should be able to compile everything in a reasonable
amount of time with no errors.
 
If you're using IntelliJ...
    If this is your first time using IDEGen...
        IDEA needs a lot of memory. Add "-Xms748m -Xmx748m" to your VM options
        in "IDEA_HOME/bin/idea.vmoptions" on Linux or
        "IntelliJ IDEA.app/Contents/Info.plist" on OS X.
        Create a JDK configuration named "1.6 (No Libraries)" by adding a new
        JDK like you normally would and then removing all of the jar entries
        under the "Classpath" tab. This will ensure that you only get access to
        Android's core libraries and not those from your desktop VM.
 
    From the project's root directory...
        Repeat these steps after each sync...
        1) make (to produce generated .java source)
        2) development/tools/idegen/idegen.sh
        3) Open android.ipr in IntelliJ. If you already have the project open,
           hit the sync button in IntelliJ, and it will automatically detect the
           updated configuration.
        If you get unexpected compilation errors from IntelliJ, try running
        "Build -> Rebuild Project". Sometimes IntelliJ gets confused after the
        project changes significantly.
If you're using Eclipse...
 
    If this is your first time using IDEGen...
 
        Edit eclipse.ini ("Eclipse.app/Contents/MacOS/eclipse.ini" on OS X) and
        add "-Xms748m -Xmx748m" to your VM options.
 
        Configure a JRE named "1.5 (No Libraries)" under "Preferences -> Java ->
        Installed JREs". Remove all of the jar entries underneath "JRE system
        libraries". Eclipse will not let you save your configuration unless at
        least one jar is present, so include a random jar that won't get in the
        way.
    From the project's root directory...
 
        Repeat these steps after each sync...
 
        1) make (to produce generated .java source)
        2) development/tools/idegen/idegen.sh
        3) Import the project root directory into your Eclipse workspace. If you
           already have the project open, simply refresh it (F5).
Excluding source roots and jars
    IDEGen keeps an exclusion list in the "excluded-paths" file. This file
    has one regular expression per line that matches paths (relative to the
    project root) that should be excluded from the IDE configuration. We
    use Java's regular expression parser (see java.util.regex.Parser).
    You can create your own additional exclusion list by creating an
    "excluded-paths" file in the project's root directory. For example, you
    might exclude all apps except the Browser in your IDE configuration with
    this regular expression: "^packages/apps/(?!Browser)".
Controlling source root ordering (Eclipse)
    You may want some source roots to come before others in Eclipse. Simply
    create a file named "path-precedence" in your project's root directory.
    Each line in the file is a regular expression that matches a source root
    path (relative to the project's root directory). If a given source root's
    path matches a regular expression that comes earlier in the file, that
    source root will come earlier in the generated configuration. If a source
    root doesn't match any of the expressions in the file, it will come last,
    so you effectively have an implicit ".*" rule at the end of the file.
    For example, if you want your applications's source root to come first,
    you might add an expression like "^packages/apps/MyApp/src$" to the top
    of the "path-precedence" file.  To make source roots under ./out come last,
    add "^(?!out/)" (which matches all paths that don't start with "out/").

生成导入到AS所需的配置文件

首先要编译一次源码

然后看有没有out/host/linux-x86/framework/idegen.jar ,如果没有的话就执行一下下面的命令,生成out/host/linux-x86/framework/idegen.jar:

source build/envsetup.sh

mmm development/tools/idegen/	# 生成idegen.jar
make idegen -j4

. development/tools/idegen/idegen.sh   # 生成 android.ipr 和 android.iml

会在根目录下面生成android.ipr和android.iml。

附件中已经存放备用文件!!!

android.ipr:一般保存了工程相关的设置,比如 modules 和 modules libraries 的路径,编译器配置,入口点等。

android.iml:用来描述modules。它包括modules路径、 依赖关系,顺序设置等。一个项目可以包含多个 *.iml 文件。

android.iws :(主要包含一些个人的配置信息,也有可能在执行上述操作后没有生成,这个没关系,在打开过一次项目之后就会自动生成了)

到这一步我们其实就可以导入到Android Studio里面去了。

过滤一些模块

如果把Android所有的源码全部导入到Android Studio里面去,工程将会非常大,而且会很耗时间,那么我们就可以把不需要的模块给过滤掉。

打开android.iml文件,加入以下代码,修改excludeFolder的配置:

<excludeFolder url="file://$MODULE_DIR$/.repo"/>
<excludeFolder url="file://$MODULE_DIR$/abi"/>
<excludeFolder url="file://$MODULE_DIR$/frameworks/base/docs"/>
<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$/cts"/>
<excludeFolder url="file://$MODULE_DIR$/dalvik"/>
<excludeFolder url="file://$MODULE_DIR$/developers"/>
<excludeFolder url="file://$MODULE_DIR$/development"/>
<excludeFolder url="file://$MODULE_DIR$/device"/>
<excludeFolder url="file://$MODULE_DIR$/docs"/>
<excludeFolder url="file://$MODULE_DIR$/external"/>
<excludeFolder url="file://$MODULE_DIR$/hardware"/>
<excludeFolder url="file://$MODULE_DIR$/kernel-3.18"/>
<excludeFolder url="file://$MODULE_DIR$/libcore"/>
<excludeFolder url="file://$MODULE_DIR$/libnativehelper"/>
<excludeFolder url="file://$MODULE_DIR$/ndk"/>
<excludeFolder url="file://$MODULE_DIR$/out"/>
<excludeFolder url="file://$MODULE_DIR$/pdk"/>
<excludeFolder url="file://$MODULE_DIR$/platform_testing"/>
<excludeFolder url="file://$MODULE_DIR$/prebuilts"/>
<excludeFolder url="file://$MODULE_DIR$/rc_projects"/>
<excludeFolder url="file://$MODULE_DIR$/sdk"/>
<excludeFolder url="file://$MODULE_DIR$/system"/>
<excludeFolder url="file://$MODULE_DIR$/tools"/>
<excludeFolder url="file://$MODULE_DIR$/trusty"/>
<excludeFolder url="file://$MODULE_DIR$/vendor"/>

这样我们就只导入了frameworks和packages的代码。

导入

打开android.ipr

启动时打开

在这里插入图片描述

open existing project
在这里插入图片描述
弹出路径选择框,输入相应的源码根路径,然后选择android.ipr文件,就开始导入源码啦。在导入过程中,需要等待索引的建立相关的关联,大概需要花10~20分钟。

配置差的大概会花1个小时甚至卡死


Hr(Hancher 瀚澈)
创建:2021年5月28日
修改:2021年5月28日
Hr的Android开发目录



所属网站分类: 技术文章 > 博客

作者:听说你没有见过我

链接:http://www.javaheidong.com/blog/article/207799/6263a30e7a7082736d04/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

20 0
收藏该文
已收藏

评论内容:(最多支持255个字符)