Goodbye to Eclipse, Android Studio Beginner Tutorial (ii) Project import

Source: Internet
Author: User

The previous blog introduces some of the common settings for as, and when the tools are properly tuned, it is natural to start the development of the project. To create a new project from scratch, this simple, needless to say, this blog will share my process of importing projects from the old platform eclipse into the AS, as well as some problems encountered and how to solve them. Let's start by taking a rough look at some of the areas that need attention.

Structure Catalog

Unlike eclipse, the project directory under Android View is divided into java,res and manifests.

    • The manifests directory holds the manifest file, needless to say.
    • The Java directory generates three folders by default, where test is the directory where unit test code is executed natively, Androidtest is the directory where the unit test code is executed on Android devices, and the first directory without a suffix is the directory where our code is stored.
    • The Res directory holds resource files, including picture resource files, layout layouts, and so on, and this is similar to Eclispe, but there is a new thing: Mipmap directory, which will see the launch icon that contains the app. Check out the official documentation and see the following sentence:

To avoid these display issues, apps should with the Mipmap/resource folders for launcher icons. The Android system preserves these resources regardless of density stripping, and ensures that launcher apps can pick icon s with the best resolution for display.
Source: Http://developer.android.com/tools/projects/index.html#mipmap

To avoid device display problems, the app should use the Mipmap directory to store app icons. So the app's launch icon should be placed in the Mipmap folder, but the other uses are not very clear, You've also encountered an import Eclipse project before. 9 Picture error, someone on the network said. 9 figure should be put in the mipmap, but I put the. 9 picture in the Mipmap directory still does not solve my problem, and finally because the project. 9 The diagram is not much, and the tool that uses as is redrawn and resolves the problem.

Library dependencies

How to add the presence of a local third-party library in eclipse:
-Import a third-party library into workspace
-Right-click Project-android-add Library

How to add libraries in as:
-Import third-party library projects to project, third-party libraries as a new module in project
-File-project structure, select project, add Library

By contrast, project in as is equivalent to the concept of workspace in Eclipse, which is equivalent to a separate project in Eclipse. It can also be found that the two are similar to the operation of relying on the local third-party library, adding the jar package is the same, as long as the jar package is copied into the Lib directory (switch to the project files view will see the Lib directory), and then the same operation project Structure, select File dependency and choose to rely on the jar package just added under Lib library.
But if it is added online open Source Library, the gap between the two is reflected in the past on GitHub to see the excellent open Source library, want to apply to their own projects, you have to download the project, and then add dependencies, although the operation is not cumbersome, But I have come to realize that more and more developers on GitHub are turning to as, no longer providing the version that is used on eclipse alone. This does not repeat, because want to turn platform, can see this blog friend, certainly more or less have some sympathy. In a word:Google Dafa is good . Go back to eclipse and keep it safe.

First knowledge of Gradle

In the Android View Gradle directory, you can see that there are multiple build.gradle, where the suffix module + project name is usually added to the third-party library to configure the Gradle file, With this open source Library on GitHub as an example, there's a piece of code on the GitHub home page: Circleimageview

The only thing we have to do is copy this code to the Gradle-dependencies statement block of the project.

Then click the toolbar icon

After that Gradle will automatically download the library from the remote repository of the necessary jar packages and other dependent files, a key to do, it is not too cool!
However, Gradle is cool, but the follow-up will also mention some of the problems that arise when importing items because of the Gradle version.

Import Eclipse Project

It says how to rely on the library, but some friends need to develop old projects instead of new ones, light into Eclipse project times the mistake is enough to drink a pot, not to mention how to properly rely on the library, so next to demonstrate how to properly import Eclipse project. Different projects will appear the problem is not the same, here right vote is a point, to give you some ideas to solve the problem.
First, in Eclipse, right--export, export the project's Gradle directory

Select the project you want to export, all the way next, the last step is to suggest the force overriding a column tick (I understand that there is already a Gradle file, the selected words will be forced to rewrite), the export will appear after successful prompt:

