美文网首页
2.2 将已有Eclipse ADT项目导入Android St

2.2 将已有Eclipse ADT项目导入Android St

作者: GuoYiheng | 来源:发表于2017-02-10 22:19 被阅读0次

    打开Android Studio,在欢迎界面可以看到有一条选项Import project(Eclipse ADT,Gradle,etc.),如G 1.

    G 1
    选中后就可以从打开的窗口选择想要导入的项目.可以看到res,srcAndroidManifest.xml都在项目的根目录,很显然,这是一个Eclipse工程: G 2

    然后再指定要导入到的路径,会提示将lib文件夹下的jar包添加到Gradle文件的dependencies里:

    G 3

    然后Android Studio会开始重组并构建工程,重构结束后默认打开一个importsummary.txt文件,告知我们重构后主要有哪些改变:

    ECLIPSE ANDROID PROJECT IMPORT SUMMARY
    ======================================
    
    Ignored Files:
    --------------
    The following files were *not* copied into the new Gradle project; you
    should evaluate whether these are still needed in your project and if
    so manually move them:
    
    * .gitignore
    * LICENSE.txt
    * README.md
    * proguard.cfg
    
    Moved Files:
    ------------
    Android Gradle projects use a different directory structure than ADT
    Eclipse projects. Here's how the projects were restructured:
    
    * AndroidManifest.xml => app\src\main\AndroidManifest.xml
    * libs\commons-httpclient-3.1.jar => app\libs\commons-httpclient-3.1.jar
    * res\ => app\src\main\res\
    * src\ => app\src\main\java\
    
    Next Steps:
    -----------
    You can now build the project. The Gradle project needs network
    connectivity to download dependencies.
    
    Bugs:
    -----
    If for some reason your project does not build, and you determine that
    it is due to a bug or limitation of the Eclipse to Gradle importer,
    please file a bug at http://b.android.com with category
    Component-Tools.
    
    (This import summary is for your information only, and can be deleted
    after import once you are satisfied with the results.)
    

    在生成的settings.gradle文件里会显示

    include ':app'
    

    说明app工程是项目里唯一的模块.
    需要注意的是,在整个重构过程中,清单文件并没有改变:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="net.oschina.app"
              android:versionCode="13"
              android:versionName="1.7.0">
    
        <uses-sdk android:minSdkVersion="4"/>
    
        <application
            android:name=".AppContext"
            android:icon="@drawable/icon"
            android:label="@string/app_name">
          <!--限于篇幅,内容省略-->
     
        </application>
        <!--限于篇幅,内容省略-->
    </manifest>
    

    既然我们已经将工程重构为了Android Studio工程,所以最好还是将清单文件内容改为Android Studio默认的格式,将uses-sdk内容写到build.gradle文件里.

    相关文章

      网友评论

          本文标题:2.2 将已有Eclipse ADT项目导入Android St

          本文链接:https://www.haomeiwen.com/subject/oscnittx.html