Problems and solutions encountered in upgrading to Android Studio3.0

The problems and solutions encountered in upgrading to Android Studio3.0, Android Studio3.0 is a big update this time. After the upgrade, I found that the compilation has indeed been greatly improved, as well as the latest error debugging tools. In short, the new version of Google is still very sincere.

Problems encountered

1、flavorDimensions

Error log

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

Reason: gradle3.0 needs to use flavorDimensions for multi-version packaging, modify as follows:

android {
//…
defaultConfig {
//…
flavorDimensions “dimen”
}
}

Then make the corresponding changes in productFlavors

productFlavors {
productA { dimension “dimen” }
productB { dimension “dimen” }
}

Configure multiple flavorDimensions

android {
//…
defaultConfig {
//…
flavorDimensions “dimenA”,”dimenB”
}
}
productFlavors {
productA { dimension “dimenA” }
productB { dimension “dimenB” }
productC { dimension “dimenA” }
}

2.apk named
Error Log

Cannot set the value of read-only property ‘outputFile’ for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=busDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl. Open File

The previous code:

applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith(‘.apk’)) {
def fileName = “XXX- de faultConfig.versionCo de d e f a u l t C o n f i g . v e r s i o n C o d e − {defaultConfig.versionName}- releaseTi m e ( ) - r e l e a s e T i m e ( ) − {productFlavors.name[0]}”
if (variant.buildType.name == ‘release’) {
fileName += ‘.apk’
} else if (variant.buildType.name == ‘debug’) {
fileName += ‘_debug.apk’
} else {
fileName += ‘_other.apk’
}
output.outputFile = new File(outputFile.parent, fileName)
}
}
}

Replace gradle3.0 each with all, output.outputFile with outputFileName, no new File is needed, the modified code:

applicationVariants.all { variant ->
variant.outputs.all {
def fileName = “XXX- de faultConfig.versionCo de d e f a u l t C o n f i g . v e r s i o n C o d e − {defaultConfig.versionName}- releaseTi m e ( ) - r e l e a s e T i m e ( ) − {productFlavors.name[0]}”
if (variant.buildType.name == ‘release’) {
fileName += ‘.apk’
} else if (variant.buildType.name == ‘debug’) {
fileName += ‘_debug.apk’
} else {
fileName += ‘_other.apk’
}
outputFileName = fileName
}
}

It should be noted that when using Build->Generate Signed APK..., the generated apk package will be placed in a folder named after the channel name

3.Annotation processors must be explicitly declared now.Please add them to the annotationProcessor configuration.

Error log

Error:Execution failed for task ‘:app:javaPreCompilePreProductDebug’.
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 (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.
修复方案
android {
//…
defaultConfig {
//…
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
}
}

4.Aapt2Exception

Error log

Error:(113, 5) error: style attribute ‘@android:attr/windowEnterAnimation’ not found.
Error:(113, 5) error: style attribute ‘@android:attr/windowExitAnimation’ not found.

Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ‘:app:processPreProductDebugResources’.
Failed to execute aapt

Solution Add the following code in gradle.properties, disable aapt2 compilation
android.enableAapt2=false

5. Other

The new version of gradle does not need to configure buildToolsVersion

dependencies are like this when importing the package
{
implementation fileTree(include: ['*.jar'], dir:'libs')
androidTestImplementation…
implementation project…
implementation files…
implementation…
testImplementation'junit:junit:4.12'
}

Guess you like

Origin blog.csdn.net/hai_jian/article/details/81454443