久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何從 AAR 依賴中排除特定資源?

How To Exclude Specific Resources from an AAR Depedency?(如何從 AAR 依賴中排除特定資源?)
本文介紹了如何從 AAR 依賴中排除特定資源?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

模塊的 build.gradle 文件是否有一種相當簡單的方法來指示應排除依賴項中的某些文件?我對從 AAR 中排除某些資源特別感興趣.

Is there a reasonably simple way for a module's build.gradle file to indicate that certain files from a dependency should be excluded? I am specifically interested in excluding certain resources from an AAR.

LeakCanary 是一個有趣的庫,用于幫助追蹤內存泄漏.但是,它對 compileSdkVersion 的未記錄要求為 21 或更高.雖然大多數項目不應該有這個問題,但庫在沒有充分理由的情況下要求某個 compileSdkVersion 是不合時宜的.開發團隊可能已經凍結了他們的 compileSdkVersion 作為一般政策的一部分,只在他們的應用程序或其他東西的主要版本更新中更改這些類型的設置.

LeakCanary is an interesting library for helping to track down memory leaks. However, it has an undocumented requirement of compileSdkVersion of 21 or higher. While most projects should not have a problem with this, it's unseemly for a library to require a certain compileSdkVersion without a good reason. A development team may have frozen their compileSdkVersion as part of a general policy to only change those sorts of settings as part of major version updates of their app or something.

在這種情況下,至少對于 v1.3.1 的 LeakCanary,AFAICT 需要 compileSdkVersion 的唯一原因是因為 AAR 有一個 res/values-v21/ 目錄,包含從 Theme.Material 繼承的主題定義.此主題由診斷活動使用.最終用戶永遠不會看到該活動,只有在 debug 構建中的開發人員才能看到.坦率地說,那個活動看起來像什么,就主題而言,并不重要.強制 compileSdkVersion 為 21 只是為了讓診斷活動具有特定主題,恕我直言,愚蠢.

In this case, for v1.3.1 of LeakCanary at least, the only reason compileSdkVersion is required, AFAICT, is because the AAR has a res/values-v21/ directory, containing a theme definition that inherits from Theme.Material. This theme is used by a diagnostic activity. That activity is never seen by end users, only by developers in debug builds. Frankly, what that activity looks like, theme-wise, does not really matter. Forcing a compileSdkVersion of 21 just to have that diagnostic activity have a certain theme is, IMHO, stupid.

如果作為 compile 指令的一部分,我們可以說嘿,請跳過這個 AAR 中的 res/values-v21/,好吧?".由于 -v21 主題只是提供了在別處定義的主題的替代定義,因此刪除 -v21 主題不會在運行時破壞構建或破壞事物,而只會給我們一個以 Holo 為主題的診斷活動.

It'd be nice if as part of a compile directive we could say "hey, please skip res/values-v21/ from this AAR, m'kay?". Since the -v21 theme is simply providing an alternative definition of a theme defined elsewhere, dropping the -v21 theme will not break the build or break things at runtime, but merely will give us a Holo-themed diagnostic activity.

我看不到 this answer 如何處理依賴項.我也不確定是否完整,而且它似乎不被支持.它也并不真正符合簡單"的條件—我不希望有人嘗試將其放入 build.gradle 文件中,只是為了阻止來自 LeakCanary 等診斷庫的單個文件.

I fail to see how this answer works with dependencies. I am also uncertain if it is complete, and it certainly does not appear to be supported. It also doesn't really qualify as "simple" — I would not expect somebody to try dropping this in a build.gradle file just to block a single file from a diagnostic library like LeakCanary.

那么,有沒有比這更簡單的方法可以與當前版本的 Android Plugin for Gradle 一起使用?

So, is there something simpler than this that works with now-current editions of the Android Plugin for Gradle?

推薦答案

為您編寫了高級 gradle 任務:

Wrote advanced gradle task for you:

final List<String> exclusions = [];

Dependency.metaClass.exclude = { String[] currentExclusions ->
    currentExclusions.each {
        exclusions.add("${getGroup()}/${getName()}/${getVersion()}/${it}")
    }
    return thisObject
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile ('com.android.support:appcompat-v7:20.+')
    debugCompile ('com.squareup.leakcanary:leakcanary-android:1.3.1')
            .exclude("res/values-v21/values-v21.xml")
    releaseCompile ('com.squareup.leakcanary:leakcanary-android-no-op:1.3.1')
}

tasks.create("excludeTask") << {
    exclusions.each {
        File file = file("${buildDir}/intermediates/exploded-aar/${it}")
        println("Excluding file " + file)
        if (file.exists()) {
            file.delete();
        }
    }
}

tasks.whenTaskAdded({
    if (it.name.matches(/^process.*Resources$/)) {
        it.dependsOn excludeTask
    }
})

現在您可以在每個依賴項上使用方法 .exclude() ,提供到路徑列表中,您想從指定的依賴項中排除.此外,您可以堆疊 .exclude() 方法調用.

Now you can use method .exclude() on each dependency, providing into list of paths, you want to exclude from specified dependency. Also, you can stack the .exclude() method calls.

這篇關于如何從 AAR 依賴中排除特定資源?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

IncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM(更新到 Android Build Tools 25.1.6 GCM/FCM 后出現 IncompatibleClassChangeError)
How to get current flavor in gradle(如何在 gradle 中獲取當前風味)
How to fix quot;unexpected element lt;queriesgt; found in lt;manifestgt;quot; error?(如何修復“意外元素lt;查詢gt;在“清單中找到錯誤?)
Multi flavor app based on multi flavor library in Android Gradle(基于 Android Gradle 中多風味庫的多風味應用)
Android dependency has different version for the compile and runtime(Android 依賴在編譯和運行時有不同的版本)
Transitive dependencies for local aar library(本地 aar 庫的傳遞依賴)
主站蜘蛛池模板: 日韩网站免费观看 | 久久成人一区 | 又黑又粗又长的欧美一区 | 成人伊人| 国产精品久久久久国产a级 欧美日韩国产免费 | 久久久成| 久久久久综合 | 国产精品日韩欧美一区二区 | 日韩精品成人一区二区三区视频 | www.久久| 欧美一级在线 | 亚洲成网 | 日韩精品视频在线 | 久久久91精品国产一区二区三区 | 黄色毛片视频 | h在线免费观看 | www,黄色,com| 日韩视频在线观看中文字幕 | 久久精品国产精品青草 | 国产亚洲一区二区精品 | 日韩午夜一区二区三区 | 精品在线一区 | 在线免费毛片 | 99在线资源 | 天天夜夜操 | 亚洲国产精品一区二区三区 | 91高清视频在线观看 | 在线观看av免费 | 国产高清久久 | 国产免费色| 国产精品一区二区视频 | 91在线网 | 国产精品久久久久久吹潮 | 一二三四在线视频观看社区 | 手机三级电影 | 黄视频免费观看 | 久久一区二区三区四区 | 亚洲免费在线 | 天天综合天天 | 欧洲av在线 | 亚洲免费久久久 |