android studio升級3.0版本,問題處理
android studio升級3.0版本,問題處理
問題1:編譯版本與構建版本修改
compileSdkVersion : 26,
buildToolsVersion : “26.0.2”,
gradle版本:
distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
classpath ‘com.android.tools.build:gradle:3.0.0’
問題2:apk名稱配置調整,build有一個outputFileName ,直接配置
Error:(120, 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:D:\Android\workspace_zhy\qufish_office\app\build.gradle">Open File</a>
//輸出apk配置
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith(‘.apk‘)) {
// 輸出apk名稱
def fileName
if (variant.buildType.zipAlignEnabled) {
//正式版本
fileName = "XX_${defaultConfig.versionName}_${packageTime()}_${buildType.name}.apk"
} else {
fileName = "XX_${defaultConfig.versionName}_${packageTime()}_${buildType.name}.apk"
}
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
調整後
applicationVariants.all {
outputs.all {
// 輸出apk名稱
def newApkName
if (buildType.zipAlignEnabled) {
newApkName = "XX_${defaultConfig.versionName}_${packageTime()}_${buildType.name}.apk"
} else {
newApkName = "XX_${defaultConfig.versionName}_${packageTime()}_${buildType.name}.apk"
}
outputFileName = newApkName
}
}
問題3:如果你有配置多渠道包,會報錯dimension
//android{}內
flavorDimensions "color"
productFlavors {
baidu {
//每個渠道多家一個這個配置
dimension "color"
...
}
}
問題4:
compile ‘com.android.support:multidex:1.0.1’
倉庫位置調整到google,需要在配置倉庫的地方加入google()(報錯的時候直接點擊下也可以自動添加這個倉庫),另外multidex的版本號升級到1.0.2
allprojects {
repositories {
jcenter()
mavenCentral()
maven { url ‘https://jitpack.io‘ }
google()
}
}
問題5:
Information:Gradle tasks [:pickerview:generateDebugSources, :pickerview:generateDebugAndroidTestSources, :pickerview:mockableAndroidJar, :zhxflib:generateDebugSources, :zhxflib:generateDebugAndroidTestSources, :zhxflib:mockableAndroidJar, :wigetlib:generateDebugSources, :wigetlib:generateDebugAndroidTestSources, :wigetlib:mockableAndroidJar, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar]
D:\zhihuixinfanWorkerSpace\ZhiHuiXinFan\app\build\intermediates\manifests\full\debug\AndroidManifest.xml
Error:(12) error: unknown element found.
Error:(12) unknown element 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:processDebugResources’.
Failed to execute aapt
Information:BUILD FAILED in 8s
Information:6 errors
Information:0 warnings
Information:See complete output in console
解決方法:
在項目的gradle.properties中:
android.enableAapt2=false
android studio升級3.0版本,問題處理