How can i create AAR with gradle dependencies locally in Android Studio? - android

Hi i just want to create AAR file from my library module locally.
I tried assemble its creating but the problem is its not including the other dependencies which i added in gradle. Is any idea or blog for solve this issue ?

Related

Android Library issue

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.

Android imported AAR how to keep changes in sync with original AAR project?

If I have project-A which is a SDK and its being exported as a AAR into project-B which imports the module as a AAR how could i go about linking the two modules so changes made to the AAR in project-B don't have to be duplicated in the original project-A?
Create a Project A (library), create project B(application) and put them in the same project.
update the settings.gradle file like this:
include ':projecta', ':projectb'
And make sure the projects are in the same directory
.gradle
.idea
projecta
projectb
etc
By doing this you won't have to explicitly add the aar to project B because they will be in the same project and both automatically be built when you make a release.
Edit about linking with multiple projects
In the case you want to have links to multiple projects your best bet is to create a maven repository.
Doing so will allow you to use your project in the following way:
build.gradle
dependencies{
implementation com.mydomain.projecta:1.0.1
}
Any project you want to use you project A with can be used by writing the line above.
When you update project A you update your maven server and change the version to 1.0.2
You also will have to update the dependencies in the linked projects:
dependencies{
implementation com.mydomain.projecta:1.0.2
}
I think that is the most stress free way to distribute your SDK in one place and easily resuse it in multiple places.
Here are some links about setting up a maven server
https://inthecheesefactory.com/blog/how-to-setup-private-maven-repository/en
https://www.androidauthority.com/add-a-github-library-to-android-studio-using-maven-jcenter-jitpack-777050/

Embedded Unity within my App

I'm trying to build an AR project in Unity and use it as a library in my native android app.
I used this article as a guideline:
https://medium.com/#davidbeloosesky/embedded-unity-within-android-app-7061f4f473a
I successfully imported the project to Android Studio, but the settings.gradle file is missing.
Although I can run the project from the studio, when I convert it to a library and use its aar file in my native android app - I fail to build the project.
Has anyone succeeded doing it?
I followed the guideline and it worked out. I put the .aar file below the native app libs file. In app build.gradle, under dependencies add:
implementation(name:"AndroidPluginDemo",ext:"aar")
and under android add
repositories {
flatDir {
dirs 'libs' //this way we can find the .aar file in libs folder
}
}
Just to add on to the above answers asking about the camera not working, the problem for me was the one of the classes in the unity app wasn't being found when i imported that library into my android app.
When you're converting the application to a library project, take note in the build.gradle of the dependencies.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation(name: 'vlsdk', ext:'aar')
}
In my case I had to find the 'vlsdk.aar' file that was being referenced, and import that as a new module (as is done in step 6 of the tutorial) into my native android app. Hope this helps.
I know this is very old and i hope you have found a solution. but to anyone else facing this issue.
Add the ".aar" libraries found in the libs folder of unity's exported project to the build.gradle file as dependencies(they also need to be physically present in the native projects libs folder).
In my case when i built the .aar library from the exported project it did not add the dependencies(unity exported project also has dependencies found in the libs folder). I only excluded the "unity-classes.jar" file as my unity code is already in the ".aar" that i created.
Check the following link
https://medium.com/#randive.rishiraj/7-steps-to-integrate-google-arcore-unity-project-to-a-native-android-app-d85793ba0b37
Hope this helps.
To implement Unity features inside native apps we need to change Unity Project as a library, and then integrate inside our native application.
From version 2019.3.a2 Unity introduced a new feature Unity as a library in native apps both Android and Ios.
Steps:
1. Export Unity Project as an Library (Android)
2. Add Unity Library Module inside Native Android Project
3.Show Unity View inside Android Activity
Previously, the exported Unity project will have only one gradle module and one manifest file.
But now the Structure has been changed to two gradle modules.
1. launcher
2.unityLibrary
Both launcher and unityLibrary module will have its own build.gradle and manifest files.
unityLibrary - module will have Unity runtime and project data, it can be easily integrated into any other gradle project. It will help
to integrate Unity inside our native android project.
launcher - module will have all icons and the application name.
But we want use only unityLibrary module as an library inside our native android project.
This blog helps to implement unity view in your native android app.
https://navinkumar0118.medium.com/show-unity-view-inside-native-android-app-8035b9b6895a

Does an Android .aar built with Gradle contain dependencies?

Not sure why I can't find any answers on this. If I convert my library project into an .aar using Gradle in Android Studio, does it retain all the dependencies of that module?
I'm asking because I'm trying to use a Gradle generated .aar locally, but it looks like only some of the original dependencies have been packaged. Namely, it complains that I'm missing 'OkHttp', but if I add it to the main project I get duplicate class errors.
Usually a library does not directly contain its dependencies. This does not matter whether it is an aar or a jar. Instead, the library declares its dependencies in the Gradle build file and they are resolved when someone uses the library.

Multiple AAR files

I am using Android Studio 1.2
I create a private library I want to use that one in another application.
To use it I create an AAR files, but this AAR don't work. I have in my library a dependency to an AAR file.
The AAR files do not the dependencies?
If I use the jar and I includ ans create all the dependencies the project works fine.
NOTE :
I know how to importe the AAR file. The problem is to use an AAR in the AAR..
Thanks.
If I'm understanding your question correctly, there are 3 projects involved:
Library Project 2 --> Library Project 1 --> Application Project
You are editing "Library Project 1" and have added to it's app/build.grade a dependency on the Library Project 2's aar. Something like this: compile 'com.arasthel:gnavdrawer-library:1.1.5'
I am not sure where you are running into an issue, but I'll attempt an answer anyway. If I'm completely off-base, can you please elaborate on how the AAR dependency is not working? Any error messages?, a class/resource not found, etc.
I think it's unlikely you are unable to use a class from Library Project 2 inside Library Project 1, because I just tried this myself and it seems to be working just fine. It's worth noting that the Library Project 1 aar file will NOT include classes or resources from Library Project 2. Library Project 2 will be noted as a dependency in Library Project 1's pom if published using gradle's maven plugin to publish Library Project 1.
My guess is that you are having a problem in the Application Project? Perhaps the class from Library Project 2 is not found in the Application Project?
If that is correct, then there are two possible solutions:
Enable transitive dependencies on the aar dependency in the Application project's app/build.gradle: Instead of compile 'com.example:myLibrary:versionX', make it compile('com.example:myLibrary:versionX'){transitive=true}. I just verified this causes gradle to read Library Project 1's pom and automatically add dependencies found there into the Application Project.
If you would like to use transitive dependencies, your Library Project will need to be generating a pom and publishing it along with the aar. See https://stackoverflow.com/a/30085677/431296 for some additional information on how I have this working.
Manually add the dependency on Library Project 2 to the Application Project - so that your Application has a dependency line for both Libraries. Depending on your specific situation this may or may not be a workable solution.
Add following code to you project build.gradle file, and you should put you AAR file to the libs folder.
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
And finally add compile info to your dependencies:
dependencies {
compile(name:'AARFileName', ext:'aar')
}

Categories

Resources