【AndroidStudio】3.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">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">Add Google Maven repository and sync project</a><br><a href="openFile:G:/Work/Svn/BetaSVN/Tech/Beta.Android/Src/BCP/app/build.gradle">Open File</a><br><a href="open.dependency.in.project.structure">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">Add Google Maven repository and sync project</a><br><a href="openFile:G:/Work/Svn/BetaSVN/Tech/Beta.Android/Src/BCP/app/build.gradle">Open File</a><br><a href="open.dependency.in.project.structure">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">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">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">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.
解决:
  a.修改gradle的版本
  b.增加google() 修改版本号
buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        ...
        classpath 'com.novoda:bintray-release:0.5.0'//修改此处版本号为 0.5.0---修改之前是0.3.4
        ...
    }
}


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">Open File</a>
解决:

没有3.1.0的版本,修改为3.0.0的版本

10、Error:Unable to find method 'com.android.build.gradle.internal.variant.BaseVariantData.getOutputs()

解决:

buildscript {
    ext.kotlin_version = '1.1.2-3'
    repositories {
        maven { url 'https://maven.google.com' }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
将1.1.2-3’ -> ‘1.1.2-4’



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值