简体   繁体   中英

How to convert a module dependency to aar dependency in android?

I have an android base project where I have some reusable module so that I can use them in any projects, I have 4 module dependency such as -

  1. moduleOne
  2. moduleTwo
  3. moduleThree
  4. moduleFour

Where I have defined in moduleThree's gragle -

    implementation project(':moduleOne')
    implementation project(':moduleTwo')
    implementation project(':moduleFour')

It means I am using all 3 modules in moduleThree.

And in my project gradle file I have defined like this -

    implementation project(':moduleOne')
    implementation project(':moduleTwo')
    implementation project(':moduleThree')
    implementation project(':moduleFour')

And in my app's setting.gradle file -

include ':app', ':moduleOne', ':moduleTwo', ':moduleThree', ':moduleFour'

So as of now I am using in my application as a module for that I have to copy the folder and then I have pasted in my original project. I found it's a tedious job so I decided to create an aar file and directly use them in my project.

But when I am putting all four aars in my project BI am not able to access it's resources files, it's throwing some exception - Android Resources linking failed. Jetified. I have tried

  • Clean the project
  • Invalidate cache and restart
  • Rebuild the project
  • delete build folder

So my problem is except providing all the modules I want to provide only aar files and then any project can add them as a dependency. I have already generated aar file but facing a problem to run the project -

     <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:TagsEditText="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sv_scan_description"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <com.example.moduleThree.ui.TagsEditText
                        android:id="@+id/tagsEditText"
                        style="@style/TextEditTheme"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        TagsEditText:tagsBackground="@drawable/send_to_email_bg"
    ---/>
</ScrollView>

AAPT: error: attribute tagsBackground (aka com.example.myproject:tagsBackground) not found.

Note- generated Aar files were moduleOne-debug.aar and moduleOne-release.aar and I renamed release one to moduleOne.aar and used in project. Is it ok?

So the real problem is that aar and jar created this way do not contain libraries on which they depend. If adding the library this way, you need to add all its dependencies to a project that uses it.

In my example it was implementation 'com.github.mabbas007:TagsEditText:1.0.5', I have added it into app - gradle file and after synching it's working fine.

If the project contains a lot of such dependencies, you should add all of them. But you still can run in problems like "manifest merger failed" and other problems.

Or you can try to deploy your lib to maven or jitpack, but you need to setup this correctly to ensure that pom file will be generated with all needed dependencies, to be able to use this library easily.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM