Android studio 升级到3.0时项目遇到的问题

第一个问题:

在项目的build.gradle文件里面

Cannot set the value of read-only property ‘outputFile’

Error:(56, 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.

之前的代码如下

applicationVariants.all { variant ->

          variant.outputs.each { output ->

             if (output.outputFile != null && output.outputFile.name.endsWith('.apk')

                 && 'release'.equals(variant.buildType.name)) {

                     def apkFile = new File(

                             output.outputFile.getParent(),

                     "zh_${variant.flavorName}_v${variant.versionName}_${buildTime()}.apk")

                     output.outputFile = apkFile

        }

    }

讲之前的代码注释修改成如下即可,貌似是命名改变了。

applicationVariants.all { variant ->

        /* variant.outputs.each { output ->

           if (output.outputFile != null && output.outputFile.name.endsWith('.apk')

                && 'release'.equals(variant.buildType.name)) {

                       def apkFile = new File(

                  output.outputFile.getParent(),


                "zhemituan_${variant.flavorName}_v${variant.versionName}_${buildTime()}.apk")

      output.outputFile = apkFile

   }

}*/

variant.outputs.all {

outputFileName ="zh_${defaultConfig.versionName}"+"_${variant.productFlavors[0].name}.apk"

    }

}

PS:另外就是记得在defaultConfig 下方加上这么一句话

flavorDimensions"versionCode"

第二个问题是:

compile ‘com.android.support:multidex:1.0.1’

若项目里面添加了此依赖,需要您将项目的build.gradle文件进行修改,也就是配置仓库的地方

allprojects {

    repositories {

                  jcenter()

                 maven { url"https://jitpack.io"}

                 google()// 加入此行代码---

         }

}

同时在module下的build.gradle处将之前的multidex的版本号升级到1.0.2

第三个问题:

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

这个问题我也是看了别人的博客才知道如何解决;

在项目的gradle.properties文件中底部加入

android.enableAapt2=false

第四个问题:

Annotation processors must be explicitly declared now. The following dependenciesonthecompile classpath are foundtocontainannotation processor. Please add themtotheannotationProcessor configuration. - butterknife-7.0.1.jar Alternatively,setandroid.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath =truetocontinuewithprevious behavior. Notethatthis optionisdeprecatedandwill be removedinthefuture.

使用了黄油刀出现的问题,compile'com.jakewharton:butterknife:7.0.1'

在module下的build.gradle中添加如下配置即可

android {

...defaultConfig {

...

           javaCompileOptions {

         annotationProcessorOptions {

          includeCompileClasspath = true }

          }

    }

}

第五个问题:

升级gradle了,之前项目用的是25.0.0的,导致虽然没有报错,但是有warning

,所以需要将项目里面所有使用到的改成26+

第六个问题:

找不到这个类support.v4.animation.AnimatorCompatHelper;

这个应该不是升级导致的,可能是因为项目中依赖导致的,姑且暂时记录在这里,因为我是升级之后出现了这个问题,具体解决办法就是

在build.gradle最后添加,代码如下:

configurations.all {

     resolutionStrategy.eachDependency {

      DependencyResolveDetails details ->

     def requested = details.requested

              if (requested.group == 'com.android.support') {

                    if (!requested.name.startsWith("multidex")) {

                            details.useVersion '24.1.1'

                               }

                   }

           }

}

PS:上述问题解决方案,基本上都是看了其他人写的文章才知道的,谢谢无私者的奉献。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xvzhengyang

感谢,励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值