更新Android Studio 3.0碰到的問題

來源:互聯網
上載者:User

標籤:size   tool   iss   default   ***   一個   null   時間   build   

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

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已經是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

 

 

繼續編譯繼續出錯

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

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

http://blog.csdn.net/syif88/article/details/75009663

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

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

 

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

 

更新Android Studio 3.0碰到的問題

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.