Use Android Studio to import source code

Source: Internet
Author: User

Use Android Studio to import source code
1. Background

When I got on the road, I was about to start focusing on the old business of those two years. I regret that I didn't develop the habit of writing a blog when I used the Amlogic and Realtak solution boxes in my previous company, this is also a question for a netizen. Not to mention, this article is just a tool explanation.

I have written an article on the skills and configurations of Android Studio for App development at the application layer. I will not explain them here. For details, refer to my blog titled "getting started with Android Studio". Here we mainly explain is to use it to view the relevant configuration of the source code (the instance according to the official source code android-5.1.1_r14 for configuration instructions ).

In the past, I used Eclipse to import part of the code when checking and modifying the source code in my previous company. Now I found a development/tools/idegen directory in the android source code, I found that the IDE project file is generated (mainly the intellij project file, which is actually the Android Studio file), so the welfare tool is here. For details, see the following.

2. Configuration and use process 2-1 Basic preparations

First, you have to install and configure Android Studio. For details, refer to "getting started with Android Studio".

Next, you have to download the source Code. As for how to download the Code, it is not described here. It is relatively simple. Just go to the official website and check it.

Second, you need to ensure that the source code has been compiled to generate out-related directory files.

Well, the above is some basic preparation work. For custom source code or native source code, these preparation steps are all necessary and do not need to be emphasized.

2-2 configure import and use 2-2-1 compile the source code idegen module and generate the AS configuration file (*. ipr)

Before you start to compile the idegen module, you must first compile the out directory and Related Files globally. Let's not talk too much about it. We will compile the idegen module using the following command:

mmm development/tools/idegen/

This command is used to compile the project of the idegen module and generate the idegen. jar file. (check the Android. mk target of this module without any explanation ). If the following information is displayed after running, the compilation is OK:

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

Run the following script:

development/tools/idegen/idegen.sh

This command generates the corresponding android. ipr and android. iml IEDA project configuration files in the root directory. Wait for a moment to get a description similar to the following: OK:

Read excludes: 21msTraversed tree: 194799ms

Through the above operations, we have completed the basic source code configuration.

2-2-2 custom operations before importing Android Studio

As we all know, importing the source code using Eclipse is slow, and importing the source code using Android Studio is slow. Therefore, we recommend that you modify the android. iml file (remove the code you don't need) and then import it to Studio.

Just like the android. iml file that is extracted from the following row 1887:


  
   
    
     
      
       
        
         
          
           
            
             
              
               
              
             
            
           
          
         
        
       
      
     
    
   
  

We can follow the above Code Filter out unwanted content in the same way, so that the import will be much faster.

You can also use the Project Stucture of Android Studio to open Modules on the left, and delete some directories in Sources on the right.

2-2-3 Use Android Studio to import the source code project

With these operations, we can open Android Studio, open an existing Android Studio project, and choose to open android under the root directory of the source code. ipr file, and then the same index appears, you can wait for the Import: tu

VcS/profiles = "write image description here" src = "http://www.bkjia.com/uploads/allimg/151012/0502514Z5-1.png" title = "\"/>

No !!!

2-3 tips

As we can see, we can search for the complete source code through Android Studio. However, if you open a Service. java class, and then place the mouse on the Intent parameter of any method, press CTRL + left mouse button to jump to the Intent class, you will find that the previous jump is an Intent. why? Because it redirects to the class file inside the jar in your default SDK. Since we need to modify and view the entire source code, it is a lot of effort to jump to the Intent. java file. The specific procedure is as follows:

First, delete all dependencies in the dependency, and retain only the two that are not selected (of course, you can choose to retain some other jar files you use), as shown below:

Click the JARs or directories in the plus sign to add your source code frameworks and external and other jump directories you use to the dependency, and then apply.

At this time, we open the Service. java jump Intent as above, and you will find that you directly jump to the Intent. java file in your source code path, as shown below:

At this point, it is enough for people who only view the source code.

3. Conclusion

As the saying goes, to do something better, you must first sharpen the tool. You will find that using Android Studio is much better than Eclipse and Source Insight (of course, SubText is still very powerful ), plug-ins such as code prompts, jumps, and Python Shell support are all very powerful. Please try it slowly.

By the way, Google's ambition is really great. It seems that Android Studio is about to be built as an all-around IDE by them.

4. Add README

The original English README document is attached. The English experts can simply read it here:

IDEGen automatically generates Android IDE deployments for IntelliJ IDEA
And Eclipse. Your IDE shocould 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 filehas one regular expression per line that matches paths (relative to theproject root) that should be excluded from the IDE configuration. Weuse Java's regular expression parser (see java.util.regex.Parser).You can create your own additional exclusion list by creating anexcluded-paths file in the project's root directory. For example, youmight exclude all apps except the Browser in your IDE configuration withthis regular expression: ^packages/apps/(?!Browser).

Controlling source root ordering (Eclipse)

You may want some source roots to come before others in Eclipse. Simplycreate a file named path-precedence in your project's root directory.Each line in the file is a regular expression that matches a source rootpath (relative to the project's root directory). If a given source root'spath matches a regular expression that comes earlier in the file, thatsource root will come earlier in the generated configuration. If a sourceroot 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 topof the path-precedence file.  To make source roots under ./out come last,add ^(?!out/) (which matches all paths that don't start with out/).

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.