pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

從 gradle 構建 Android 項目時找不到參數的方法 a

Could not find method android() for arguments when building Android project from gradle(從 gradle 構建 Android 項目時找不到參數的方法 android())
本文介紹了從 gradle 構建 Android 項目時找不到參數的方法 android()的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個基于 gradle 的 Android 項目,其中包含 4 個子模塊 - 兩個庫和兩個應用程序.我試圖通過將一些共享代碼/配置移動到頂級 build.gradle 文件并使用 subprojects {} 使該代碼可供每個子模塊使用,從而簡化每個子模塊的 build.gradle 文件子模塊.

I have an gradle-based Android project with 4 submodules - two libraries and two applications. I was trying to simplify the build.gradle files of each submodule by moving some of of the shared code/configurations to the top level build.gradle file and use subprojects {} to make that code available to each submodule.

文件系統結構如下:

Root
 |- App1/
 |- App2/
 |- Lib1/
 |- Lib2/
 |- build.gradle
 |- settings.gradle

問題是,如果我將 android {} 部分添加到子項目中,那么 gradle 任務就會失敗.例如,這是我的頂級 build.gradle 文件:

The problem is that if I add an android {} section to the subprojects then gradle tasks fail. For example, this is my top-level build.gradle file:

subprojects { project ->
  android {
    buildToolsVersion "20.0.0"
  }
}

運行 gradle 會返回:

Running gradle returns this:

出了什么問題:評估根項目android"時出現問題.在根項目android"上找不到參數 [build_7dngpra6ldok366maq0on77r7e$_run_closure3_closure5@43d95624] 的方法 android().

What went wrong: A problem occurred evaluating root project 'android'. Could not find method android() for arguments [build_7dngpra6ldok366maq0on77r7e$_run_closure3_closure5@43d95624] on root project 'android'.

我搜索了類似的帖子,有些人建議將 apply plugin: 'android' 行添加到每個子項目中,以公開 gradle 缺少的 android() 方法正在抱怨.但是,該解決方案對我不起作用,因為它會有效地將該行添加到庫項目中,這需要 apply plugin: 'android-library' 代替.

I searched for similar posts and some people suggest adding the line apply plugin: 'android' to each subproject in order to expose the missing android() method that gradle is complaining about. However, that solution doesn't work for me because it would effectively add that line to library project, which require apply plugin: 'android-library' instead.

當您在同一個項目中有應用程序和庫時,有沒有辦法在 subprojects {} 中使用 android {}?

Is there a way to use android {} inside of subprojects {} when you have apps and libraries in the same project?

推薦答案

這實際上是對 android-gradle 插件結構方式的限制,android 工具網站.

This is actually a limitation on the way that the android-gradle plugin is structured and there is a workaround documented at the android tools website.

如果您有很多 Android 模塊,您可能希望避免在所有模塊中手動設置相同的值.因為您可能混合了 android 和 android-library 項目,所以您不能通過子項目閉包應用這些插件.

If you have a lot of Android modules, you may want to avoid manually setting the same values in all of them. Because you probably have a mix of android and android-library project you can't apply these plugins through a subprojects closure.

建議的解決方案是:

...在根項目的 build.gradle 中:

...in the root project's build.gradle:

ext {
  compileSdkVersion = 19
  buildToolsVersion = "19.0.1"
}

在所有安卓模塊中:

android {
  compileSdkVersion rootProject.ext.compileSdkVersion
  buildToolsVersion rootProject.ext.buildToolsVersion
}

...

我注意到的一個想法是,這不適用于舊版本的 gradle(我嘗試使用 1.10 并遇到錯誤).不過,對于 Gradle 2.1,這似乎可以正常工作.

One think I noticed was that this doesn't work on older versions of gradle (I was trying with 1.10 and got an error). With Gradle 2.1 this seems to work correctly though.

