I looked at the general information in Android Developers here and previous questions in Stack Overflow here1 , here2 , here3 , and here4 .
I would like to create a new "utility library" that I can use from other projects, but there is something I don't understand. Here's what I do:
First, I start new project in Android Studio 2.2 (OS X 10.11):
Application name: Test
Package name: com.example.tomihasa.test
Minimum SDK: API 15: Android 4.0.3
Activity: Empty Activity
( ) Backwards Compatibility (AppCompat)
Second, I start a new library: File, New, New Module, Android Library
Application/Library name: MyLibrary
Package name: com.example.tomihasa.mylibrary
Minimum SDK: API 15: Android 4.0.3
I now have directories:
/Users/tomihasa/AndroidStudioProjects/Test
/Users/tomihasa/AndroidStudioProjects/Test/mylibrary
Why is mylibrary inside Test? Should it be somewhere else if I want to use it elsewhere? How can I move it?
Third, in settings.gradle I have:
include ':app', ':mylibrary'
Fourth, I build the MyLibrary:
Build, Make Module 'mylibrary'.
I can not find any .JAR or .AAR package as mentioned in here .
What am I missing?
You're creating a module
which is inside your Test
project. All your modules will be included here. The module itself should have its own build scripts and directories and can be used independent to the rest of the project if it doesn't have any dependencies of the other modules.
You can still use this module as a library in other projects if you want. Android Studio will create aar
files (debug and/or release) every time you build it and put it in your Test/myLibrary/build/outputs/aar/
folder. They should be named something like {module-name}-debug.aar
and {module-name}-release.aar
respectively. You can also upload the aar
to a local maven repository or use the aar
directly in other projects. If it doesn't appear, then you may need to do a clean project in Android Studio by going to Build->Clean Project
.
If you want to create a stand-alone library, you need to create a separate project. Then you have to import the built aar
in to your other projects using one of the methods above.
EDIT:
To install to local maven repository, first you need to include the mavenLocal()
repo in your build script.
Then in your library's build.gradle
file, you need to apply the maven
plugin:
apply plugin: 'com.android.library'
apply plugin: 'maven'
android {
...
task installArchives(type: Upload) {
description 'This task will upload the build to mavenLocal()'
repositories.mavenInstaller {
pom.version = '0.0.1'
pom.artifaceId = 'myLibrary'
pom.groupId = 'com.example.tomihasa'
}
}
}
In the gradle console, type ./gradlew build installArchives
to build and upload.
Then your projects can install it by including mavenLocal()
in to their build scripts and doing:
dependencies {
compile 'com.example.tomihasa:myLibrary:0.0.1'
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.