天天看點

Android Studio3.0更新gradle遇到的坑

更新了android studio3.0後,對于檔案的搜尋和方法中參數的使用,是一個重大的改變,但更新gradle後,缺出現很多的問題。個人整理一下,希望對大家有所幫助。

說明:我原來的環境是as2.3+gralde2.14.1+plugin2.2.3

更新後的環境是:as3.0+gradle4.2.1+plugin3.0.0

1、

Error:(82, 0) Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.

<a href="openFile:G:\Work\Svn\BetaSVN\Tech\Beta.Android\Src\BCP\app\build.gradle" target="_blank" rel="external nofollow" >Open File</a>

解決:

修改app的檔案輸出格式

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            android.applicationVariants.all { variant ->

                variant.outputs.all {

                    outputFileName = "app_V${defaultConfig.versionName}.apk"

                }

//                variant.outputs.each { output ->

//                    def outputFile = output.outputFile

//                    if (outputFile != null && outputFile.name.endsWith('.apk')) {

//                        //這裡修改apk檔案名

//                        def fileName = "app_V${defaultConfig.versionName}.apk"

//                        output.outputFile = new File(outputFile.parent, fileName)

//                    }

//                }

            }

2、

Error:Failed to resolve: com.android.support:multidex:1.0.2

<a href="add.google.maven.repository" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" >Add Google Maven repository and sync project</a><br><a href="openFile:G:/Work/Svn/BetaSVN/Tech/Beta.Android/Src/BCP/app/build.gradle" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" >Open File</a><br><a href="open.dependency.in.project.structure" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" >Show in Project Structure dialog</a>

解決:

修改build.gradle腳本,增加google()

3、

Error:Failed to resolve: com.android.support:multidex-instrumentation:1.0.2

<a href="add.google.maven.repository" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" >Add Google Maven repository and sync project</a><br><a href="openFile:G:/Work/Svn/BetaSVN/Tech/Beta.Android/Src/BCP/app/build.gradle" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" >Open File</a><br><a href="open.dependency.in.project.structure" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" >Show in Project Structure dialog</a>

解決:

同上

4、

Error:(604, 5) error: expected reference but got (raw string) @+android:style/Animation.Translucent.

解決:

沒有找到好的辦法,最後修改gradle的版本,最後使用4.2.1才解決。

5、

Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details

解決:

修改gradle.properties檔案,增加以下參數配置

android.enableAapt2=false

6、

Error:(23, 0) Cannot set the value of read-only property 'outputFile' for object of type com.android.build.gradle.internal.api.LibraryVariantOutputImpl.

<a href="openFile:G:\Work\Svn\BetaSVN\Tech\Beta.Android\Src\BAWNew\common\build.gradle" target="_blank" rel="external nofollow" >Open File</a>

解決:

修改辦法同第一個

7、

Error:Unable to load class 'org.gradle.api.internal.component.Usage'.

Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

<a href="syncProject" target="_blank" rel="external nofollow" >Re-download dependencies and sync project (requires network)</a></li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.

<a href="stopGradleDaemons" target="_blank" rel="external nofollow" >Stop Gradle build processes (requires restart)</a></li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

解決:

修改gradle的版本

8、

Error:No such property: FOR_RUNTIME for class: org.gradle.api.attributes.Usage

解決:

将gradle的版本從4.3.1降級到4.2.1

9、

Error:Could not find com.android.tools.build:gradle:3.1.0.

Searched in the following locations:

    file:/C:/Program Files/Android/Android Studio3.0/gradle/m2repository/com/android/tools/build/gradle/3.1.0/gradle-3.1.0.pom

    file:/C:/Program Files/Android/Android Studio3.0/gradle/m2repository/com/android/tools/build/gradle/3.1.0/gradle-3.1.0.jar

    https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.0/gradle-3.1.0.pom

    https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.0/gradle-3.1.0.jar

    https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.0/gradle-3.1.0.pom

    https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.0/gradle-3.1.0.jar

Required by:

    project :

<a href="openFile:G:\Work\Svn\BetaSVN\Tech\Beta.Android\Src\BAWNew_bak\build.gradle" target="_blank" rel="external nofollow" >Open File</a>

解決:

沒有3.1.0的版本,修改為3.0.0的版本

繼續閱讀