gradle tool升級到3.0注意事項

Gradle版本升級

其實當AS升級到3.0之后,Gradle Plugin和Gradle不升級也是可以繼續使用的,但很多新的特性如:Java8支持、新的依賴匹配機制、AAPT2等新功能都無法正常使用。

Gradle Plugin升級到3.0.0及以上,修改project/build.gradle文件:

修改global.gradle(自定義lib管理的gradle)
tools = [gradleTools      : 'com.android.tools.build:gradle:3.0.1'
]修改project/build.gradle文件buildscript {repositories {google()}apply from: 'global.gradle' def tools = rootProject.ext.tools dependencies { classpath tools.gradleTools } }

Gradle升級到4.1及以上,修改project/gradle/gradle-wrapper.properties文件

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
生成APK文件名屬性outputFile變為只讀

在app module中修改build.gradle文件之前改apk名字的代碼

variant.outputs.each { output ->def outputFile = output.outputFileif (outputFile != null && outputFile.name.endsWith('.apk')) {def fileName = "host_${variant.buildType.name}_${variant.productFlavors[0].name}_${mApplicationId}_${defaultConfig.versionCode}_v${mVersionName}.apk" output.outputFile = new File(outputFile.parent, fileName) } }

由于outputFile屬性變為只讀,需要進行如下修改,直接對outputFileName屬性賦值即可:

variant.outputs.all {outputFileName = "host_${variant.buildType.name}_${variant.productFlavors[0].name}_${mApplicationId}_${defaultConfig.versionCode}_v${mVersionName}.apk" }
依賴關鍵字的改變
  • api: 對應之前的compile關鍵字,功能一模一樣。會傳遞依賴,導致gradle編譯的時候遍歷整顆依賴樹
  • implementation: 對應之前的compile,與api類似,關鍵區別是不會有依賴傳遞
  • compileOnly: 對應之前的provided,依賴僅用于編譯期不會打包進最終的apk中
  • runtimeOnly: 對應之前的’apk’,與上面的compileOnly相反

關于implementation與api的區別,主要在依賴是否會傳遞上。如:A依賴B,B依賴C,若使用api則A可以引用C,而implementation則不能引用。

這里更推薦用implementation,一是不會間接的暴露引用,清晰知道目前項目的依賴情況;二是可以提高編譯時依賴樹的查找速度,進而提升編譯速度。 渠道需要聲明flavor dimensions

剛開始Sync的時候應該會報錯:
Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html

也就是每個flavor渠道都必須歸屬一個dimension維度,若只有一個維度,渠道中可以不寫dimension屬性,默認分配到該維度。直接添加一個默認的維度即可,如:flavorDimensions "dimension"

解決方法是在app.gradle添加flavorDimensions

defaultConfig {flavorDimensions  getVersion("VERSION_CODE")
}

也可以像官方文檔那樣設置多個維度

