Gradle's pitfalls

Source: Internet
Author: User

It's amazing to use Android studio. Now, let me use eclipse to kill people!

However, there are still a few users, so there are not many solutions to some problems in the project, or even none. I plan to record some of my experiences.

Bytes --------------------------------------------------------------------------------------------------------------

1. Android studio does not support jar packaging, so the problem we encountered before connecting to unity was that the project written in Android studio had to be transferred to eclipse for packaging (a bit silly ), later, I found that the app \ build \ intermediates \ Classes directory contains all compiled bytecode files, so ...... Direct command

jar -cvf xxx.jar *

Isn't it? Then, it should be noted that android Studio also compiled the r class bytecode file, when connecting to unity, there will be bugs caused by inconsistent resource IDs generated by Android studio and unity. Therefore, you can delete these R-related bugs. When talking about resources,

 

Ii. solutions to problems that lead to resource disorder in Unity's connection with Android (although it is not related to gradle, it is a problem that I encountered step by step in practice. I should write it together)

As mentioned above, when we use R. Id. xxx, it is actually an ID automatically generated by the ADT. We reference this ID system to help us find this resource. Therefore, when interfacing with unity, the officially recommended method is to place the res folder together in the android path, that is, unity is responsible for re-allocating the resource ID, in this way, the ID reference in our static Code may not be the resource we need, so the solution is not to use static R. id. xxx can be used to obtain resources

// String DESC = res. getstring (R. id. description); // string DESC = res. getstring (res. getidentifier ("Description", "string", "com. mycompany. myApp "));

In this way, the corresponding resources are dynamically obtained. OK, and the problem is solved.

 

3. Unity is still faulty. For example, the ondraw running in a custom view in my project is incorrect. After the connection, no reason can be found, so I want unity to be responsible for packaging for Mao? Later, I accidentally found that the Google Android project option was available in build setting during packaging. I didn't expect unity to directly export the android project, in this case, you can reference your project as the project exported by unity from LIB or reference unity Lib in my android project, of course, in my attempt, the latter is successfully packaged and run, which is also the method I have been using now, that is, the project exported by unity can be imported as a library project, then you can reference this library project in your android project. There are a lot of operations on the Internet and Google on your own, but one problem is that the library method may include: APP: dexdebug error, that is, a problem occurs during jar packaging, later, it was found that both the project and the Library had to reference the same jar (the Android-related tool provided by unity), so the solution was to block a jar,

configurations {    all*.exclude jar: ‘libs/classes.jar‘}

Add this section to build. gradle in your android project. (Not familiar with gradle syntax, which is a big pitfall for me)

 

Iv. Recommended unity Android packaging method

It is recommended that many resources be involved! In addition, debug can be performed on the android side. After unity exports the android project, it will copy the assests directly to src/main (Android studio ), then place the jar referenced in the Unity project into the Libs of assests, and create a jnilibs folder in main, copy the entire libs/armeabi-x folder of the Unity exported project. In this way, there will be no problem, and then how to connect to it is the same as other ones.

 

5. Unity is full of traps. The title should be changed to some pitfalls encountered by unity.

Gradle's pitfalls

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.