簡體   English   中英

如何在 android 中將模塊依賴轉換為 aar 依賴?

[英]How to convert a module dependency to aar dependency in android?

我有一個 android 基礎項目,其中有一些可重用的模塊,以便我可以在任何項目中使用它們,我有 4 個模塊依賴項,例如 -

  1. 模塊一
  2. 模塊二
  3. 模塊三
  4. 模塊四

我在 moduleThree 的 gragle 中定義的地方 -

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

這意味着我正在使用 moduleThree 中的所有 3 個模塊。

在我的項目 gradle 文件中,我這樣定義 -

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

在我的應用程序的設置中。gradle 文件 -

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

因此,到目前為止,我在我的應用程序中將其用作模塊,因為我必須復制該文件夾,然后將其粘貼到我的原始項目中。 我發現這是一項乏味的工作,所以我決定創建一個 aar 文件並直接在我的項目中使用它們。

但是當我將所有四個 aars 放入我的項目中時,BI 無法訪問它的資源文件,它拋出了一些異常 - Android 資源鏈接失敗。 噴射。 我努力了

  • 清理項目
  • 使緩存無效並重新啟動
  • 重建項目
  • 刪除構建文件夾

所以我的問題是除了提供我只想提供 aar 文件的所有模塊,然后任何項目都可以將它們添加為依賴項。 我已經生成了 aar 文件,但是在運行項目時遇到了問題-

     <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:錯誤:找不到屬性 tagsBackground(又名 com.example.myproject:tagsBackground)。

注意生成的 Aar 文件是 moduleOne-debug.aar 和 moduleOne-release.aar,我將第一個版本重命名為 moduleOne.aar 並在項目中使用。 可以嗎?

所以真正的問題是,以這種方式創建的 aar 和 jar 不包含它們所依賴的庫。 如果以這種方式添加庫,則需要將其所有依賴項添加到使用它的項目中。

在我的示例中,它是實現 'com.github.mabbas007:TagsEditText:1.0.5',我已將其添加到應用程序 - gradle 文件中,並且在同步后它工作正常。

如果項目包含大量此類依賴項,則應將其全部添加。 但是您仍然可以遇到諸如“清單合並失敗”之類的問題和其他問題。

或者您可以嘗試將您的 lib 部署到 maven 或 jitpack,但您需要正確設置以確保生成的 pom 文件包含所有需要的依賴項,以便能夠輕松使用此庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM