I have a library with all the source files inside of it. I need to compile this library into an .aar file, but I can't seem to import it into a module or project. There is no .idea folder within this library.
How can I create an .aar file out of this?
If the library is in your project with the source, then it is already compiled each time you run. Look under <your_lib> -> build -> outputs -> aar. There you will have an .aar for each build type you have. i.e. debug and release
It may be simplest to create a new AAR library module in Android Studio and then copy the source and resources for your library into the new module. To do this select File > New > New Module... > Android Library.
However, if you already have an Android project and you just want to alter the build to generate the project as an AAR library rather than an application, you can change the plugin used in the Gradle build script.
Alter the apply plugin line from:
apply plugin: ‘com.android.application’
to:
apply plugin: ‘com.android.library’
Related
I'm trying to create an Android library for two days already.
Realy need your help.
I have an existing App which I want to do as a Library.
According to Android developers documentation:
f you have an existing app module with all the code you want to reuse,
you can turn it into a library module as follows:
Open the module-level build.gradle file. Delete the line for the
applicationId. Only an Android app module can define this. At the top
of the file, you should see the following: apply plugin:
'com.android.application' Change it to the following: apply plugin:
'com.android.library'
I have done this step.
The next step is saying:
When you want to build the AAR file, select the library module in the
Project window and then click Build > Build APK.
I don't really understand how to build the AAR file.
Also in my library, I have others dependencies which I need to be in my Library.
I tried a lot of suggestions in StackOverflow but didn't find the answer.
Unfortunately, I didn't find a good example of creating an Android Library with dependencies.
I don't really understand how to build the AAR file
Just compile the library or use ./gradlew build.
The output will be stored under the library's subdirectory under build/outputs/aar.
I have others dependencies which I need to be in my Library.
The aar file doesn't contain the transitive dependencies.
I suggest you publishing your library into a public or private maven repository.
I am trying to create android aar which uses play services. I have added playservices dependency in library gradle file. But when aar is exported in release mode runtime it is not working.
How to add google play services in aar?
Please help
You may want to check these steps in adding your library as a dependency:
Add the library to your project in either of the following ways (if you created the library module within the same project, then it's already there and you can skip this step):
Add the compiled AAR (or JAR) file (the library must be already built):
Click File > New > New Module.
Click Import .JAR/.AAR Package then click Next.
Enter the location of the compiled AAR or JAR file then click Finish.
Import the library module to your project (the library source becomes part of your project):
Click File > New > Import Module.
Enter the location of the library module directory then click Finish.
The library module is copied to your project, so you can actually edit the library code. If you want to maintain a single version of the library code, then this is probably not what you want and you should instead add the compiled AAR file as described above.
Make sure the library is listed at the top of your settings.gradle file, as shown here for a library named "my-library-module":
include ':app', ':my-library-module'
Open the app module's build.gradle file and add a new line to the dependencies block as shown in the following snippet:
dependencies {
compile project(":my-library-module")
}
Click Sync Project with Gradle Files.
But, if it's an app module that you want to reuse, you can turn it into a library module by following these steps to convert an app module to a library module:
Open the module-level build.gradle file.
Delete the line for the applicationId. Only an Android app module can define this.
At the top of the file, you should see the following:
apply plugin: 'com.android.application'
Change it to the following:
apply plugin: 'com.android.library'
Save the file and click Tools > Android > Sync Project with Gradle
Files.
For a more detailed information, see this documentation. Also. this related SO post can give additional insights.
As play-services now a days contains aar library instead of jar, we can not merge aar file with library i.e. another aar file. And, hence it is not possible to add play-services inside aar file. Best solution for this problem is who ever is using aar made by you, tell them to add play-services dependency in project.
Add a new module to your project and select import .JAR/.AAR Package.
After you added the module proceed like this : Project Structure → Select the app module → Dependencies tab → clieck the + button → select the module you added → Ok
I am developing a library project. Right now my debugging process is something like this :
Make some changes in library code
build it into an aar file
use the aar file in main app project as new library module
then debug the code changes in lib code.
As you can see it's a long process and takes a lot of time to debug library. What is the proper way for library development using android studio?
You can do this way:
Add library module in same project directory like app folder : File-> new-> new module -> Android Library.
Add your library module name in setting.gradle (eg. include ':app',':xyz') : should be added automatically
Right click on your main app folder-> open module settings -> add your library as dependency to "app" (it's under module dependency).
Go to build.gradle file of your main project, add module like compile project (':xyz')
No need to create aar , just make changes in lib module and Run your main project and debug it .
Hope this will help you !
I would include a demo-app project in parallel to library project:
// /settings.gradle
include ':app', ':lib'
// /app/build.gradle
depencency {
compile project(':lib')
}
I'm using Eclipse for developing an Android application. I need to use a library that can be imported using gradle (from Maven repository), since the jar is not provided. How can I do this?
Have you try this link?
Create a new folder called basic-eclipse.
Inside the folder, create folders src/main/java.
Create the Gradle build file in the basic-eclipse folder with the following contents:
apply plugin: 'java'
apply plugin: 'eclipse'
repositories {
mavenCentral()
}
targetCompatibility = 1.6
dependencies {
compile 'commons-lang:commons-lang:20030203.000129'
testCompile 'junit:junit:4.+'
}
From the command line, run gradle eclipse
Now, go into Eclipse and choose File -> Import -> Existing Projects into Workspace and choose the basic-eclipse folder that you created.
import-eclipse-project Notice that src/main/java is automatically configured to be the source directory. Also, the Commons-Lang and Junit jars have been downloaded and added to our build path automatically (in addition to Hamcrest, a jar that Junit depends on).
Unfortunately, the Android Development Toolkit (ADT) does not yet support AAR dependencies.
Please see here for more information:
https://code.google.com/p/android/issues/detail?id=59183
There is an open ticket for the Android for Maven Eclipse project to bring AAR support to Eclipse:
https://github.com/rgladwell/m2e-android/issues/177
Also, the Andmore project is looking to bring AAR support to Eclipse:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=459569
According to your questions,you want to import '.jar' and '.aar',I think you should chose AS.
I want to have a gradle "project" that creates a jar using a custom task (doesn't use any of the gradle java plugins). What is the proper way to construct the build.gradle so that I can depend on it in my android app's gradle project?
More Details:
Currently my jar file is being created in a cmake project that I call from gradle.
I want to have a proper build.gradle file that calls my cmake command then uses the resulting jar as the artifact. Then I would like to be able to simply add "compile project(':mylib') from my android project's build.gradle.
you can make a jar task like:
task myJar(type:Jar) {
archiveName='my.jar'
from sourceSets.main.output
include 'foo/com/**/*', 'bar/com/**/*'
}