Search result for Question Taged aar
There are some results of your Tag: aar
    How to solve Error building Android library

    1. FAILURE
    2. We are now seeing this error when building one of our library modules:
      $ ./gradlew library_module:assemble
      
      Execution failed for task ':library_module:bundleDebugAar'.
      > Direct local .aar file dependencies are not supported when building an AAR. 
      The resulting AAR would be broken because the classes and Android resources from any local .aar 
      file dependencies would not be packaged in the resulting AAR. Previous versions of the Android 
      Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The 
      following direct local .aar file dependencies of the :library_module project caused this error: 
      ______.aar
      

    3. Most common Solution
    4. I recently encountered the same issue, the fix was to remove the library from libs/ and import it using File -> New -> New Module -> Import .JAR/.AAR Package, then referencing it in the library module build.gradle file:

      dependencies {
        implementation project(":imported_aar_module")
      }
      

      If you are on a newer Android Studio version (4.0.0+), this option is not available. Instead you have to do it manually.

      1. Create a new directory and put the following content into the build.gradle file withing the new directory:
      configurations.maybeCreate("default")
      artifacts.add("default", file('[nameOfTheAar].aar'))
      
      1. Place the aar into this new directoy. Next to the build.gradle file.
      2. Add the new created Gradle project to the settings.gradle file:
      include(":pathToTheCreatedDirectory")
      
      1. Include the project in your library where you want to use the aar:
      implementation project(":pathToTheCreatedDirectory", configuration = "default")
      

    5. Solution 2
    6. When building an Android library that depends on other Android libraries (i.e., aar files), you will get the following error message if you include the aar files as dependencies in the project:

      Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error).

      As the above message states, when you build an Android library project, any aar it depends on is not packaged. If you built this way prior to AGP (Android Gradle Plugin) 4, you probably noticed that you had to include the aar dependencies on the project consuming your library.

      You can compile your Android library project by specifying that the aar dependencies are compileOnly. See this for more info on when to use compileOnly.

      So just add the following to your app build.gradle file:

      compileOnly files('libs/some-library.aar')
      

      Note that if you do this you will have to include the aar dependencies on the application project that consumes your library.

      Alternatively, you can create a module that imports your aar dependency as @Sandi mentioned in the answer above.

      Another way is to publish your aar dependencies to a maven repository and then add them to your library project like this:

      implementation 'mylibrarygroup:mylibraryartifact:version-x.y.z@aar'
      

    7. Solution 3
    8. I want to call out @StefMa's comment on this question which was incredible simple and solved this issue for me, but it's buried among many other comments on this thread and is easily missed.

      The 'correct' answer on this thread no longer works because it's not possible to import AARs in Android Studio anymore as referred to in that answer. But, the solution referred to in StefMa's comment linking to this GitHub post does, and it works perfectly.

      Long story short - put your AAR into a separate module.

      There's no need to muck around with creating lib directories, just follow these directions -

      1. Create a new directory in your project's root directory. The image below shows two of them - spotify-app-remote and spotify-auth, but one is sufficient. Within that, put your AAR in, and create a new build.gradle file.

        Folder structure

      2. Within the build.gradle file, add the following, replacing the aar filename with the name of your AAR file -

        configurations.maybeCreate("default")
        artifacts.add("default", file('spotify-app-remote-release-0.7.1.aar'))
        
      3. Add this to your settings.gradle file, substituting the name of the directory you created

        include ':spotify-app-remote'
        
      4. Include your new module in the module you wish to use the AAR. eg, if you want to use it within your app module, open app's build.gradle and add

        api project(':spotify-app-remote')
        

        within your dependencies { } block, obviously again substituting spotify-app-remote with whatever the name of your module is.

    9. Solution 4
    10. In my experience, when Gradle Plugin version is 4.2.2+ and Gradle version is 7.1+, as in @Luis's answer 'compileOnly' works.

      compileOnly files('libs/your_library_name.aar')
      

      It didn't work when the Gradle versions were lower.

    Filibert Nosizwe 2022-08-11
    java - Android Library Gradle release JAR

    How can I release Jar packaging of android-library project?
    I've found, classes.jar is located under build/bundles/release/classes.jar and I suppose this is correct Jar package (contains *.class files).

    Is there some official way, to release library as JAR instead of AAR ?

    Edit
    I use Gradle to release Maven artifacts, and I'd like to release JAR along with AAR package. So JAR with signature, md5, manifest, ...
    based on https://chris.banes.me/2013/08/27/pushing-aars-to-maven-central/

    apply plugin: 'maven'
    apply plugin: 'signing'
    
    configurations {
        archives {
            extendsFrom configurations.default
        }
    }
    
    def sonatypeRepositoryUrl
    if (isReleaseBuild()) {
        println 'RELEASE BUILD'
        sonatypeRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
    } else {
        println 'DEBUG BUILD'
        sonatypeRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
    }
    
    if(!hasProperty('nexusPassword')) {
        ext.set('nexusPassword', System.console().readPassword("\n\$ Type in password for Sonatype nexus account " + nexusUsername + ": "))
    }
    
    if(!signing.hasProperty('password')) {
        ext.set('signing.password', System.console().readPassword("\n\$ Type in GPG key password: "))
    }
    
    afterEvaluate { project ->
        uploadArchives {
            repositories {
                mavenDeployer {
                    beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
    
                    pom.artifactId = POM_ARTIFACT_ID
    
                    repository(url: sonatypeRepositoryUrl) {
                        authentication(userName: nexusUsername, password: nexusPassword)
                    }
    
                    pom.project {
                        name POM_NAME
                        packaging POM_PACKAGING
                        description POM_DESCRIPTION
                        url POM_URL
    
                        scm {
                            url POM_SCM_URL
                            connection POM_SCM_CONNECTION
                            developerConnection POM_SCM_DEV_CONNECTION
                        }
    
                        licenses {
                            license {
                                name POM_LICENCE_NAME
                                url POM_LICENCE_URL
                                distribution POM_LICENCE_DIST
                            }
                        }
    
                        developers {
                            developer {
                                id "loopj"
                                name "James Smith"
                            }
                            developer {
                                id "smarek"
                                name "Marek Sebera"
                            }
                        }
                    }
                }
            }
        }
    
        signing {
            required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
            sign configurations.archives
        }
    
        task androidJavadocs(type: Javadoc) {
            source = android.sourceSets.main.java.srcDirs
        }
    
        task androidJavadocsJar(type: Jar) {
            classifier = 'javadoc'
            from androidJavadocs.destinationDir
        }
    
        task androidSourcesJar(type: Jar) {
            classifier = 'sources'
            from android.sourceSets.main.java.srcDirs
        }
    
        artifacts {
            archives androidSourcesJar
            archives androidJavadocsJar
        }
    }
    

    using

    task androidJar(type: Jar) {
        from android.sourceSets.main.java.srcDirs
    }
    

    will package only java files, not compiled and linked against android sdk

    Winnie Zubin 2022-08-19
    java - Android Archive Library (aar) vs standard jar

    I've been reading some articles about the new adoption of Gradle as the standard build system for Android apps. Well, coming from standard Java development I usually depend on jar files in order to build my project. However it seems that Android has also aar packages, which are the equivalent to the dll files in a Windows OS, as mentioned here:

    First, you have to realize that the Android platform does not allow application-level “shared libraries”. In the “traditional” programming language platforms, C, C++, Java, you name it, we have this mechanism of sharing runtime libraries. (E.g., DLL on Windows, DSO on Unix, Jar on JVM, etc.). On Android, however, you cannot do that, unless you are Google or a handset manufacturer (See Footnote 1 below). As an application developer, this can be a fundamental limitation. “Sharing” or “reusing” codes, both at build time and run time, is a very important part of software engineering practice. This is rather hard (not impossible, just harder) on Android because of the aforementioned limitation.

    However, I have some doubts around this concept. I mean, when should a developer be interested including aar dependencies in its application? Are this dependencies tightened to some SDK minimum version?

    For example, in one project I access a COM port, which I use NDK precompiled .so libraries for. Do I have to create an aar if I want to share this utility?

    Shayne Misti 2022-08-15
    android - Cordova plugin development - adding aar

    I am new to the cordova plugin development stuff. I want to write a plugin which is able to open a new android activty and showing some advertisement.

    So I followed a simple tutorial here. That works very well and as expected.

    Next step is to include this Android Studio Gradle project to my plugin.

    My first try: Adding the gradle project to a subfolder of my cordova plugin and adding the following line to the plugin.xml file:

    <framework src="libs/Broper/build.gradle" custom="true" type="gradleReference" />
    

    also I tried:

    <framework src="libs/Broper/app/build.gradle" custom="true" type="gradleReference" />
    

    doesn't work. So I can't import the classes of that android studio project to my plugin java files.

    Then a better solution (I thought so) is to add an AAR instead. But there I don't even have a clue what to do to add that AAR in my cordova plugin.

    So, the question is: How do I add an android studio project (or library) to my cordova plugin the right way?

    Simon Yitro 2022-08-22
    Create aar file in Android Studio

    I'd like to create an aar file for my library in Android Studio, i would've gone with a jar option but my library has resources.

    Any idea how to create an aar file from a library?

    Ritu Nadežda 2022-08-15
    java - How to include JAR dependency into an AAR library

    Summary:

    I have an AAR file that depends on a JAR file, when I build the AAR project, it doesn't contain the JAR code.

    Details:

    I have a Java SDK library project that contains code that we use for Java web projects and such, this library is created using Gradle and resides in an internal nexus server (as a JAR).

    The goal is to provide an "Android configured" version of this JAR library through an AAR library that multiple Android Applications can use and minimize the effort (and boilerplate code) to implement it. This AAR file is also uploaded to the nexus server to be used by the Android Application projects.

    My AAR project includes a gradle dependency for my Java SDK library (the JAR) but when built, the AAR doesn't include any classes from it.

    Code:

    This is the Java SDK project's gradle file:

    apply plugin: 'java'
    
    //noinspection GroovyUnusedAssignment
    sourceCompatibility = 1.7
    version = '1.1.1'
    
    repositories {
        mavenCentral()
    }
    
    jar {
        from {
            configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
        }
    }
    
    dependencies {
        testCompile group: 'junit', name: 'junit', version: '4.11'
        testCompile 'org.apache.directory.studio:org.apache.commons.io:2.4'
        compile 'org.springframework:spring-web:3.1.1.RELEASE'
        compile 'com.google.code.gson:gson:2.3'
    }
    

    This is the gradle file for my AAR Project, note that I removed the Maven repository declarations to my nexus server from it. I guess it shouldn't matter for the sake of this question.

    apply plugin: 'com.android.library'
    
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.1"
    
        defaultConfig {
            minSdkVersion 16
            targetSdkVersion 23
            versionCode 1
            versionName "2.2.2"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        lintOptions {
            abortOnError false
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.1.0'
    
        compile ('com.mycompany:javasdk:1.1.1')
    }
    

    This is the gradle file for my Android Project, again I removed the nexus server references:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.1"
    
        defaultConfig {
            applicationId "com.mycompany.application1"
            minSdkVersion 16
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.1.0'
    
        compile ('com.mycompany:androidsdk:2.2.2@aar')
    }
    

    NOTE: I initially solved the issue by adding the JAR in the lib directory of the AAR project, but this is undesired. It makes having a nexus server useless. It would be good that we can just bump the JAR's version number in the AAR project's gradle file and the update happens automatically at compile time.

    NOTE2: I tried adding transitive=true to my AAR dependency in the Android Project but it didn't solved anything, the real issue is that when building the AAR project, the JAR project code doesn't get bundled.

    Vimal Anderson 2022-08-24
    java - Difference between AAR, JAR, DEX, APK in Android

    In Android systems or development enviroments, what are the differences between AAR, JAR, DEX, and APK files? What is the purpose of each one?

    AFAIK, JAR are just like a collection of .class files (like in Java).

    AAR are JAR files + resources. But what's its usage case? To be used to distribute development libraries for Android?

    APK seems to be similar to packages like .deb or .rpm. Is it the only way to install applications on Android?

    What about DEX files? Compiled applications... but what's the difference with a JAR or AAR file?

    Moreveor, when distributing .so (i.e. native code) files for Android, what's the best way to do it?

    Cher Samanta 2022-08-25
    android - Adding AAR in IntelliJ IDEA without gradle

    How can I add aar-module into the project in IDEA (without gradle, using ant)?

    Sitora Meresankh 2022-09-04
    android - How to use local aar dependency?

    i google about local aar,every one say it can work,but it don't work at android studio 1.1.0.

    i try to use :

    compile fileTree(dir: 'libs', include: ['*.aar'])
    

    but it tip:

    Warning:Project app: Only Jar-type local dependencies are supported. Cannot handle: /Users/kycq/AndroidStudioProjects/QingTaJiao/app/libs/KycqBasic-release.aar
    

    how should i do to use local aar? if i should use:

    compile 'com.example.library:library:1.0.0@aar'
    

    how to do this?

    Hari Ionas 2022-08-21
    In Android Studio, is there a way to search a word within jar, aar, and maven imported libraries?

    Sometimes within the library I need to search a method name or a method that deals with what I am looking for.

    In Android Studio, is there a way to search a word within jar, aar, and maven imported libraries?

    It doesn't have to be using Android Studio, is there a tool which I can search words within jar, aar, maven imported libraries?

    Kasi Hanna 2022-09-10
    intellij idea - Add local javadoc to local aar in Android-Studio

    Is there a way to attach javadocs, provided in a jar, to a aar library? There is no source code available and both files exist locally (not in a repository).

    The aar is added through:

    repositories {
        flatDir {
            dirs 'libs'
        }
    }
    
    dependencies {
        compile(name:'library', ext:'aar')
    }
    

    And works fine (besides the inability to add docs).

    What I tried (and did not work):

    • navigate to a class contained in the aar and tried to attech the javadocs through "attach source"
    • add library.aar.properties containing doc=docs/library-javadoc.jar
    • packed javadoc.jar into library.aar next to the classes.jar

    Environment:
    Android-Studio 0.8.2
    gradle plugin 0.12

    It might not be possible ATM (see this bug: https://code.google.com/p/android/issues/detail?id=73087) but any workaround would be appreciated.

    Stefana Dominik 2022-08-26
    android - How to export AAR library with its documentation?

    I'm wondering why my library always lost its documentation once it was built to AAR format. Also, Android Studio shrinks the code, i.e. the code before built always different with the code after built into AAR format, none originals. I want my library to has its own documentation and has the original code. You can see the different below:

    Before built

    before

    After built into AAR format

    after

    Where is the documentation?! Also, you'll notice that the whole code are really shrunk and different.

    So, how do I export AAR library with its documentation without shrink the code?

    Raja Prateek 2022-08-31
    android - how to start an activity in another module explicitly

    I created an aar and i added it to my project as an module. in this module i have a HelloWorldActivity that i want to run.

    my module manifest looks like this.

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="ir.sibvas.testlibary1.HelloWorldActivity"
            android:label="@string/app_name" >
    
            <intent-filter>
                <action android:name="ir.sibvas.testlibary1.HelloWorldActivity" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
    
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
    
    
        </activity>
    </application>
    

    Now i can start this activity from my project using this code

     Intent intent = new Intent("ir.sibvas.testlibary1.HelloWorldActivity");
     startActivity(intent);
    

    but as you can see this code is implicit and problem with implicit calling is that if i use this module in more than one app, both installed on user device it will show an app chooser dialog to user. So how can make this call explicit, preventing user from switching app?

    this code will not run since HelloWorldActivity is not in the same package as calling activity

    Intent intent = new Intent(this, HelloWorldActivity.class);
    startActivity(intent);
    

    I really don't want to change my module for each project that uses it.

    Ibrahim Yaron 2022-08-23
    Android Studio Library project error

    I have imported a module into my project. When i rebuilt the project , AS gave me an error saying Warning:Dependency Lib:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency. I searched and changed apply plugin: 'com.android.application' to apply plugin: 'com.android.library' and also removed ApplicationId from defaultConfig. Yet i am getting this same error "Warning:Dependency Lib:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency." Can any one help me?

    Here is my gradle code:

    apply plugin: 'com.android.library'
    
        android {
        compileSdkVersion 23
        buildToolsVersion "23.0.1"
    
        defaultConfig {
            minSdkVersion 12
            targetSdkVersion 23
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        }
    
        dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.1.0'
        compile 'com.android.support:design:23.1.0'
        compile project(':DimenLib')
        }
    
    Gaynor Valerianus 2022-09-06
    maven - How do I ship an Android Library (aar) with remote dependencies (gradle)?

    I am trying to build an aar file with gradle that has remote dependencies. An example build script is below. As you can see I have two dependencies. The problem I'm having is when I do a release, the aar file does not contain the remote dependencies, so when I include the aar file in other projects I get NoClassDefFound errors.

    I found that if I copy the jar from my local maven repo to a libs folder in my project, then the jar does get included in the release aar. How do I include the remote dependencies in the aar file? I've also read elsewhere that it's bad practice to ship dependencies like this, so if there's a better way to do what I'm trying to do I'm all for it.

    buildscript {
    
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.9.+'
        }
    }
    
    apply plugin: 'android-library'
    
    repositories {
        mavenCentral()
        mavenLocal()
    }
    
    android {
    ... omitted for brevity
    }
    
    dependencies {
        compile 'com.somepackage:someartifact:1.0'
        compile 'com.anotherpackage:artifact:2.0'
    }
    
    Laxmi Queenie 2022-09-11
    maven - How to release an AAR with another android library project dependency?

    Here is my development project structure:

    projectFolder
      |
      +--App
      |
      +--MyLib
      |
      +--Libraries
          |
          +--LibA
    

    MyLib depends on LibA, I have packaged MyLib as an AAR and release it to a Maven repo, But when I include MyLib in another project(TestProj) as a remote aar dependency, I get build error(can't resolve dependency of LibA, LibA is not included with the release of MyLib), This is the build.gradel in app folder of TestProj:

    dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile ('xxx.xxxxxx:yyyyy:1.0-SNAPSHOT@aar'){
          transitive = true
      }
    }
    

    And here is the build.gradle of MyLib:

    dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile project(':Libraries:LibA')
    }
    

    How can I release MyLib with LibA already packaged in the AAR?

    Alícia Ugochukwu 2022-09-27
    android - How to exclude files from aar with Gradle dynamically?

    I'm having android library (aar) that contains (and builds while building module) native code:

    apply plugin: 'com.android.library'
    
    android {
      compileSdkVersion 16
      buildToolsVersion "25.0.0"
    
      defaultConfig {
        minSdkVersion 11
        targetSdkVersion 16
        versionCode 1
        versionName "1.0"
    
        ndk {
          abiFilters 'armeabi-v7a'
        }
      }
    
      externalNativeBuild {
        ndkBuild {
          path 'jni/Android.mk'
        }
      }
    
      sourceSets {
        main {
          manifest.srcFile 'AndroidManifest.xml'
          java.srcDirs = ['src']
          res.srcDirs = ['res']
          jni.srcDirs = ['jni']
        }
      }
    
      packagingOptions {
        exclude '/lib/armeabi-v7a/libv8.cr.so'
        exclude '/lib/armeabi-v7a/libv8_libbase.cr.so'
         // TODO : generate dynamically from `SHARED_V8_LIB_FILENAMES`
      }
    }
    

    I've modified Android.mk file to have different config dependent on SHARED_V8_LIB_FILENAMES environment variable:

    ...
    # Report configuration
    ifeq ($(SHARED_V8_LIB_FILENAMES),)
    # static
    $(info [Configuration] Linking statically with built-in v8)
    else
    # dynamic
    
    define info_define
        $(info [Configuration] Linking dynamically with shared v8 library ./libfoo-binaries/android_$(TARGET_ARCH_ABI)/$1)
    endef
    $(foreach item,$(SHARED_V8_LIB_FILENAMES),$(eval $(call info_define,$(item))))
    endif
    ...
    

    How can i modify my build.gradle in order to generate packageOptions section dependent on environment variable SHARED_V8_LIB_FILENAMES? I need to check if the variable is set, parse it with space separator and add files list to be excluded from final aar file.

    Krisztina Promise 2022-09-27
    android - Adding local .aar files to my gradle build

    So I have created an Android library and successfully compiled it into a .aar file. I called this aar file: "projectx-sdk-1.0.0.aar". Now I want my new project to depend on this aar so what I have done is follow this post.

    But the post confuses me since I do not get the desired result:

    The package name of the aar is : com.projectx.photosdk and the module inside is called sdk

    Here is my current project structure:

    |-SuperAwesomeApp
    |--.idea
    |--gradle
    |--App
    |---aars
    |----projectx-sdk-1.0.0.aar
    |---build
    |---jars
    |---src
    |---build.gradle
    

    And here is my Gradle build file:

    apply plugin: 'android'
    
    buildscript {
        repositories {
            mavenCentral()
            flatDir {
                dirs 'aars'
            }
        }
    }
    
    android {
        compileSdkVersion 19
        buildToolsVersion "19.0.1"
    
        defaultConfig {
            minSdkVersion 11
            targetSdkVersion 19
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                runProguard false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            }
        }
    }
    
    dependencies {
        compile 'com.android.support:gridlayout-v7:19.0.1'
        compile 'com.android.support:support-v4:19.0.1'
        compile 'com.android.support:appcompat-v7:19.0.1'
    
    
        compile 'com.projectx.photosdk:sdk:1.0.0@aar'
    //    compile files( 'aars/sdk-1.0.0.aar' ) // Does not work either
    }
    

    EDIT

    The errors I am getting:

    Failed to refresh Gradle project 'SuperAwesomeApp'
         Could not find com.projectx.photosdk:sdk:1.0.0.
         Required by:
         SuperAwesomeApp:App:unspecified
    
    Urbain Vidar 2022-08-18
    java - How to Add and Use an AAR in AndroidStudio Project

    I am trying to use a custom aar in my android project. I found dozens of examples in StackOverflow and the Web. Many failed at build, none worked. The clearest was at http://kevinpelgrims.com/blog/2014/05/18/reference-a-local-aar-in-your-android-project/
    That came closest to working.

    Here's what I did

    1. Successfully created a very simple AAR (Ref.aar) from Ref.java

      // Ref.java  
      package com.ramrod.Ref;  
      public class Ref {
          // Square an integer
          public static int
          square(int val) {
              return (val * val);
          }
      }  
      
    2. Created a test project (RefTest)

    3. Created folder 'libs' under RefTest/app
    4. Added Ref.aar to libs
    5. File->New->New Module->Import .JAR/.AAR Package.
    6. Selected Ref.jar as filename->Finish (appeared successful).
    7. Modified build.gradle

      // build.gradle (Module: app)  
      
      apply plugin: 'com.android.application'
      
      android {
          compileSdkVersion 27  
          buildToolsVersion "27.0.3"
          defaultConfig {
              applicationId "com.ramrod.RefTest"
              minSdkVersion 11
              targetSdkVersion 15
          }
          buildTypes {
              release {
                  minifyEnabled false
                  proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
              }
          }
          repositories {
              flatDir {
                  dirs 'libs'
              }
          }
          dependencies {
              compile( name:'Ref', ext:'aar' )
         }
      }  
      
    8. Sync build.gradle (all)
    9. Added reference to Ref.aar method (square) to onCreate in RefTest main activity.

      int sq = Ref.square( 2 );
      
    10. Build->Clean then Build->Rebuild.
      This produced error: cannot find symbol variable Ref

    I'm sure I'm doing something naive or just plain dumb, but I can't see it.
    Any help appreciated.

    Krisztina Promise 2022-09-24
    android - Transitive dependencies for local aar library

    We're making some library, basicly for our API, that we would make life easier for our external developers.

    So we created new library project and put Retrofit and some other libraries as dependencies.

    dependencies {
        compile 'com.android.support:appcompat-v7:23.3.0'
        compile 'com.google.code.gson:gson:2.6.2'
        compile 'com.squareup.retrofit2:retrofit:2.0.1'
        compile 'com.squareup.retrofit2:converter-gson:2.0.1'
        compile 'com.squareup.okhttp3:okhttp:3.2.0'
    }
    

    Now when we build it, it produces aar file.

    But now when we put the aar file to libs directory and set it as dependency, we still have to put the same dependency in user's build.gradle file, which sucks. It should be taken from the library, right?

    repositories {
        flatDir {
            dirs 'libs'
        }
    }
    
    dependencies {
        compile(name: 'ourlibrary', ext: 'aar') {
            transitive = true;
        }
    }
    

    How to make transitive = true work?

    Marianne Alf 2022-08-21
    android - Gradle: how to include dependencies from repositories to output aar file

    I am trying to build an arr package in Android Studio. This package contains dependecies for Zendesk:

    allprojects {
        repositories {
            maven { url 'https://zendesk.artifactoryonline.com/zendesk/repo' }
        }
    }
    
    compile (group: 'com.zendesk', name: 'sdk', version: '1.7.0.1') {
        transitive = true
    }
    
    compile (group: 'com.zopim.android', name: 'sdk', version: '1.3.1.1') {
        transitive = true
    }
    

    I want to build this package for a Unity3d project. This package should contain all dependecies for Zendesk (the transitive = true property). When I open the aar file there is no dependencies for Zendesk. What is wrong?

    Benjamín Murali 2022-09-22
    Adding multiple file providers in Android application

    guys, I am working on an android application for which I need external application dependency(.aar file) library application has its own file provider and my application have its own.

    library work well when I run it as a separate app but when I include it my application then camera functionality not working. I get the following error

    java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
    

    following the manifest file of the application

    <provider
                android:name="android.support.v4.content.FileProvider"
                android:authorities="${applicationId}.provider"
                android:exported="false"
                android:grantUriPermissions="true">
                <meta-data
                    android:name="android.support.FILE_PROVIDER_PATHS"
                    android:resource="@xml/file_paths" />
            </provider>
    

    and the following is a manifest file of the lib module

    <provider
                android:name="android.support.v4.content.FileProvider"
                android:authorities="com.ma.bot.provider"
                android:exported="false"
                android:grantUriPermissions="true">
                <meta-data
                    android:name="android.support.FILE_PROVIDER_PATHS"
                    android:resource="@xml/file_paths" />
            </provider>
    

    both application and lib module have different package name how I add this 2 file providers into the application I also try including multiple file providers using, but I get XML parse error on app compilation.

    android:authorities="${applicationId}.provider;com.ma.bot.provider"
    

    how to solve this.

    Kyle Elkins 2022-10-05
    Android load modules dynamically

    I wanna write an android application which can be extended with modules (android libraries). The modules shall be loaded at runtime. Therefore they'll be downloaded from an url and stored in a directory. The modules are aar files.

    Is there a way to load aar files dynamically at runtime?

    I know it's possible to just load the contained classes.jar with an URLClassLoader. But than I can't load the layout, string, ... resources. HM

    Does anyone know a way how to solve this?

    EDIT:

    I found a few related topics:

    • Dynamically loading aar library
    • https://stackoverflow.com/questions/25919338/is-possible-to-include-a-dynamically-aar-file
    • Write Plugin for Android App
    • Plugins architecture for an Android app?
    • How to develop an app that has add-ons?
    • Android - Build an application that supports add-ons

    It seems that it doesn't work because of the answer from the first link. I hope I'm wrong with that thinking.

    Beatrycze Luc 2022-09-19
    Using Kotlin in Android library distributed as AAR

    Is it even possible to use Kotlin to write a library?

    The problem I see is that it will depend on specyfic versions of kotlin-stdlib and kotlin-runtime and force user of the library to use the same version.

    I'm considering using jarjar to repackage those but then, how to include those in a fatjar-type distribution? Inside the unpacked aar I see /libs directory - is there a way to use that?

    Beatrycze Luc 2022-09-13
    gradle - Android / Execution failed for task checkDebugAarMetadata / A failure occurred while executing CheckAarMetadataWorkAction

    TL'DR: In this Android Kotlin library I updated from Gradle 5.6.4 to 6.6.1 (commit d5d8d2). Now I cannot build a project depending on the aar anymore.

    Test setup

    I build and deploy the aar to mavenLocal ...

    $ ./gradlew clean :roadsigns:assemble
    $ ./gradlew publishToMavenLocal
    

    ... and then reference the deployed library artifact in the sample Android app module. First I add mavenLocal() in the root build.gradle file:

    allprojects {
        repositories {
            google()
            mavenCentral()
            jcenter()
            mavenLocal() // <-- Add this
        }
    }
    

    I reference the mavenLocal() dependency directly:

    dependencies {
        implementation
        // implementation project(":roadsigns")
        implementation "info.metadude.kotlin.library.roadsigns:roadsigns:$version"
        implementation Libs.kotlinStdlib
        // ...
    

    The error

    When I build the sample app then I get the following build error:

    $ ./gradlew clean assembleDebug
    
    Execution failed for task ':checkDebugAarMetadata'.
    > Multiple task action failures occurred:
    
       > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
          > A dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) does
            not specify an aarFormatVersion value, which is a required value.
            Dependency: info.metadude.kotlin.library.roadsigns:roadsigns:4.0.0.
            AAR metadata file: /home/USERNAME/.m2/repository/info/metadude/kotlin/library/roadsigns/roadsigns/4.0.0/roadsigns-4.0.0-javadoc.jar.
    
       > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
          > A dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) does
            not specify an aarFormatVersion value, which is a required value.
            Dependency: info.metadude.kotlin.library.roadsigns:roadsigns:4.0.0.
            AAR metadata file: /home/USERNAME/.m2/repository/info/metadude/kotlin/library/roadsigns/roadsigns/4.0.0/roadsigns-4.0.0-sources.jar.
    
       > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
          > A dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) does
            not specify an aarFormatVersion value, which is a required value.
            Dependency: info.metadude.kotlin.library.roadsigns:roadsigns:4.0.0.
            AAR metadata file: /home/USERNAME/.m2/repository/info/metadude/kotlin/library/roadsigns/roadsigns/4.0.0/roadsigns-4.0.0.aar.
    

    Context information

    When I try the same with Gradle 5.6.4 then there is no error.

    In the Android Kotlin library I am using:

    • digital.wup:android-maven-publish:3.6.3
    • com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5

    I using Java 8 (OpenJDK) on my machine and verified that the same error occurs on a different computer.

    Experiments

    • When I deploy the library with Gradle 5 and build the app with Gradle 5 or Gradle 6 in both cases it works.

    The question

    What changed from Gradle 5 to Gradle 6 which causes the aar to be broken (?)

    Findings

    • I took a look at the files being deployed in mavenLocal():

      ~/.m2/repository/info/metadude/kotlin/library/roadsigns
      └── roadsigns
      ├── 4.0.0
      │   ├── roadsigns-4.0.0.aar
      │   ├── roadsigns-4.0.0-javadoc.jar
      │   ├── roadsigns-4.0.0.module
      │   ├── roadsigns-4.0.0.pom
      │   └── roadsigns-4.0.0-sources.jar
      └── maven-metadata-local.xml

    • I compared the files deployed with Gradle 5 and Gradle 6. Interestingly, the roadsigns-4.0.0.aar files are binary equivalent. The pom file differs, though:

      Diff of roadsigns-4.0.0.pom files

    • Also there is a roadsigns-4.0.0.module file only when I deploy with Gradle 6.

    • When I manually remove the "new" do_not_remove: published-with-gradle-metadata part from the file deployed with Gradle 6 then the app builds successfully! The question remains ... what's going on here?!

    Raja Prateek 2022-09-13
    How to include aar files used in library projects in main project in Android

    My project is including some library project. Library is using some aar files and its dependecny is already defined in the module: gradle file. I am facing problem in including this library in my project.

    If I keep duplicate aar files in app->lib and define their dependency in app->gradle file then there is no problem. But it shouldn't be the right approach.

    Please find below the error:

    A problem occurred configuring project ':app'.

    Could not resolve all dependencies for configuration ':app:_qaDebugCompile'. Could not find :api-release:. Searched in the following locations:
             https://jcenter.bintray.com//api-release//api-release-.pom
             https://jcenter.bintray.com//api-release//api-release-.aar
             file:/D:/sample/sample-android-app/app/libs/api-release-.aar
             file:/D:/sample/sample-android-app/app/libs/api-release.aar
         Required by:
             sample-android-app:app:unspecified > sample-android-app:misnapworkflow:unspecified
    

    please find below the project structure:

    sample
    |-- app
    |-- misnapworkflow
        |
        |-- lib
            |-- api-release.aar
    

    In app gradle file following has been mentioned to include the project

    dependencies { compile project(':misnapworkflow') }

    Please find below the misnapworkflow gradle file:

    apply plugin: 'com.android.library'
    
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.1"
    
        defaultConfig {
            minSdkVersion 10
            targetSdkVersion 23
            consumerProguardFiles 'proguard-rules.pro'
        }
    
        lintOptions {
            abortOnError false
        }
    
        // Publish both debug and release libraries
        publishNonDefault true
    
        buildTypes {
            debug {
                debuggable true
                jniDebuggable true
                minifyEnabled false
                shrinkResources false
                testCoverageEnabled true
            }
    
            release {
                signingConfig signingConfigs.debug
                debuggable false
                jniDebuggable false
                minifyEnabled true
                shrinkResources false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    task grantPermissions(type: Exec, dependsOn: 'installDebugTest') {
        logger.warn('Granting permissions...')
        commandLine "adb shell pm grant com.miteksystems.misnap.misnapworkflow.test android.permission.WRITE_EXTERNAL_STORAGE".split(' ')
        commandLine "adb shell pm grant com.miteksystems.misnap.misnapworkflow.test android.permission.CAMERA".split(' ')
        logger.warn('Permissions granted.')
    }
    
    tasks.whenTaskAdded { task ->
        if (task.name.startsWith('connected')
                || task.name.startsWith('create')) {
            task.dependsOn grantPermissions
        }
    }
    
    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.android.support:appcompat-v7:23.0.1'
    
        // Add dependency for MiSnap external API
        compile(name: 'api-release', ext: 'aar')
    
        // Add dependency for MiSnap
        compile(name: 'misnap-release', ext: 'aar') {
            exclude module: 'appcompat-v7'
        }
    
        // Eventbus dependency
        compile 'de.greenrobot:eventbus:2.4.0'
    
        // Add OPTIONAL dependency for Manatee
        compile(name: 'manatee-release', ext: 'aar')
    
        compile(name: 'cardio-release', ext: 'aar')
    }
    
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
    
    Pāvils Philomena 2022-09-14
    Putting permissions to manifest of Android .aar library project

    I am developing an Android project which includes two modules where one is a library module for producing .aar files and another is a sample app utilising the produced .aar file.

    Thus, there are two AndroidManifest.xml files in this project. Say I am developing a Bluetooth library, so I put permissions for bluetooth in library's manifest file. By including this library .aar as dependency, can I omit the <uses-permission> tag in the app's manifest file? In other words, does Android app "merge" (may be not literally but semantically) its dependent .aar libraries' permissions?

    My experience suggests that while some permissions tend to behave as above, others demand explicit declaration in application's AndroidManifest.xml. I would like to know if my assumption is true, if there are any resources or documentations clearly distinguishing permissions those can reside in .aar library's manifest and those required to be declared in application's own manifest file.

    Thank you!

    Lenuța Robert 2022-09-02
    gradle - How to publish Android .aar sources to make Android Studio automatically find them?

    I'm publishing libraries to an internal Sonatype Nexus repository.

    Android Studio has a feature that automatically finds the correct source for a library that is referenced through gradle. I publish the sources for our aar as a separate jar to the nexus. But Android Studio is not picking them up.

    How do I have to publish the sources to make them available in Android Studio?

    Markos Agatha 2022-09-16
    aar support in Android.mk

    I am doing android custom ROM development now. the build system of aosp is based on Android.mk, But I want to include some aar libraries, is it possible to include aar libaries in Android.mk ?

    Mandlenkosi Shantelle 2022-09-21
    maven - play-services-base versus -basement dependencies (AAR) in Android

    I found an xml file GoogleDependencyFlurryPlugin.xml

    <dependencies>
    <dependency><groupId>com.google.android.gms</groupId><artifactId>play-services-base</artifactId><version>8.4+</version></dependency>
    <dependency><groupId>com.google.android.gms</groupId><artifactId>play-services-basement</artifactId><version>8.4+</version></dependency>
    </dependencies>
    

    and indeed an xml file GoogleDependencyPlayGameServicesPlugin.xml

    <dependencies>
    <dependency><groupId>com.google.android.gms</groupId><artifactId>play-services-games</artifactId><version>8.4+</version></dependency>
    <dependency><groupId>com.google.android.gms</groupId><artifactId>play-services-plus</artifactId><version>8.4+</version></dependency>
    </dependencies>
    

    Now, at one point the former file had ONLY

    play-services-base > OR < play-services-basement

    and that seemed to cause a huge problem. AndroidJavaException: java.lang.NoSuchMethodError: once running on a device.

    Android experts, is it the case that if you have "base" you must have "basement" ... or perhaps vice versa?

    Indeed, WRT play-services-games or play-services-plus, perhaps one/both of those depend in some way (or contradict?) base/basement?

    Zaxaria Geirr 2022-09-25
    How to exclude a file from an .AAR Android library archive with gradle

    I am trying to create an AAR file for a library Android project using Android Studio and gradle.

    I want to exclude from this archive specific folders and files but I cannot find a working solution.

    The project has 2 flavours.

    app/
    |--libs/
    |--src/
       |--flavour1/
       |  |--java/
       |     |--a1/
       |     |  |--class_File1.java
       |--flavour2/
       |  |--java/
       |     |--a1/
       |     |  |--class_File1.java
       |--main/
          |--java/
          |  |--...
          |--res/
          |  |--raw/
          |  |  |--comments.txt
          |  |--...
          |--AndroidManifest.xml
    

    and I use a build.gradle file like this one

    apply plugin: 'com.android.library'
    
    android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
    
    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 21
    }
    packagingOptions {
        exclude 'assets'
        exclude '**/comments.txt'
    }
    
    
    sourceSets {
    
            flavour1 {
                resources {
                    exclude '**/comments.txt'
                }
            }
            flavour2 {
    
            }
    
    }
    
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    
    productFlavors {
    
        flavour1 {
    
           packagingOptions {
                exclude 'assets'
                exclude 'res/raw/comments.txt'
            }
        }
        flavour2 {
        }
    }
    }
    
    dependencies {
    compile 'com.google.android.gms:play-services:+'
    }
    

    Generally speaking, I have experimented a lot. I have tried packagingOptions, exclusion in sourceSets but nothing seems to work. What I am trying to achieve is not include for example in the .AAR archive the file comments.txt and the folder "assets" which is an optional folder. I examine each time the .AAR file by renaming it to zip and looking into the files included.

    I have also looked into the documentation here, where maybe configurations could be a solution but I am not sure how to use it or how to move forward. Any help will be appreciated.

    Manu Signý 2022-09-13