這篇關于從 gradle 構建 Android 項目時找不到參數的方法 android()的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 庫的傳遞依賴)
主站蜘蛛池模板: 硫酸钡厂家_高光沉淀硫酸钡价格-河南钡丰化工有限公司 | 雄松华章(广州华章MBA)官网-专注MBA/MPA/MPAcc/MEM辅导培训 | VOC检测仪-甲醛检测仪-气体报警器-气体检测仪厂家-深恒安科技有限公司 | 郑州大巴车出租|中巴车租赁|旅游大巴租车|包车|郑州旅游大巴车租赁有限公司 | 六维力传感器_六分量力传感器_模腔压力传感器-南京数智微传感科技有限公司 | 南京欧陆电气股份有限公司-风力发电机官网 | 螺纹三通快插接头-弯通快插接头-宁波舜驰气动科技有限公司 | 不锈钢复合板|钛复合板|金属复合板|南钢集团安徽金元素复合材料有限公司-官网 | X光检测仪_食品金属异物检测机_X射线检测设备_微现检测 | 高考志愿规划师_高考规划师_高考培训师_高报师_升学规划师_高考志愿规划师培训认证机构「向阳生涯」 | 济南画室培训-美术高考培训-山东艺霖艺术培训画室 | 体感VRAR全息沉浸式3D投影多媒体展厅展会游戏互动-万展互动 | 微信小程序定制,广州app公众号商城网站开发公司-广东锋火 | 博医通医疗器械互联网供应链服务平台_博医通 | HDPE储罐_厂家-山东九州阿丽贝防腐设备| 河南空气能热水器-洛阳空气能采暖-洛阳太阳能热水工程-洛阳润达高科空气能商行 | 变色龙云 - 打包app_原生app_在线制作平台_短链接_ip查询 | 无缝钢管-聊城无缝钢管-小口径无缝钢管-大口径无缝钢管 - 聊城宽达钢管有限公司 | 济南办公室装修-厂房装修-商铺装修-工装公司-山东鲁工装饰设计 | 云南成考网_云南成人高考报名网| 消泡剂-水处理消泡剂-涂料消泡剂-切削液消泡剂价格-东莞德丰消泡剂厂家 | 蓝牙音频分析仪-多功能-四通道-八通道音频分析仪-东莞市奥普新音频技术有限公司 | 直齿驱动-新型回转驱动和回转支承解决方案提供商-不二传动 | 欧洲MV日韩MV国产_人妻无码一区二区三区免费_少妇被 到高潮喷出白浆av_精品少妇自慰到喷水AV网站 | 工业淬火油烟净化器,北京油烟净化器厂家,热处理油烟净化器-北京众鑫百科 | 深圳法律咨询【24小时在线】深圳律师咨询免费 | LED显示屏_LED屏方案设计精准报价专业安装丨四川诺显科技 | 液压中心架,数控中心架,自定心中心架-烟台恒阳机电设计有限公司 行星搅拌机,双行星搅拌机,动力混合机,无锡米克斯行星搅拌机生产厂家 | 中国产业发展研究网 - 提供行业研究报告 可行性研究报告 投资咨询 市场调研服务 | 集菌仪厂家_全封闭_封闭式_智能智能集菌仪厂家-上海郓曹 | 汕头市盛大文化传播有限公司,www.11400.cc | 不锈钢酒柜|恒温酒柜|酒柜定制|酒窖定制-上海啸瑞实业有限公司 | 亚克力制品定制,上海嘉定有机玻璃加工制作生产厂家—官网 | 天然鹅卵石滤料厂家-锰砂滤料-石英砂滤料-巩义东枫净水 | 玻璃钢格栅盖板|玻璃钢盖板|玻璃钢格栅板|树篦子-长沙川皖玻璃钢制品有限公司 | 华溶溶出仪-Memmert稳定箱-上海协烁仪器科技有限公司 | 合肥触摸一体机_触摸查询机厂家_合肥拼接屏-安徽迅博智能科技 | 沈阳缠绕膜价格_沈阳拉伸膜厂家_沈阳缠绕膜厂家直销 | 政府园区专业委托招商平台_助力企业选址项目快速落地_东方龙商务集团 | 芜湖厨房设备_芜湖商用厨具_芜湖厨具设备-芜湖鑫环厨具有限公司 控显科技 - 工控一体机、工业显示器、工业平板电脑源头厂家 | 慈溪麦田广告公司,提供慈溪广告设计。 |