How to manually include external aar package using new Gradle Android Build System

后端 未结 23 1799
故里飘歌
故里飘歌 2020-11-22 03:58

I\'ve been experimenting with the new android build system and I\'ve run into a small issue. I\'ve compiled my own aar package of ActionBarSherlock which I\'ve called \'act

相关标签:
23条回答
  • 2020-11-22 04:15

    I tried all solution here but none is working, then I realise I made a mistake, I put the .aar in wrong folder, as you can see below, I thought I should put in root folder, so I created a libs folder there (1 in picture), but inside the app folder, there is already a libs, you should put in second libs, hope this help those who has same issue as mine:

    0 讨论(0)
  • 2020-11-22 04:17

    Please follow below steps to get it working ( I have tested it up to Android Studio 2.2)

    Lets say you have kept aar file in libs folder. ( assume file name is cards.aar )

    then in app build.gradle specify following and click sync project with Gradle files. Open Project level build.gradle and add flatDir{dirs 'libs'} like did below

    allprojects {
       repositories {
          jcenter()
          flatDir {
            dirs 'libs'
          }
       }
    }
    

    and now open app level build.grdle file and add .aar file

        dependencies {
           implementation(name:'cards', ext:'aar')
    }
    

    If everything goes well you will see library entry is made in build -> exploded-aar

    Also note that if you are importing a .aar file from another project that has dependencies you'll need to include these in your build.gradle, too.

    0 讨论(0)
  • 2020-11-22 04:17

    Add below line in app level build.gradle

      implementation fileTree(dir: "libs", include: ["*.aar"])
    

    Change Project structure from Android to Project.

    Navigaate to app->libs as below

    Then paste "aar" in libs folder.

    Click on File at top left of android studio and click "Sync Project with Gradle Files" as below.

    That's it.

    0 讨论(0)
  • 2020-11-22 04:20

    UPDATE ANDROID STUDIO 3.4

    1. Go to File -> Project Structure

    1. Modules and click on +

    1. Select Import .aar Package

    1. Find the .aar route

    1. Finish and Apply, then verify if package is added

    1. Now in the app module, click on + and Module Dependency

    1. Check the library package and Ok

    1. Verify the added dependency

    1. And the project structure like this

    0 讨论(0)
  • 2020-11-22 04:21
    1. Right click on your project and select "Open Module Settings".

    1. Click the "+" button in the top left corner of window to add a new module.

    1. Select "Import .JAR or .AAR Package" and click the "Next" button.

    1. Find the AAR file using the ellipsis button "..." beside the "File name" field.

    1. Keep the app's module selected and click on the Dependencies pane to add the new module as a dependency.

    1. Use the "+" button of the dependencies screen and select "Module dependency".

    1. Select the module and click "OK".

    0 讨论(0)
  • 2020-11-22 04:24

    before(default)

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    

    just add '*.aar' in include array.

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

    it works well on Android Studio 3.x.

    if you want ignore some library? do like this.

    implementation fileTree(include: ['*.jar', '*.aar'], exclude: 'test_aar*', dir: 'libs')
    debugImplementation files('libs/test_aar-debug.aar')
    releaseImplementation files('libs/test_aar-release.aar')
    
    0 讨论(0)
提交回复
热议问题