0

I am having an android library project which is using third party libraries. I have created it's .aar file and imported the .aar file in a different project. Classes and resources are imported but the gradle libraries are not imported. I don't want to mention those dependencies again in the project. Is there any way to import that project with .aar file or something else which include build.gradle or dependencies.

2 Answers2

0

If you are including this library in dependencies block then try to use api instead of implementation.

Krystian Kaniowski
  • 1,959
  • 17
  • 33
  • Currently I am using `implementation (name: 'my-library', ext: 'aar')` When I tried the same with `api` getting the same error of dependencies not foundr. I have added .aar file in `libs` folder of my project and mentioned it's location in app-level gradle by `flatDir{ dirs 'libs' }` Could you please tell the proper format for `api` import statement. – Atharv Upadhyay Sep 21 '20 at 09:53
  • I comment question directly, after spending some time for thinking I realized, that it's not a problem with including, rather it's a problem with exporting. So after update library try with both `implementation` and `api` which I think you used correctly and let me know if `api` was necessary – Krystian Kaniowski Sep 21 '20 at 20:29
  • I have given a solution which is working for me, I need you to check it once. – Atharv Upadhyay Sep 22 '20 at 07:54
0

AAR file does not include external dependencies which are mention in app/build.gradle so instead of adding it directly we upload to local maven and integrate it.

To upload it in your local maven you can add the following function in app/build.gradle

apply plugin: 'maven'

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "file://localhost" + System.getenv("HOME") + "/.m2/repository")
            pom.version = '1.0-SNAPSHOT'
            pom.groupId = 'your.package'
            pom.artifactId = 'sdk-name'
        }
    }
}

You can change the pom version, groupId and artifactId according to how you want to use it.

If this process is completed you can integrate the library.

  • In the app/build.gradle of the project in which you want to add the library specify the path.

    implementation 'your.package:sdk-name:1.0-SNAPSHOT'

  • In the project/build.gradle add the following

    allprojects{
        ...
        mavenLocal()
    }
    

    This will search for the library in the local machine.

If still, you get some error try to invalidate caches and restart the android-studio from the File Menu.