importing an existing JAR or AAR as new project module
Asked Answered
F

7

15

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.

Formalin answered 12/3, 2021 at 10:52 Comment(2)
Have you tried programmersought.com/article/36706527385Hurlee
this worked for me ! follow the link https://mcmap.net/q/49062/-how-to-manually-include-external-aar-package-using-gradle-for-androidFormalin
B
13

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

Barbee answered 10/6, 2021 at 9:48 Comment(4)
Still can't select aar file from explorer in step 1.Reorganization
@AbhayKoradiya How about manually copying and pasting the path in that field ?Barbee
after adding it this way, the new module should be manually added to settings.gradle, like this: include ':modulename'Jointer
For me I first put the aar file in the libs directory, and then the path i needed to specify was "../libs/<nameoffile>.aar". But overall this was a great answer with helpful screenshots!Romantic
B
3

You can directly implement using JAR/ARR file path.

implementation files('/File Path/file.aar')
Burma answered 16/6, 2021 at 6:23 Comment(1)
@AbhayKoradiya Sure. This is not the question. This is the answer. The question is at the top of this page.Rema
C
3

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.
Chairwoman answered 9/5, 2022 at 14:54 Comment(0)
F
1

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.

Formalin answered 17/6, 2021 at 14:41 Comment(2)
What is "the" libs folder? I have no libs folder in my project.Rema
Found it. Belongs directly under “app”. So next to “src”.Rema
D
0

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().

Dittmer answered 12/6, 2021 at 5:58 Comment(1)
@AbhayKoradiya The question is from Didier Supernover and not from you. You cannot claim that something else was asked.Rema
O
0

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.

Overdress answered 13/6, 2021 at 16:26 Comment(2)
since it's a canary version (non-stable) features may not work as expected all the time you could file a bug on their tracker if GUI is broken. Meanwhile, this might help as a workaround if someone is blocked because of canary release not working properlyOverdress
@AbhayKoradiya Just ask your own question if it differs from the question in this thread. Your copy-paste comment is just annoying.Rema
S
0

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'

Sinistrality answered 30/7, 2021 at 6:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.