Please select the following directory: ... build.gradle, do not import the Eclipse project itself!

I don't know, anyway, I was following this hint. In the as in the import directory of the Build.gradle file, and then the results of the entire working directory of the project are imported (╯‵-′) ╯︵┻━┻.
What the heck! I must have opened the wrong way! And then tried in as.

Import is successful only if you select the project itself instead of the Build.gradle file.
But don't be happy too early, it's just the beginning of trouble.

Issue 1 class not found

Workaround: Can not find the related class, navigate to the code, found to be recyclerview some of the class error, so guess is because of dependencies, in the project depends on the library to add Recyclerview library, problem solving!

Issue 2 Library recurring dependencies

You can see in the error prompt that there are multiple libraries with the same name, because I brought the SupportV7 Recyclerview library when I exported the project from eclipse, and I have just added a new Recyclerview library, so it's a simple solution, Remove the Recyclerview dependencies before, solve the problem!

Issue 3 Manifest file Merge error Manifest merger failed

The whole error message is this:

Java.lang.RuntimeException:Manifest merger Failed:uses-sdk:minsdkversion 1 cannot be smaller than version 7 declared in library [com.android.support:appcompat-v7:23.2.1] D:\studioCode\NewOneBuy\lib_CircleImageView\build\ Intermediates\exploded-aar\com.android.support\appcompat-v7\23.2.1\androidmanifest.xml
Suggestion:use tools:overridelibrary= "Android.support.v7.appcompat" to force usage

It can be seen that the manifest file merge error caused by Circleimageview's minsdkversion is lower than the version defined by AppcompatV7, and the hints tell us the workaround Just configure it in the Circleimageview manifest file.

Issue 4 package does not exist

This problem is also simple, navigate to the relevant code, use the shortcut key: Ctrl+alt+o, remove Invalid guide package.

Issue 5 Duplicate files (jar package) Duplicate files

The message also indicates that in File1,file2 two different libraries contain the same file (Jar package) export error, in the Prodect view of the Lib directory, you can see that there are indeed duplicate files

Solving the problem is also simple: Remove the jar package and remove the dependencies

Question 6 finished with Non-zero exit value 2
  • What went wrong:
    Execution failed for task ': Newonebuy:transformclasseswithdexfordebug '.
    Com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException: Java.util.concurrent.ExecutionException:com.android.ide.common.process.ProcessException: Org.gradle.process.internal.ExecException:Process ' command ' C:\Program Files (x86) \java\jdk1.8.0_60\bin\java.exe " Finished with Non-zero exit value 2

This does not understand the cause of the error, but finally through the project module in the Build.gradle to fix the problem, but I do not know why.

 defaultConfig {        "com.example.newonebuy"        11        21        true    }

In fact, before the introduction, looking at a row and a line of red error in my heart is collapsed, but in fact, as long as the patience of the prompt according to the tips of the troubleshooting, encountered do not understand on Google, after all, this is only a few very basic problems, will always be resolved. Recent life in a lot of trouble, in code code when gradually can feel a very strange feelings, in the code of the world, 1 is 1,0 is 0, as long as you are willing to pay the effort, mistakes will always disappear, the bug will always repair, and unlike the real world, many things people difficult to test, even if the hearts of the heart can be measured, There are times when you feel deeply powerless and helpless.
No more nonsense, this is the first to share. The next blog will share some of the things that are versioned with GitHub on as, and some of the issues that are caused by the Gradle version when you import the module. Also recently saw Kotlin this emerging language seems quite interesting, wait until the next project to try to see if Kotlin can efficiently and effectively solve some problems, if there are any gains, there are also written to share. There is a point of hot hair a light, write the article as long as there is a person to see, solve a person's problem, the article has value. Even if no one is looking, then write to yourself as a summary of what you think you are learning.
But do good deeds, do not ask the future. May the world be peace, and may someone rejoice and be safe.

Goodbye to Eclipse, Android Studio Beginner Tutorial (ii) Project import

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.