Manually import Eclipse Project in Android Studio
RT. This should be the biggest problem many friends have encountered after switching from Eclipse to Android Studio. First, we need to re-understand the directory structure in, as mentioned in my previous post (projects in Android Studio are equivalent to Workspace in Eclipse, while modules are equivalent to projects in Eclipse ).
Therefore, manually import the Project is actually the Module in the. You can perform the following steps:
1. Copy build. gradle to the project to be imported.
2. Copy the Project you want to import to the AS Project root directory folder (that is, the folder that contains gradlew, gradlew. bat,. gradle)
3. Modify settings. gradle in the as Project and add include. This tells the AS Project to include this Module (for example, include ': SlidingMenuLibrary ')
4. Rebuild Project, the. iml file will be automatically generated for the project (the iml file is the configuration file for the AS recognition Project, which is similar to the. project file in Eclipse)
The main content of build. gradle is shown below:
apply plugin: 'com.android.application'dependencies { compile fileTree(dir: 'libs', include: '*.jar')}android { compileSdkVersion 17 buildToolsVersion "20.0.0" sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] } // Move the tests to tests/java, tests/res, etc... instrumentTest.setRoot('tests') // Move the build types to build-types/
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... // This moves them out of them default location under src/
/... which would // conflict with src/ being used by the main source set. // Adding new build types or product flavors should be accompanied // by a similar customization. debug.setRoot('build-types/debug') release.setRoot('build-types/release') }}
In fact, the above file is exported using Eclipse, and you can copy it directly with confidence. Pay attention to the following points:
1. the gradle file of the App is provided above. If it is a Library project, you need to modify apply plugin: 'com. android. application 'is apply plugin: 'com. android. library '.
2. compileSdkVersion and buildToolsVersion must be modified according to the local SDK version. Open the SDK Manager and check the version.
3. sourceSets main specifies the directory location of the source code, because the default AS code structure is different from that of Eclipse.
4. dependencies specifies the dependent libraries. compile fileTree (dir: 'libs', include: ['*. jar']) compiles all. jar libraries in the libs directory. If you are dependent on some library projects, you can add: compile project (': Cordova ')
Conclusion: in fact, the latest version of AS already supports direct Module import. However, when importing, copy a Copy of your project (equivalent to a new Copy), and then the imported directory structure becomes the AS directory structure. if you want to maintain the Eclipse directory structure, use the above method.