Android Studio的自带Gradle版本是4.1,插件版本是3.0.0,所以如果你使用的是老版本,就会出现一些小的兼容问题,我们看看报了哪些错误呢:

问题1

Error:(72, 0) Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=appDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.

outputFile是只读属性,不可以对他进行修改

看一下我的gradle里面的代码:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 // 定义生成的apk的名称 def apkName;   buildTypes {   release {    ...    // 定义release版本生成的apk的名字    apkName = "xxx" + VERSION_NAME + "_release.apk";   }   debug {    ...    // 定义debug版本生成的apk的名字    apkName = "ugirls_" + VERSION_NAME + "_debug.apk";   } }   // 修改apk build的名字 android.applicationVariants.all { variant ->   variant.outputs.each { output ->    def outputFile = output.outputFile    if (outputFile != null && outputFile.name.endsWith('.apk')) {      //这里使用之前定义apk文件名称      output.outputFile = new File(outputFile.parent, apkName)    }   } }

这段代码的功能是修改Build命令生成的apk的名称,因为outputFile变成只读属性,所以报错。

修改后:

?
1 2 3 4 5 6 7 8 9 10 // 之前代码保持不变 // 修改apk build的名字 android.applicationVariants.all { variant ->   variant.outputs.all {    if (outputFileName.endsWith('.apk')) {     //这里使用之前定义apk文件名称     outputFileName = apkName    }   } }

把each修改为all,然后通过outputFileName修改生成的apk的名称。

如果你提示没有找到all方法或者是未找到outputFileName,你可以先把这个功能注释掉,等其他问题都解决了,再打开就可以解决这个问题了。

问题2

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

所有的flavor属性应当属于同一个命名空间

看着问题似乎有点深奥,其实就是需要我们为flavors设置一个版本,统一使用相同版本的flavors。

