Saturday, May 23, 2015

Android Studio Overview and Migrating from Eclipse Projects


Android studio is a Android focused official IDE designed specifically for Android development, similar to eclipse with the ADT plugin. Contains all the Android SDK Tools to design, test, debug, and profile your app. On top of the capabilities you expect from IntelliJ, Android Studio offers:



  • Powerful code editing (Smart editing, code refactoring)
  • Rich Layout editor
  • Gradle-based build support
  • Maven support
  • Template based wizards
  • Lint tool analysis
  • Easy access to Google service like GCM


  • Android development environment built on intelliJ IDEA

      Android build system overview

      The Android build system is the toolkit you use to build, test, run and package your apps. The build system can run as an integrated tool from the Android Studio menu and independently from the command line. You can use the features of the build system to:
      • Customize, configure, and extend the build process.
      • Create multiple APKs for your app with different features using the same project and modules.
      • Reuse code and resources across source sets.


      The general process for a typical build is outlined below. The build system merges all the resources from the configured product flavors, build types, and dependencies. If different folders contain resources with the same name or setting, the following override priority order is: dependencies override build types, which override product flavors, which override the main source directory.
         The Android Asset Packaging Tool (aapt) takes your application resource files, such as the AndroidManifest.xml file and the XML files for your Activities, and compiles them. An R.java is also produced so you can reference your resources from your Java code.
         The aidl tool converts any .aidl interfaces that you have into Java interfaces.
         All of your Java code, including the R.java and .aidl files, are compiled by the Java compiler and .class files are output.
         The dex tool converts the .class files to Dalvik byte code. Any 3rd party libraries and .class files that you have included in your module build are also converted into .dex files so that they can be packaged into the final .apk file.
         All non-compiled resources (such as images), compiled resources, and the .dex files are sent to the apkbuilder tool to be packaged into an .apk file.
         Once the .apk is built, it must be signed with either a debug or release key before it can be installed to a device.
         Finally, if the application is being signed in release mode, you must align the .apk with the zipalign tool. Aligning the final.apk decreases memory usage when the application is -running on a device.


      Dependency Managment overview
      1. Ant -  Apache Ant is a Java based build tool from Apache Software Foundation. Apache Ant's build files are written in XML and they take advantage of being open standard, portable and easy to understand. Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications. Ant supplies a number of built-in tasks allowing to compile, assemble, test and run Java applications. Ant can also be used effectively to build non Java applications, for instance C or C++ applications. More generally, Ant can be used to pilot any type of process which can be described in terms of targets and tasks. 

      2. Maven - Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information. Maven’s primary goal is to allow a developer to comprehend the complete state of a development effort in the shortest period of time. In order to attain this goal there are several areas of concern that Maven attempts to deal with:
           Making the build process easy
           Providing a uniform build system
           Providing quality project information
           Providing guidelines for best practices development
           Allowing transparent migration to new features
      3.  Gradle - Gradle is the next evolutionary step in JVM-based build tools. It draws on lessons learned from established tools such as Ant and Maven and takes their best ideas to the next level. Following a build-by-convention approach, Gradle allows for declaratively modeling your problem domain using a powerful and expressive domain-specific language (DSL) implemented in Groovy instead of XML. Because Gradle is a JVM native, it allows you to write custom logic in the language you're most comfortable with, be it Java or Groovy.
      Features & Benefits of Gradle
      1. Dependency Management – Flexible approach to dependency management that can reuse existing maven respositories or reference local jars.
      2. Gradle is a advanced build management system based on Groovy
      3. Its an open source build system
      4.  Combines the power of Ant and Maven
      5. Product flavors – Free and Paid versions
      6. Build Type – Debug, QA, release
      7. Binary bundles for libraries (.aar) – Gradle supports the new .aar binary bundle format for the library projects.


      Migrating From Eclipse Projects
      To migrate an Eclipse project to an Android Studio project, you have two options:
      • Importing the Eclipse project directly into Studio. This is the preferred approach, and has numerous advantages:
        • It will detect many source libraries (such as ActionBarSherlock) and binary libraries (e.g. guava.jar), and will replace these with maven dependencies instead, which means you no longer have to maintain the libraries manually
        • It will rewrite the project using the new canonical Android Gradle project structure, which supports instrumentation tests in the same project as the tested code, flavor and build type specific resources, etc

      • Exporting the Eclipse project from Eclipse as a Gradle project. This mechanism is not as flexible (or frequently updated) as the direct Gradle import, but it has two usages:
        • It will let you keep your Gradle project using the same file structure as Eclipse ADT projects (in other words, it does not move files around; everything is kept in place, and a special build.gradle file tells Gradle to look for sources in the old directory structure rather than the new one). This is useful if you want to continue working with both Studio and Eclipse on the same codebase.
        • If your project is doing a lot of Eclipse-specific directory mappings (with path variables, linked resources etc) it's possible that the Android Studio importer can not resolve the paths properly; in that case, try the Eclipse exporter (but please also file a bug so we can fix the importer).
      Importing Directly into Android Studio
      To import into Android Studio, select File > Import, and then select the directory containing your Eclipse ADT project. A wizard will open and guide you through the rest of the import process. When the project import has finished, it will open up a file called "import-summary.txt" which lists all the steps taken during import and suggestions for next steps. For example, it may note files that were not migrated, it may note missing components in your SDK install, and so on.
      Exporting from Eclipse
      Open the project in Eclipse, and from there, export the project. 

      Choose the Gradle option
      Proceed through the wizard. When you are done, you can import the build.gradle file into Android Studio.

      0 comments:

      Post a Comment