怎么导入源码到游戏中心-使用 Android Studio 导出源代码

1 背景

我上路了,我要继续我五年的事业了。 我很遗憾在以前的公司做Amlogic和Realtak解决方案包时没有养成写博客的习惯。 。 话不多说,本文只是工具讲解。

关于Android Studio进行应用层App开发的方法和配置,我写了一篇文章来分析。 这里我就不解释了。 详细内容请参见我的博文《Android Studio入门到精通》。 这里我们主要讲解的是使用它,看源码的相关配置(本例是根据官方源码android-5.1.1_r14进行配置说明)。

以前在上一家公司检查修改源码的时候都是用Eclipse导出部分代码的,但是现在在android源码中发现了一个development/tools/idegen目录。 我查了一下,发现是生成IDE的工程文件(主要是intellij的工程文件,其实是Android Studio的),福利工具就是这么来的。 欲了解更多详情,请参阅下文。

2 配置及使用流程 2-1 基础规划工作

首先,您必须安装并配置Android Studio。 详细内容请参考《Android Studio入门到精通》。

然后你必须下载源代码。 至于如何下载,这里就不解释了。 比较简单怎么导入源码到游戏中心,去官网查一下就可以了。

其次,需要确保源代码已经编译生成了相关的目录文件。

好了,以上是一些基本的规划任务。 对于自定义源代码或原生源代码,这些规划步骤是必要的,因此无需指出。

怎么导入源码到游戏中心-使用 Android Studio 导出源代码

2-2 配置导出及使用 2-2-1 编译源码idegen模块,生成AS配置文件(*.ipr)

在开始编译idegen模块之前,必须知道需要先全局编译out目录及相关文件。 关于这一点我不会说太多。 我们使用以下命令编译 idegen 模块:

mmm development/tools/idegen/

这行命令的含义是编译idegen模块项目,然后生成idegen.jar文件(不信你去查看这个模块的Android.mk目标,不再解释)。 运行后,如果看到如下信息,则说明编译成功:

......
#### make completed successfully (7 seconds) ####

然后执行以下脚本:

development/tools/idegen/idegen.sh

该命令的意思是在根目录下生成相应的android.ipr、android.iml IEDA工程配置文件。 等待一段时间,出现类似如下的提示信息,表示OK:

Read excludes: 21ms
Traversed tree: 194799ms

通过以上操作,我们就完成了基本的源码配置工作。

2-2-2 导入Android Studio前的一些定制操作

大家都知道用Eclipse放入源码很慢,而且从Android Studio导出源码也很慢,所以建议改android.iml文件(去掉你不使用的代码)使用),然后导出到Studio。

就像下面提取的 android.iml 文件的第 1887 行开始的内容一样:

<sourceFolder url="file://$MODULE_DIR$/./sdk/testapps/userLibTest/src" isTestSource="true"/>
<sourceFolder url="file://$MODULE_DIR$/./tools/external/fat32lib/src/main/java" isTestSource="false"/>
<excludeFolder url="file://$MODULE_DIR$/out/eclipse"/>
<excludeFolder url="file://$MODULE_DIR$/.repo"/>
<excludeFolder url="file://$MODULE_DIR$/external/bluetooth"/>
<excludeFolder url="file://$MODULE_DIR$/external/chromium"/>
<excludeFolder url="file://$MODULE_DIR$/external/icu4c"/>
<excludeFolder url="file://$MODULE_DIR$/external/webkit"/>
<excludeFolder url="file://$MODULE_DIR$/frameworks/base/docs"/>
<excludeFolder url="file://$MODULE_DIR$/out/host"/>
<excludeFolder url="file://$MODULE_DIR$/out/target/common/docs"/>
<excludeFolder url="file://$MODULE_DIR$/out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates"/>
<excludeFolder url="file://$MODULE_DIR$/out/target/product"/>
<excludeFolder url="file://$MODULE_DIR$/prebuilt"/>

我们可以在里面模仿这段代码的写法怎么导入源码到游戏中心,过滤掉不需要的内容,这样导出会快很多。

也可以通过Android Studio的Project Structure打开右边的Modules,然后排除两边的Sources中的一些目录。

2-2-3 使用Android Studio导出源码项目

完成以上操作后,我们打开Android Studio,然后选择打开一个已有的Android Studio项目,然后选择打开源码根目录下的android.ipr文件,然后就会有如图这样的索引,只需等待导出:tu

至此我们就可以轻松的使用Android Studio查看源码了。 如下所示:

挂不了啊! ! !

2-3 使用方法

如上图所示,我们可以通过Android Studio搜索整套源码。 但此时如果你打开一个Service.java类,然后将键盘放在其中任意一个Intent参数上,按住CTRL+鼠标左键跳转到Intent类,你会发现跳转的是一个Intent。类文件,有什么用? 因为他跳转到了你默认的SDK中jar里面的class文件。 由于我们要更改和查看整套源代码,跳转到的内容太多,所以我们需要配置它跳转到Intent.java文件。 具体方法如下:

首先删除dependency中的所有依赖,只保留下图中没有选中的两个(当然你可以选择保留一些你使用的其他jar),如下:

然后单击 JAR 或目录的减号来添加源代码的框架和外部以及您使用的其他跳转目录到依赖项,然后应用。

这时候我们像之前一样打开Service.java跳转到Intent,你会发现直接跳转到了你的源码路径下的Intent.java文件如右图,如下:

这对于那些平时只看源码的人来说已经足够了。

3 总结

俗话说,工欲善其事,必先利其器。 你会发现使用Android Studio比Eclipse和Source Insight要好很多(当然SubText还是很强大的),无论是代码提示还是跳转,还是Python Shell等插件支持等等都非常强大,慢慢体会吧。

顺便说一句,谷歌的野心确实很大。 看来Android Studio将被他们正式塑造为一个全能的IDE。

4 附加自述文件

附上英文原版README文档,英文高手可以看这里:

IDEGen 自动为 IntelliJ IDEA 生成 Android IDE 配置

和日食。 您的 IDE 应该能够以合理的方式编译所有内容

没有错误的时间量。

如果您使用 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.

如果您使用 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).

排除源根和 jar

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)".

控制源根排序 (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/").

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悟空资源网 游戏源码 怎么导入源码到游戏中心-使用 Android Studio 导出源代码 https://www.wkzy.net/game/163594.html

常见问题

相关文章

官方客服团队

为您解决烦忧 - 24小时在线 专业服务