Android Studio3.0爬坑日记

升级AndroidStudio到3.0之后出现好多问题。抽空总结下,节省大家的爬坑时间:

1、遇到的第一个问题就是发现之前项目的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.

解决方案:在你的app的build中
android {
    ...
    defaultConfig {
        ...
        //添加如下配置就OK了
        javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
    }
    ...
}
原因是3.0后禁用批注处理器错误检查,可以通过设置 includeCompileClasspath true 将行为恢复为 Android 插件2.3.0
2、第二个错误:  
 Error:(22, 5) style attribute '@android:attr/windowEnterAnimation' not found
 Error:(22, 5) style attribute '@android:attr/windowExitAnimation' not found
 Error:(31, 5) style attribute '@android:attr/windowEnterAnimation' not found
 Error:(31, 5) style attribute '@android:attr/windowExitAnimation' not found
 Error:E:\MyProject\Hss\app\build\intermediates\incremental\mergeBaiduDebugResources\merged.dir\values\values.xml:1862 style attribute '@android:attr/windowEnterAnimation' not found
 Error:E:\MyProject\Hss\app\build\intermediates\incremental\mergeBaiduDebugResources\merged.dir\values\values.xml:2545 style attribute '@android:attr/windowEnterAnimation' not found
 Error:failed linking referencesError:java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.AaptException: 
 AAPT2 link failed:Error:com.android.builder.internal.aapt.AaptException: AAPT2 link failed:
 Error:Execution failed for task ':app:processBaiduDebugResources'.
 > Failed to execute aapt(因为当时没有粘贴自己项目的报错信息,这里粘贴别人的说明一下问题)
 解决方案:
 在gradle.properties中关闭APPT2 编译
即在Project/gradle.properties中添加 android.enableAapt2=false,原因还有搞清楚,有清楚的可以留言告诉我,大家互相学习。
  3、在Android Studio3.0打包时,build.gradle文件中
 applicationVariants.all { variant ->  variant.output[0].outputFile.each { output ->  def outputFile = output.outputFile  if (outputFile != null && outputFile.name.endsWith('.apk')) {  outputFileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")  output.outputFile = new File(outputFile.parent, fileName)  }  }  }这段代码会报错:"Cannot set the value of read-only property 'outputFile"更改为:

 android.applicationVariants.all { variant ->  variant.outputs.all {   outputFileName = "_${variant.name}_${variant.versionName}.apk"   }  }

 4、在Android Studio3.0打包的时候会出现打包成功后总是安装失败的问题,具体问题可以参考下面两篇博文:
 http://blog.csdn.net/love_yan_1314/article/details/70184528
 http://blog.csdn.net/zgh0711/article/details/72190165
	5、apt插件问题(Error:Cannot choose between the following configurations of project :mylibrary:):
 Error:Cannot choose between the following configurations of project :mylibrary:
 - debugApiElements
 - debugRuntimeElements
 - releaseApiElements
 - releaseRuntimeElementsAll of them match the consumer attributes:
 解决方案如下:
 1.在project——>build.gradle中注释 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
 2.在app——>build.gradle中注释apply plugin: 'com.neenbedankt.android-apt'
 3.将app——>build.gradle——>dependencies中apt开头的改为annotationProcessor
	   如:

 //    apt 'com.google.dagger:dagger-compiler:2.4'
	annotationProcessor 'com.google.dagger:dagger-compiler:2.4'


你可能感兴趣的:(Android Studio3.0爬坑日记)