'importing an existing JAR or AAR as new project module

how to import JAR or AAR package as new project module in A new Android Studio Arctic Fox | 2020.3.1 Canary 9 ?

please let me know.



Solution 1:[1]

This works on Android Studio Arctic Fox Beta 02

Step 1 : Navigate to, File -> Project Structure. You can also press Ctrl+Alt+Shift+S

You will see a window just like below.

enter image description here

Step 2 : Click On app module as shown in image

Step 3 : Click on + icon as marked in image

enter image description here

Step 4 : You will see option to select jar/aar dependency. Click on it

enter image description here

You will see another window just like above asking you to specify path. Specify the path in which you kept the aar/jar file and hit Ok.

That should work

Solution 2:[2]

Step 1: Put your aar file in the libs folder. And let’s take the file name is supernover.aar as an example.

Step 2: Put the following code in your Project level

build.gradle  file,
    allprojects {
   repositories {
      jcenter()
      flatDir {
        dirs 'libs'
      }
   }
}

and in the app level module write the below code,

dependencies {
    Implementation(name:'supernover', ext:'aar')
}

Step 3: Then Click sync project with Gradle files.

If everything is working fine, then you will see library entry is made in build ->intermediates -> exploded-aar.

Solution 3:[3]

In my opinion, the best way to do this is to deploy the jar/aar to a local maven repository. if you install maven, you can use the mavenLocal() repository in gradle and read from there as with any other repo, regardless of the IDE you are using. All versions of Android Studio will work, all version of IntelliJ will work, VSCode will work, the command line will work, etc. Another advantage is, you'll be able to swap versions of the library as you do with all the others, just change the version in gradle (after deploying the new one), and will work for all your projects. Putting jars/aars manually into a project is just a bad practice, and reaaally outdated to top.

Once you installed maven, type this in your terminal:

mvn install:install-file -Dfile=d:\mylibrary-{version}.aar -DgroupId=com.example -DartifactId=mylibrary -Dversion={version} -Dpackaging=aar

Where you swap aar and jar depending on the type. The package name, group ID and library name are up to you, anything will work. I would use the library's package and name, and version 1.0 if you don`t have a version.

Here's an example link. Is old, but the process is the same. mvn install, then consume from mavenLocal().

Solution 4:[4]

You can directly implement using JAR/ARR file path.

implementation files('/File Path/file.aar')

Solution 5:[5]

For anyone in search of a solution still.

  1. Create a new android Application project.
  2. Convert new project into a standalone Library module.
  3. Add maven-publish plugin to the module-level build.gradle
  4. Connect your project to your Github repository (or create a new one).
  5. In the module-level build.gradle, implement the Github Packages authentication flow. I'm using 'zuko' as an example - replace every instance of that name with your Github login.
android {
...
  publishing {
       repositories {
           maven {
               name = "GitHubPackages"
               url = uri("https://maven.pkg.github.com/zuko/[git-repository]")
               credentials {
                   username = 'zuko'
                   password = 'token' // this is a Git Personal Access Token
               }
           }
       }

       publications {
           release(MavenPublication) {
               groupId 'com.zuko.libraries'
               artifactId 'choose-a-name'
               version '1.0.0'
               artifact("$buildDir/ogury-mediation-mopub-5.2.0.aar") 
              // you can actually put the artifact anywhere you want.
              // This is the location of where you place your .aar file
           }
       }
   }
...
}
  1. If everything is connected properly, save your work, and run the the task: ./gradlew publish. The error logs are straightforward so just defer to the instructions and Google for more assistance.

  2. To install a successfully published package into your desired project, use the same auth procedure for publishing.repositories, you don't need the second half, publishing.publications.

  3. example: implementation 'com.zuko.libraries:choose-a-name:1.0.0'

Solution 6:[6]

For Android Studio Bumblebee, original answer given here

I have followed steps suggested by the Android developer site:

  1. Copy .aar file into the libs folder of the app

  2. File -> Project Structure... -> Dependencies

enter image description here

  1. Click on "+" icon and select JR/AAR Dependency and select app module

enter image description here

  1. Add .aar file path in step 1.

enter image description here

  1. Check your app’s build.gradle file to confirm a declaration.

Solution 7:[7]

You could configure a repository in you buildscript that looks for dependencies in a local directory

Use this to register a local directory as repository in your app module's build.gradle where libs is a directory under app module (<project>/app/libs/)

buildscript {
    repositories {
        flatDir { dirs 'libs' }
    }
}

then declare your dependencies from the local file tree you registered earlier

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}

This will include all jar/aar artifacts present under libs directory to be included in your module's dependencies.

PS: Local jar/aar artifacts will expect any transitive dependencies to be on the classpath unless they are fat-jars (package all transitive dependencies within the artifact), so these need to be added explicitly as dependencies.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AgentP
Solution 2 Didier Supernover
Solution 3 Dharman
Solution 4 Tushar Lathiya
Solution 5 zuko
Solution 6 SANAT
Solution 7 rahul.taicho