Androidstudio Compiling project Summary

Source: Internet
Author: User

Or the story of the background, the company has a product, back and forth has three versions, is based on the project structure of Eclipse, with the change in demand, product development, the whole project has become very large, there were five or six library projects, engineering references to the third-party jar will not say, There are ten or twenty of them. Since this product was originally developed based on Xamarin and was using C # as the base language, there were various reasons for the project to use the uppercase package name, in fact, the capitalization package name did not have any explosive problem on eclipse, but wait until one day I want to transplant this project to Androidstudio , there is a fatal problem, Android Studio does not support uppercase package name, so can only give up, at least in my blog at this point in time, Android Studio is unable to support uppercase package name, can be compiled successfully, but not run on the device. Of course, these are off-topic, not important. But to remind you that, remember Kazakhstan, Android Studio does not support the capitalization of the name of the package (oh, this is only a few wonderful cases that someone will do it).

The question comes, one day the company new business line, also need to do products, because before that engineering function or relatively strong, so want to develop a product based on the existing project, Haha, what a good time, so you can put the previous project change package name to the Android Stduio, The problem is with it, let me compile two days before the project compiled successfully, my mother, eyes almost with me blind, the following is the question I encountered.

1. The app project cannot use the remote dependent object of local AAR

I did not say that the company has five or six library projects, because of the project too many, and mostly some of the tool library, some of the package of things, usually not how to change, so I would like to put them into a jar package file (with resources packaged into AAR), packaging the project will not say anything, Then I referred the package AAR to the project and found that some of the resources in the remote dependency of the AAR could not be accessed, for example, I have a Librarya project, Packaged as a a.aar, this remote relies on retrofit, and then a manager class returns a retrofit object, but I find that the app simply doesn't know the existence of retrofit, which means the app project simply can't access the retrofit object. After several setbacks, I stumbled across that the resource referenced in the jar package in A.aar was accessible, so I switched all the remote dependencies to the jar or AAR files placed in the Libs directory, and then packaged them, and at this point the project would be able to access the resources that the Librarya project relied on.

But to be honest, this kind of solution is really disgusting, but also added restrictions on the subsequent project reference jar, as well as jar upgrade, these are all problems. Later I find information on the Internet, find an article, of course, another way to solve, but this way is still there is the previous said to rely on the upgrade of the nausea, but this is a small problem, you need to upgrade, then package the compilation can, also not much of the matter.

Another way to solve the problem is: http://m.blog.csdn.net/article/details?id=50608677 Other people's way is really more advanced than I found the way, and others also illustrated, I defeated.

2. Duplicate reference of JAR package

  When you come across keywords like "transformclasseswithjarmergingfordebug", "Duplicate entry", congratulations, you can almost certainly see a duplicate reference to the jar package.

If in a relatively simple engineering relationship, this problem is still relatively good to solve some, after all, the project structure is clear, not dazzling, people around dizzy, but also will appear more difficult to find the situation, below I say I am in the conversion project is encountered in some cases.

1), different versions of the JAR package reference: The simplest and easiest to find, that is, different projects refer to different versions of the same jar package, such as a reference to Okhttp 1.0, a reference okhttp2.0, this situation is definitely to delete one, even eclipse will not let you compile through. Then you may want me, I delete the jar bag project how to do? He doesn't have this jar reference. Ah, there are two cases, the first, such as you A and B two projects each refer to two different versions of the jar package, and B depends on a project, this time, let a to rely on the jar package, b delete the jar package, other do not handle, because it is like a reference to pass, You depend on me and you don't have to rely on it.

2), remote dependent with the local jar package version is different: This is more complicated, such as my project itself relies on the Okhttp-2.4 version of the jar package, the main solution file upload download, go to Android Stduio I want to switch to retrofit as a network request, This time there is a duplicate reference when running, because retrofit2.0 default reference okhttp3.0, so this situation you know your remote dependency of some information, it is better for you to solve the problem (of course, there is a log will be prompted to repeat the definition, this time according to the prompt to solve).

3), the same version of the jar package multiple copies: What this means, this means that the same file, you put in A and B in the Lib directory, and each reference, this situation will also be problematic. But incidentally, this is not a problem with eclipse, that is, in eclipse, you put the same jar file copy multiple copies in different projects, compile and run no problem, but Android Stduio not. How to solve this, of course, the previous 1) The problem also provides some solutions, it is necessary to clean out only one, and then confused, because there may be some items do not have a referential relationship, that is, A and B projects do not have dependencies, but because only one jar file, there must be a no, this time there are two ways, Of course the principle is the same, is to delete one, let another project to refer to another project inside the file, this specific how to write, I also lazy to write code, also a word, because this is not the usual practice, the general practice is to put the project referenced jar in a common directory, You can usually choose to be the Libs directory under Project Root, and then let the other projects refer to this, which avoids the case of multiple copies of the same jar.

4), seems to have encountered the above situation ...

3, the project more than 65536 limit the number of methods

This problem arises when I add retrofit to the network framework of the project, and the solution to this problem is solved by a lot of Internet.

But here's a note: If your project contains multiple module, then each module must support adding multidexenabled true to the project's build file, otherwise you might encounter an exception such as XX cannot merge in the compilation. Approximately the following configuration

     Defaultconfig {        ...        enabling Multidex support.        multidexenabled true    

  

3, library module project can not use their own project resource file exception

This problem really made me crazy for a long time, until now, is a library module project has some custom controls and uses some of the picture resources that the project itself contains. The build passed, and it ran normally on the phone, and it might crash when you use the custom control. After debugging in the use of R.drawable.xxx place appeared classnotfoundexception, really, I confused forced, Super crazy, for two days in a row has been plagued by this problem, because I have a project, the project structure is very similar to this, but he runs without problems.

Before I was a classmate, said let me try to improve the version of Gradle, to tell the truth, Android Stduio project management, I really do not know, later in his guidance, I replaced the version, Change from 2.4 to 2.10, to tell the truth, after the replacement even compile did not pass, but I vaguely feel saved, why, in 2.4 at least can compile and run, and now even compile do not pass, how can I still feel saved, intuition, then I also see those error message, are some jar package repeated reference problem, gee, Odd Strange, the front is not Solve some of the repeated reference problems, how to jump out of such a problem at the moment, this Nima what ghost, I look carefully, and before the same, OK, there are problems to solve the problem, follow the previous steps, once again, in my writing the article record time (because it is the project compile the problem, we all know, Repeated synchronization of the project, Clean,rebuild these operations, is quite time-consuming, and need to wait a lot of time, so I think should write something to record the problem before it, at this time, all problems solved, compile, run, do not, problem, my days, Everything is OK. It seems that you can have a safe meal tonight.

To this a huge structure of projects moved from Eclipse to Android studio in normal compile run, whirring.

Wait for the back time to paste the detailed questions and procedures.

Androidstudio Compiling project Summary

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.