更新AndroidStudio3.0碰到的問題有哪些

這篇文章主要介紹更新Android Studio 3.0碰到的問題有哪些,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設、高性價比文安網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式文安網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設找我們,業(yè)務覆蓋文安地區(qū)。費用合理售后完善,10年實體公司更值得信賴。

更新完后試下運行正在維護的舊項目,出現(xiàn)各種錯誤,因為后來發(fā)現(xiàn)問題不在這,所以沒記完整,大概如下:

A larger heap for the Gradle daemon is recommended for running jack.

It currently has 512 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to at least 1536 MB.
To do this set org.gradle.jvmargs=-Xmx1536M in the project gradle.properties.

然后查看gradle.properties我的org.gradle.jvmargs已經(jīng)是2048了,另外還有個Error:UNEXPECTED TOP-LEVEL ERROR:錯誤

搜索了一下并沒找到要點,于是Build一下項目,提示

Error:Failed to complete Gradle execution.

Cause:

The version of Gradle you are using (3.3) does not support the forTasks() method on BuildActionExecuter. Support for this is available in Gradle 3.5 and all later versions.

于是更新使用Gradle最新版,新建一個項目看看默認用的什么版本,修改以下文件

gradle-wrapper.properties里

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

APP的build.gradle里

dependencies {
  classpath 'com.android.tools.build:gradle:3.0.0'
}

編譯后又有錯

Cannot set the value of read-only property 'outputFile'....

因為使用了編譯輸出文件名的代碼

applicationVariants.all { variant ->
 variant.outputs.each { output ->
 def outputFile = output.outputFile
 def fileName
 if (outputFile != null && outputFile.name.endsWith('.apk')) {
  if (variant.buildType.name.equals('release')) {
  // 輸出apk名稱為Test_v_1.0_15-09-15 11:12:32_official_release.apk
  fileName = "Test_v_${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}_release.apk"
  } else if (variant.buildType.name.equals('debug')) {
  // 輸出apk名稱為Test_v_1.0_15-09-15 11:12:32_official_debug.apk
  fileName = "Test_v_${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}_debug.apk"
  }
  output.outputFile = new File(outputFile.parent, fileName)
 }
 }
}

出錯在最后一行,應該是新版Gradle的問題,最后在Stackover Flow找到解決辦法,參考

https://stackoverflow.com/questions/44239235/android-gradle-3-0-0-alpha2-plugin-cannot-set-the-value-of-read-only-property

variant.outputs.each 改成

     variant.outputs.all

最后一行改成

outputFileName = fileName

繼續(xù)編譯繼續(xù)出錯

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

百度找到以下文章,修改后就可以正常編譯運行了

https://www.jb51.net/article/127673.htm

看了幾個文章也搞不清楚這個是什么來的,照著改項目的build.gradle

defaultConfig {
 targetSdkVersion:***
 minSdkVersion :***
 versionCode:***
 versionName :***
 //版本名后面添加一句話,意思就是flavor dimension 它的維度就是該版本號,這樣維度就是都是統(tǒng)一的了
 flavorDimensions "versionCode"
}

項目的其它代碼不用改,文章開頭的錯誤全沒了,還好沒浪費太多時間

PS:下面看下更新AndroidStudio到3.0后遇到的一個編譯問題

今天晚上更新了AndroidStudio,可是再用這個就發(fā)現(xiàn)一個編譯問題:

Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details 
Error:Execution failed for task ':app:mergeDebugResources'. 
> Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details 

通過google,發(fā)現(xiàn)了解決辦法:

在項目的gradle.properties中添加

android.enableAapt2=false 

目前還沒搞懂為什么,先留在這里吧

以上是“更新Android Studio 3.0碰到的問題有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

當前題目:更新AndroidStudio3.0碰到的問題有哪些
標題鏈接:http://muchs.cn/article48/ipjdhp.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、品牌網(wǎng)站建設建站公司、網(wǎng)站策劃軟件開發(fā)、定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應式網(wǎng)站建設