android - 将 Gradle 依赖项 res 复制到另一个 Gradle 依赖项

标签 android gradle

我目前正在为 Android 开发一些插件,遇到了一个问题,即在实现所有插件的最终项目中找不到资源。要部署插件,我使用生成 .aargradlew install,此 .aar 包含 .jar 和包含资源文件的 res 文件夹形成该项目。

问题概述:

Plugin A uses the google com.android.support:cardview-v7:23.2.0 dependency.

Plugin A now has an external library added to the project and can access the cardview res folder.

While compiling Plugin B it uses a resource from Plugin A, which is an instance of the cardview.

This cardview uses a resource file from the res folder in Plugin A.

Plugin B now adds Plugin A as dependency.

Plugin B now has the res folder from Plugin A but still misses resource items from the res folder from the cardview dependency.

此时抛出的错误是:

错误:(8) 在包中找不到属性“cardCornerRadius”的资源标识符...

这是因为Plugin B这样使用cardview:

   <android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="200dp"
        android:layout_height="200dp"
        card_view:cardCornerRadius="4dp">

        <TextView
            android:id="@+id/info_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </android.support.v7.widget.CardView>

在我的项目中找不到缺少的 card_view:cardCornerRadius,因为它从未从 Plugin A 复制到 Plugin B

我的问题如下:

有没有办法让我的 Plugin B 理解什么是 card_view:cardCornerRadius 而无需添加 com.android.support:cardview-v7:23.2. 0 依赖于 Plugin B,而是从 Plugin A 复制过来?

最佳答案

Raymond,aar 没有发布依赖项!至少它不像 jar 那样容易。您需要在您的应用程序中再次重新导入它们(依赖项)。假设 app 使用 plugin-B(aar)。 Plugin-B 使用 plugin-A 作为依赖。 Plugin-B 可以访问 plgin-A 资源,但应用不能。您需要再次将 plugin-A 导入您的应用。请参阅:Documentation:Dependency Management

An artifact only notation creates a module dependency which downloads only the artifact file with the specified extension. Existing module descriptors are ignored.

当从 plguin-B 生成 aar 时,您可以尝试使用对 plugin-A 的传递,例如:

compile ('com.apipas:plugin_a:1.0.0@aar'){
       transitive=true
}

祝你好运,'。

关于android - 将 Gradle 依赖项 res 复制到另一个 Gradle 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36090234/

相关文章:

Android:如何判断被叫号码是否有效

android - getUriForFile() 抛出无法找到包含的已配置根

gradle - Gradle-确定 jar 来自哪个依赖项

Android Studio gradle 风格未在 Build Variants 中显示

android - 如何检查Android应用程序中依赖项的大小?

android - 在android中滚动谷歌地图v2时获取 map 中心点?

安卓相机曝光

java - TextView 拒绝更改文本

android - 使用带有 Gradle 的 Android API 的 Java 模块

sql - 在 Gradle 任务中执行 SQL?