?
1 2 3 4 5 6 7 8 defaultConfig {   targetSdkVersion:***   minSdkVersion :***   versionCode:***   versionName :***   //为flavor设置一个版本,命名是随意的   flavorDimensions "versionCode" }

问题3


有些库不能被正常引用,例如我使用的multidex,在上面的截图中已经提示我们如何解决这个问题

?
1 2 3 4 5 6 7 8 9 10 buildscript {   repositories {    ...    // 添加google库的依赖    google()   }   dependencies {    ...   } }

问题4

Error:(2638) error: style attribute '@android:attr/windowEnterAnimation' not found.

提示我们找不到@android:attr/windowEnterAnimation,因为已经不支持@开头使用android自带的属性,我们只要把@符号删掉就可以了。

修改前:

?
1 2 3 4 < style name = "ToastStyle" parent = "android:Animation" >    < item name = "@android:windowEnterAnimation" >@anim/push_fade_in item >    < item name = "@android:windowExitAnimation" >@anim/push_fade_out item > style >

修改后:

?
1 2 3 4 < style name = "ToastStyle" parent = "android:Animation" >    < item name = "android:windowEnterAnimation" >@anim/push_fade_in item >    < item name = "android:windowExitAnimation" >@anim/push_fade_out item > style >

问题5

Error:Execution failed for task ':app:javaPreCompileAppDebug'.
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-6.1.0.jar (com.jakewharton:butterknife:6.1.0)
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.

好多的错误日志啊,其实最关键的只有前两行:

使用注解编译库,需要显示的声明,而我正在使用的butterknife是含有注解编译功能的,但是并没有声明。

解决办法:

?
1 2 3 4 5 6 7 8 android {     defaultConfig {   // 声明需要使用注解功能    javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }    ...   } }

其他的变化

通过刚才的修改,我的工程已经运行起来了,但是发现了Android Studio 3.0 的几个小变化。

变化1

Warning:One of the plugins you are using supports Java 8 language features. To try the support built into the Android plugin, remove the following from your build.gradle:
apply plugin: 'me.tatarka.retrolambda'

从警告上看,希望我移除这个插件,于是我到官网上查看了一下信息:

If Android Studio detects that your project is using Jack, Retrolambda, or DexGuard, the IDE uses Java 8 support provided by those tools instead.

如果Android Studio发现你的工程中使用Jack ,Retrolambda 或DexGuard,编辑器会使用Java8支持,替换这个工具。
因为我使用me.tatarka.retrolambda第三方框架,所以就出现了这个,我们只要删除相关的配置就可以了。

变化2

提示有更高版本你的第三方框架:

上面的截图显示,gson有更高的版本2.8.3,提示我升级gson。这就省去了我们去github上查看是否版本更新的时间,非常的方便。


问题X:

Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error:

原创  2017年10月06日 17:13:07
  • 5103
Error:Execution failed for task ':app:mergeDebugResources'.> Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
  • 1
  • 2

在项目的gradle.properties中:

android.enableAapt2=false
问题XX:

Error: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:错误

原创  2016年12月21日 11:19:14
  • 17687


把eclipse项目导入AndroidStudio,结果报错了。

错误:Error:Execution failed for task ':app:mergeDebugResources'. > Error: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:



经过一轮的搜查: 在gradle的android{ ... } 中加入这两句就可以了 [java]  view plain  copy
  1. android {  
  2.       
  3.    ......  
  4.   
  5.     aaptOptions.cruncherEnabled = false  
  6.     aaptOptions.useNewCruncher = false  
  7.   
  8.    ......  
  9. }  

出现错误的原因是:Androidstudio严格审查png图片,就是png没有达到Androidstudio的要求
上面的那两句话大概意思是

禁止Gradle检查PNG的合法性

问题XXX:

android studio 3.0版本升级问题修改:


===》 问题一

[java]  view plain  copy
  1. Error:Cannot choose between the following configurations of project :pickerview:  
  2.   - debugApiElements  
  3.   - debugRuntimeElements  
  4.   - releaseApiElements  
  5.   - releaseRuntimeElements  
  6. All of them match the consumer attributes:  
  7.   - Configuration 'debugApiElements':  
  8.       - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.  
  9.       - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.  
  10.       - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.  
  11.       - Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.  
  12.   - Configuration 'debugRuntimeElements':  
  13.       - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.  
  14.       - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.  
  15.       - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.  
  16.       - Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.  
  17.   - Configuration 'releaseApiElements':  
  18.       - Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.  
  19.       - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.  
  20.       - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.  
  21.       - Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.  
  22.   - Configuration 'releaseRuntimeElements':  
  23.       - Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.  
  24.       - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.  
  25.       - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.  
  26.       - Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.  
[java]  view plain  copy
  1. Error:Cannot choose between the following configurations of project :pickerview:  
  2.   - debugApiElements  
  3.   - debugRuntimeElements  
  4.   - releaseApiElements  
  5.   - releaseRuntimeElements  
  6. All of them match the consumer attributes:  
  7.   - Configuration 'debugApiElements':  
  8.       - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.  
  9.       - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.  
  10.       - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.  
  11.       - Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.  
  12.   - Configuration 'debugRuntimeElements':  
  13.       - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.  
  14.       - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.  
  15.       - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.  
  16.       - Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.  
  17.   - Configuration 'releaseApiElements':  
  18.       - Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.  
  19.       - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.  
  20.       - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.  
  21.       - Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.  
  22.   - Configuration 'releaseRuntimeElements':  
  23.       - Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.  
  24.       - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.  
  25.       - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.  
  26.       - Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.  

===》解决方法(from:http://blog.csdn.net/pjingying/article/details/71975805?utm_source=itdadao&utm_medium=referral):

Warning:android-apt plugin is incompatible with future version of Android Gradle plugin. Please use ‘annotationProcessor’ configuration instead.

原因:更新Android studio 原来项目出现问题。 
分析: 尤其是采用butterknife工具的,采用新的Android Studio都会出现这样的问题,本人根据提示最后猜测原因可能是Android studio更新,然后gradle更新了,这样的话可能使原来的android-apt 工具跟不上节奏了,所以让采用annotationProcessor工具。
解决: 把project下的build.gradle 当中的依赖 

修改成如下:

buildscript { 
repositories { 
mavenCentral() 

dependencies { 
classpath ‘com.android.tools.build:gradle:2.4.0-alpha7’ 
//classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8’ //注释掉


  
然后再把module下的build.gradle : 
修改如下: 
dependencies { 
compile project(‘:roadvance-sdk’)

compile ‘com.google.dagger:dagger:2.10’ 

//apt ‘com.google.dagger:dagger-compiler:2.10’

annotationProcessor ‘com.google.dagger:dagger-compiler:2.10’

compile ‘com.android.support:appcompat-v7:25.3.1’

compile ‘com.jakewharton:butterknife:8.5.1’ 

//apt ‘com.jakewharton:butterknife-compiler:8.5.1’

annotationProcessor ‘com.jakewharton:butterknife-compiler:8.5.1’ 

再把 apply plugin: ‘com.neenbedankt.android-apt ’ 这个引用给删除。 
重新reBuild的一下



===》 问题二


[html]  view plain  copy
  1. Error:Execution failed for task ':wigetlib:javaPreCompileDebug'.  
  2. > 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.  
  3.     - butterknife-7.0.1.jar (com.jakewharton:butterknife:7.0.1)  
  4.   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.  
  5.   See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.  
[html]  view plain  copy
  1. Error:Execution failed for task ':wigetlib:javaPreCompileDebug'.  
  2. > 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.  
  3.     - butterknife-7.0.1.jar (com.jakewharton:butterknife:7.0.1)  
  4.   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.  
  5.   See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.  

解决方法:

appbuild

android {

   ... 

  defaultConfig { 

         ...

       //添加如下配置就OK

  javaCompileOptions { 

           annotationProcessorOptions {

              includeCompileClasspath = true

            }

         }

         ...

    }

       ...

  }


总结

这就是我今天遇到的问题及解决方案,如果之前有更多问题再补充。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

更多相关文章

  1. Android(安卓)gradle plugin sync failed 错误
  2. Android(安卓)Studio 解决build.gradle运行编译报错问题
  3. 修改状态栏(StatusBar)图标(icon)(定制自己的状态栏)
  4. android rom修改小白有福了
  5. Ionic 程序打包发布Android版本
  6. Android关于view按键音的修改
  7. Android(安卓)Studio 打包发布apk
  8. Android(安卓)2.3 GingerBread for VirtualBox x86编译指南
  9. 修改最低版本minSdkVersion

随机推荐

  1. 为什么这个简单的连接查询使用子查询明显
  2. jdbc与mysql之"can't get hostname four
  3. mysql使用kill无法杀死进程
  4. Qt中使用mysql连接远程服务器
  5. SQL 函数如何设置参数默认值
  6. SQL Server更新一行阻止
  7. mysqd实例服务hang住的检测思路及方案
  8. 第73课内幕资料详细版 Spark SQL Thrift
  9. 使用SQL Server 2008提供的表分区向导
  10. SqlMapClient operation; uncategorized