升级了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() 修改版本号
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()
解决:
将1.1.2-3’ -> ‘1.1.2-4’