How to add a module dependency while building an AAR - android

I created one library project with two modules. I added the 2nd module in the dependencies of the first module like this:
implementation project(":module2")
I am able to generate the AAR file after this. But I'm getting
java.lang.NoClassDefFoundError
while running the client app.
Kindly help me find out what I am missing here.

In your first module build.gradle file, you can include like ,
api project(":module2")

Related

How to use an android module as app and library

I have an Android Studio project with an app module.
Currently, I am writing another module that should use the first one.
Can I have the first module (which is an app module) be used by the second one as a library?
you have to do like below
In your 1st app module gradle you have to add your second module implementation.
implementation project(':your_second_module_name')
Also you have to update one line in your setting.gradle
include ':app', ':your_second_module_name'

App Bundle - Dynamic feature modules : Base project not found in dynamic feature module error

I am working on a gradle android project which has custom project structure. We used sourceSets.main apis to make mappings for "AndroidManifest.xml ", "res" and others. There are no issues with this set up and all the functionality works fine.
In the project we are planning to implement dynamic feature module. As part of project configuration I have followed all the steps mentioned in android documentation https://developer.android.com/studio/projects/dynamic-delivery#feature_build_config.
As part of instructions, one has to put, base module as a dependency of the dynamic feature module, like below
dependencies {
// Declares a dependency on the base module, ':app'.
implementation project(':app')
}
When I compile the project, build is failing with below error, ("KSApp" is my main project name and "dynamic_feature" is dynamic feature module)
"Project with path ':KSApp' could not be found in project ':dynamic_feature'."
Can some one please explain, whats going wrong and how do I put base module as my dependency in dynamic feature module ?
What I tried :
Using implementation project(${project.rootDir}") in dependencies section of dynamic feature module.
Using implementation file(${project.rootDir}") in dependencies section of dynamic feature module.
Note :
I am able to successfully implement dynamic feature module in a regular projected created in Android studio. I see problem only in project with custom project structure .
Issue is in referring base module form sub module.
As my project has custom android structure, base module is in root project folder. In this case, to refer base module from sub module one should use below approach:
dependencies {
implementation project(':')
}
This is solving the issue.

i cannot find my project build.gradle file to add dependency

I cannot find my build.gradle project file to add dependency only my android studio contains 1 module build.gradle but cannot find the other one to add dependency.
i need to add the google vision dependency in my project but i am not getting where to write the dependency code
like
compile 'com.google.android.gms:play-services-vision:11.0.4'
can please anyone help me out regarding this problem
You can create a new project and then copy it from there

aar dependency error in my android project using android-maven-gradle-plugin

I have a problem when using the aar module dependency aar module as the below issue explains.
https://github.com/dcendents/android-maven-gradle-plugin/issues/65
I have a project such like a client-server structure.
It has 3 modules:
app (my server to provide some service) -- apk module
sdk (my sdk to provide some API to communicate with my app) -- aar module
common (something which should include both in my app module and sdk module ,such as utils,beans,etc. --aar module
I do not want to write it in my both app and sdk modules, debugging and modifying should work twice.
Any idea how I can resolve this?
I'm not sure exactly what you did wrong there, but I've created/modify those gradle scripts and they're working great: https://github.com/sensorberg-dev/gradle-scripts
I can see you're trying to "install" on your local maven. To do that, you have to add this line at the end of the build.gradle from the common module this line:
apply from: 'https://raw.githubusercontent.com/sensorberg-dev/gradle-scripts/master/publish-to-local-maven-repo.gradle'
and then add the metadata to the gradle.properties files, like this:
project gradle.properties:
POM_GROUP_ID=com.company.omg
POM_VERSION=0.0.1
POM_PACKAGING=aar
and common module gradle.properties:
POM_ARTIFACT_ID=common
then it's just call: ./gradlew clean installArchives

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