I used AndroidStudio2.2.1 before and then upgraded to AndroidStudio3.0.1 and
encountered the following problems:
1. Declaring custom 'clean' task when using
Error:(48, 1) A problem occurred evaluating root project 'NEWAPP'.
> Declaring custom 'clean' task when using the standard Gradle lifecycle plugins is not allowed.
- 1
- 2
Solution:
From: http://blog.csdn.net/poorkick/article/details/72599929
Relentlessly comment out the clean task in build.gradle.
//task clean(type: Delete) {
// delete rootProject.buildDir
//}
- 1
- 2
- 3
2,No service of type Factory
Error:No service of type Factory<LoggingManagerInternal> available in ProjectScopeServices.
- 1
clean project. Problem 3
3, Could not create plugin of type 'AndroidMavenPlugin'.
Warning:The specified Android SDK Build Tools version (24.0.2) is ignored, as it is below the minimum supported version (26.0.2) for Android Gradle Plugin 3.0.1.
Android SDK Build Tools 26.0.2 will be used.
To suppress this warning, remove "buildToolsVersion '24.0.2'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
Information:BUILD FAILED in 2s
Error:FAILURE: Build failed with an exception.
* Where:
Script 'https://raw.githubusercontent.com/Commit451/gradle-android-javadocs/1.0.0/gradle-android-javadocs.gradle' line: 17
* What went wrong:
A problem occurred evaluating script.
> Failed to apply plugin [id 'com.github.dcendents.android-maven']
> Could not create plugin of type 'AndroidMavenPlugin'.
> No service of type Factory<LoggingManagerInternal> available in ProjectScopeServices.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
Solution:
From: http://blog.csdn.net/suwenlai/article/details/55046644
will
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath group: 'com.zeroc.gradle.ice-builder', name: 'slice', version: '1.3.14'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4'
}
- 1
- 2
- 3
- 4
- 5
Before classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4' was version 1.3, replaced with 1.4
4, replaced with buildToolsVersion "26.0.2"
build.gradle里的buildToolsVersion在gradle3.0.1中对应的是26.0.2
buildToolsVersion "26.0.2"
这个问题是Android studio升级到3.0之后,运行的时候会提示gradle要升级到3.5版本才能编译。于是我把我的gradle升级到了
- Error:All flavors must now belong to a named flavor dimension.
- The flavor 'flavor_name' is not assigned to a flavor dimension.
- // Specifies a flavor dimension.
- flavorDimensions "color"
- productFlavors {
- red {
- // Assigns this product flavor to the 'color' flavor dimension.
- // This step is optional if you are using only one dimension.
- dimension "color"
- ...
- }
- blue {
- dimension "color"
- ...
- }
- }
5.体验最新版AndroidStudio3.0 Canary 8的时候,发现之前项目的butter knife报错,用到注解的应该都会报错 Error:Execution failed for task ':app:javaPreCompileDebug'. > Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration. - butterknife-7.0.1.jar Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior. Note that this option is deprecated and will be removed in the future. See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details. 在appIn the build , android { ... defaultConfig { ... // It is OK to add the following configuration javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } } } ... }
6. Detailed error report:
Error:(45, 0) Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=xiaomiDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
<a href="openFile:H:\CloudMus\app\build.gradle">Open File</a>
- 1
- 2
Location:
// 自定义输出配置
// applicationVariants.all { variant ->
// variant.outputs.each { output ->
// def outputFile = output.outputFile
// if (outputFile != null && outputFile.name.endsWith('.apk')) {
// // 输出apk名称为great_v1.0_wandoujia.apk
// def fileName = "great${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"
// output.outputFile = new File(outputFile.parent, fileName)
// }
// }
// }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
Android plugin 3.0 is recommended
Use all() instead of each()
Use outputFileName instead of output.outputFile if you change only file name (that is your case)
example:
// If you use each() to iterate through the variant objects,
// you need to start using all(). That's because each() iterates
// through only the objects that already exist during configuration time—
// but those object don't exist at configuration time with the new model.
// However, all() adapts to the new model by picking up object as they are
// added during execution.
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${variant.name}-${variant.versionName}.apk"
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
Therefore, modify the above writing:
applicationVariants.all { variant ->
variant.outputs.all {
// 输出apk名称为great_v1.0_wandoujia.apk
def fileName = "great${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"
outputFileName = fileName
}
}
7.Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForAlibabaDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Solution: Multidex enable true or clean rebuild project