Androidstudio how to introduce so package

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/aplixy/article/details/51592035

First of all, the prerequisites, my Androidstudio version is 2.2 Preview 3, the version is 2.1 students should also be the same.

Then let's conclude that some of your classmates may be rushing to do the project:

Conclusion:

The so package should be placed in the Jnilibs directory under the main directory in the SRC directory under the corresponding module (e.g. app module).

Note that it is jnilibs, the last side has an S, not jnilib, and L is capitalized. If you do not see the Jnilibs directory in the Src/main directory, then you only need to build a directory yourself, and then put your so package in the compilation platform classification copy into it. And then what? Then it's over, that's it, because the system will go to this directory to find the corresponding so package. As shown in the following:

The next interested students can understand why this is the case.

It may be said that the so package should be the same as the jar package, placed in the corresponding module libs directory, Eclipse is like this. Is it so simple? The answer is: NO

Principle:

In fact, in Androidstudio, we can put the jar package in the corresponding module libs directory, such as the app module (that is, the main project in the sense of the Libs) directory, And do not need to configure the Build.gradle file, you can use these jar, because the Androidstudio in the new project, the system has been configured in the default for us Gradle, if you look closely under the module Build.gradle file, there is usually a sentence:

Dependencies {    'libs', include: ['*.jar']}

See, this is to tell Gradle, our third-party jar package in the Libs directory, if there is no such line configuration, then theoretically we put the jar package directly in the Libs directory is actually not, but the new project when the system has been well-equipped for us. Here libs is a relative path, Because our Build.gradle file itself is in the app module, then here the Libs of course refers to the Libs under the app module, in fact, all the paths in the Build.gradle file can be written relative to the path, we talk about the path of so package is only write relative path on it.

OK, to get to the bottom, now know the introduction of the jar package principle, so why should so why put in such a strange directory? Can you put it in any custom directory? Of course it's possible.

In fact, in Build.gradle, there are some of these configurations by default:

Sourcesets {    main {        jnilibs.srcdirs = [' Src/main/jnilibs ']        aidl.srcdirs = [' Src/main/aidl ']    }}

These configuration after you create a new project, the default is not in the Build.gradle file, because the default is this, of course, do not write, of course, you write it right. So package go to src/main/jnilibs directory to find, Aidl file by default to Src/main/aidl directory to find ... Of course there are many other configurations, you can also configure where your Androidmanifest.xml file is, you can also configure where your Java code is, if you do not deserve a default value, here is just jnilibs and aidl for example.

See here you should understand, why we put so package directly in the SRC directory under the main directory of the Jinlibs directory can be, and do not need to configure Gradle file, because the system will be found in this directory by default, if you want to put so in a place you like, For example, in the Myjnilibs directory under the app directory, you only need to change the above content to:

Sourcesets {    main {        jnilibs.srcdirs = [' Myjnilibs ']        aidl.srcdirs = [' Src/main/aidl ']    }}

That's all you can do. Understand the principle, it seems that everything is clear, in the same vein, if you do not want to put the Aidl file in the default directory, You can also change the value of Aidl.srcdirs, if you do not want to put Java code in the default directory, you can change the value of Java.srcdirs, if you do not want to put the resource file in the default directory, you can change the value of res.srcdirs ... There are a few, students slowly to study it, if you want to change the directory structure with the project under Eclipse, the value of this can be changed, not one by one.

Androidstudio how to introduce so packages

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.