// Specifies two flavor dimensions.
flavorDimensions "mode", "minApi"
productFlavors {free { // Assigns this product flavor to the "tier" flavor dimension. Specifying // this property is optional if you are using only one dimension. dimension "mode" ... } paid { dimension "mode" ... } minApi23 { dimension "minApi" ... } minApi18 { dimension "minApi" ... } }
庫多variant依賴方式的修改

Gradle plugin 3.0.0+之后引入了新的variant自動匹配機制,也就是說app的flavorDebug變體會自動匹配library的flavorDebug變體。

回顧一下舊的方式,如果app在某個variant下需要依賴library相應的類型,需要按照下面的方式聲明依賴:

dependencies {hytestCompile project(path: ':main', configuration: 'hytestRelease') productionCompile project(path: ':main', configuration: 'productionRelease') }

新的方式,gradle會自動感知并匹配對應的variant(前提是app與library中有對應的variant類型):

dependencies {implementation project(':main')
}
填坑

1、style attribute ‘@android:attr/windowEnterAnimation’ not found. 這是aapt2導致的,3.0默認啟用了aapt2。解決辦法:在project的根目錄下的gradle.properties最后添加關閉aapt2的代碼:

android.enableAapt2=false

2、gradle tool 3.0使用最低SDK buildTool 26.0.2的版本

3、使用了aapt的需要去除掉,改用annotationProcessor

4、注意引用第三方庫的時候com.android.support包的版本需要統一,不然在multidex會導致異常或者build的時候無法build success

轉載于:https://www.cnblogs.com/fomin/p/8424478.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390234.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390234.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390234.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

如何使用React,TypeScript和React測試庫創建出色的用戶體驗

Im always willing to learn, no matter how much I know. As a software engineer, my thirst for knowledge has increased a lot. I know that I have a lot of things to learn daily.無論我知道多少,我總是愿意學習。 作為軟件工程師,我對知識的渴望…

PowerDesigner常用設置

2019獨角獸企業重金招聘Python工程師標準>>> 使用powerdesigner進行數據庫設計確實方便,以下是一些常用的設置 附加:工具欄不見了 調色板(Palette)快捷工具欄不見了 PowerDesigner 快捷工具欄 palette 不見了,怎么重新打開&#x…

bzoj5090[lydsy11月賽]組題

裸的01分數規劃,二分答案,沒了. #include<cstdio> #include<algorithm> using namespace std; const int maxn100005; int a[maxn]; double b[maxn]; double c[maxn]; typedef long long ll; ll gcd(ll a,ll b){return (b0)?a:gcd(b,a%b); } int main(){int n,k;s…

797. 所有可能的路徑

797. 所有可能的路徑 給你一個有 n 個節點的 有向無環圖&#xff08;DAG&#xff09;&#xff0c;請你找出所有從節點 0 到節點 n-1 的路徑并輸出&#xff08;不要求按特定順序&#xff09; 二維數組的第 i 個數組中的單元都表示有向圖中 i 號節點所能到達的下一些節點&#…

深入框架本源系列 —— Virtual Dom

該系列會逐步更新&#xff0c;完整的講解目前主流框架中底層相通的技術&#xff0c;接下來的代碼內容都會更新在 這里 為什么需要 Virtual Dom 眾所周知&#xff0c;操作 DOM 是很耗費性能的一件事情&#xff0c;既然如此&#xff0c;我們可以考慮通過 JS 對象來模擬 DOM 對象&…

網絡工程師常備工具_網絡安全工程師應該知道的10種工具

網絡工程師常備工具If youre a penetration tester, there are numerous tools you can use to help you accomplish your goals. 如果您是滲透測試人員&#xff0c;則可以使用許多工具來幫助您實現目標。 From scanning to post-exploitation, here are ten tools you must k…

configure: error: You need a C++ compiler for C++ support.

安裝pcre包的時候提示缺少c編譯器 報錯信息如下&#xff1a; configure: error: You need a C compiler for C support. 解決辦法&#xff0c;使用yum安裝&#xff1a;yum -y install gcc-c 轉載于:https://www.cnblogs.com/mkl34367803/p/8428264.html

程序編寫經驗教訓_編寫您永遠都不會忘記的有效績效評估的經驗教訓。

程序編寫經驗教訓This article is intended for two audiences: people who need to write self-evaluations, and people who need to provide feedback to their colleagues. 本文面向兩個受眾&#xff1a;需要編寫自我評估的人員和需要向同事提供反饋的人員。 For the purp…

刪除文件及文件夾命令

方法一&#xff1a; echo off ::演示&#xff1a;刪除指定路徑下指定天數之前&#xff08;以文件的最后修改日期為準&#xff09;的文件。 ::如果演示結果無誤&#xff0c;把del前面的echo去掉&#xff0c;即可實現真正刪除。 ::本例需要Win2003/Vista/Win7系統自帶的forfiles命…

BZOJ 3527: [ZJOI2014]力(FFT)

題意 給出\(n\)個數\(q_i\),給出\(Fj\)的定義如下&#xff1a; \[F_j\sum \limits _ {i < j} \frac{q_iq_j}{(i-j)^2}-\sum \limits _{i >j} \frac{q_iq_j}{(i-j)^2}.\] 令\(E_iF_i/q_i\)&#xff0c;求\(E_i\). 題解 一開始沒發現求\(E_i\)... 其實題目還更容易想了... …

c# 實現刷卡_如何在RecyclerView中實現“刷卡選項”

c# 實現刷卡Lets say a user of your site wants to edit a list item without opening the item and looking for editing options. If you can enable this functionality, it gives that user a good User Experience. 假設您網站的用戶想要在不打開列表項并尋找編輯選項的情…

批處理命令無法連續執行

如題&#xff0c;博主一開始的批處理命令是這樣的&#xff1a; cd node_modules cd heapdump node-gyp rebuild cd .. cd v8-profiler-node8 node-pre-gyp rebuild cd .. cd utf-8-validate node-gyp rebuild cd .. cd bufferutil node-gyp rebuild pause執行結果&#xff1…

sql語句中的in用法示例_示例中JavaScript in操作符

sql語句中的in用法示例One of the first topics you’ll come across when learning JavaScript (or any other programming language) are operators. 學習JavaScript(或任何其他編程語言)時遇到的第一個主題之一是運算符。 The most common operators are the arithmetic, l…

vue項目實戰總結

馬上過年了&#xff0c;最近工作不太忙&#xff0c;再加上本人最近比較懶&#xff0c;毫無斗志&#xff0c;不愿學習新東西&#xff0c;或許是要過年的緣故(感覺像是在找接口)。 就把前一段時間做過的vue項目&#xff0c;進行一次完整的總結。 這次算是詳細總結&#xff0c;會從…

Linux !的使用

轉自&#xff1a;https://www.linuxidc.com/Linux/2015-05/117774.htm 一、history    78 cd /mnt/ 79 ls 80 cd / 81 history 82 ls 83 ls /mnt/ !78 相當于執行cd /mnt !-6 也相當于執行cd /mnt 二、!$ cd /mnt ls !$ 相當于執行 ls /mnt轉載于:https://www.cnblogs.…

881. 救生艇

881. 救生艇 第 i 個人的體重為 people[i]&#xff0c;每艘船可以承載的最大重量為 limit。 每艘船最多可同時載兩人&#xff0c;但條件是這些人的重量之和最多為 limit。 返回載到每一個人所需的最小船數。(保證每個人都能被船載)。 示例 1&#xff1a; 輸入&#xff1a;…

使用python數據分析_如何使用Python提升您的數據分析技能

使用python數據分析If youre learning Python, youve likely heard about sci-kit-learn, NumPy and Pandas. And these are all important libraries to learn. But there is more to them than you might initially realize.如果您正在學習Python&#xff0c;則可能聽說過sci…

openresty 日志輸出的處理

最近出了個故障&#xff0c;有個接口的請求居然出現了長達幾十秒的處理時間&#xff0c;由于日志缺乏&#xff0c;網絡故障也解除了&#xff0c;就沒法再重現這個故障了。為了可以在下次出現問題的時候能追查到問題&#xff0c;所以需要添加一些追蹤日志。添加這些追蹤日志&…

誰是贏家_贏家的真正作品是股東

誰是贏家As I wrote in the article “5 Skills to Look For When Hiring Remote Talent,” remote work is a fast emerging segment of the labor market. Today roughly eight million Americans work remotely full-time. And among the most commonly held jobs include m…

博客園代碼黑色主題高亮設置

參考鏈接&#xff1a; https://segmentfault.com/a/1190000013001367 先發鏈接&#xff0c;有空實踐后會整理。我的GitHub地址&#xff1a;https://github.com/heizemingjun我的博客園地址&#xff1a;http://www.cnblogs.com/chenmingjun我的螞蟻筆記博客地址&#xff1a;http…