问题一:

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

解决方案一:

https://stackoverflow.com/questions/44239235/android-gradle-3-0-0-alpha2-plugin-cannot-set-the-value-of-read-only-property

I used this code

 applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
//输出apk名称为:应用名.apk
def fileName = "xxx.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

**Use all() instead of each() 
Use outputFileName instead of output.outputFile if you change only file name (that is your case)**

Example from the guide:

// If you use each() to iterate through the variant objects,
// you need to start using all(). That's because each() iterates
// through only the objects that already exist during configuration time—
// but those object don't exist at configuration time with the new model.
// However, all() adapts to the new model by picking up object as they are
// added during execution. android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "xxx.apk"
}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

问题二:

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
  • 1

解决方案二:

http://blog.csdn.net/syif88/article/details/75009663

大致是说,Plugin 3.0.0之后有一种自动匹配消耗库的机制,便于debug variant 自动消耗一个库,然后就是必须要所有的flavor 都属于同一个维度。 
为了避免flavor 不同产生误差的问题,应该在所有的库模块都使用同一个foo尺寸。

但是我们从中已经知道解决方案了:

在主 app 的 build.gradle 里面的

defaultConfig {
targetSdkVersion:***
minSdkVersion :***
versionCode:***
versionName :*** //版本名后面加句话,意思是flavor dimension 它的维度就是该版本号,
//这样维度就是都是统一的了 **flavorDimensions "versionCode"** }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

问题三:

Error:Execution failed for task ':youyoubao:javaPreCompileCommonDebug'.
> 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-compiler-8.6.0.jar (com.jakewharton:butterknife-compiler:8.6.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.
  • 1
  • 2
  • 3
  • 4
  • 5

解决方案三:

在 app 下的 build.gradle 的 defaultConfig 中加一句话:

defaultConfig {
...
javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
} 转:
https://blog.csdn.net/CHITTY1993/article/details/78667069

 

Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated

今天升级了AS3.0以后,在项目编译的时候发现Gradle中报错了,错误如下:
Error:(60, 0) Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=xiaomiRelease, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
<a href="openFile:E:\Studio\MyApplication\CodeBook\build.gradle">Open File</a>
经过一番折腾,网上找大牛的解读,弄明白了output.outputFile变成了只读属性,不能再往里面写东西了,以下是3.0之前的配置:
applicationVariants.all { variant ->    //批量修改Apk名字
    variant.outputs.each { output ->
        def outputFile = output.outputFile
        if (outputFile != null && outputFile.name.endsWith('.apk') && 'release'.equals(variant.buildType.name)) {
            def fileName = outputFile.name.replace("${variant.flavorName}", "V${defaultConfig.versionName}-${variant.flavorName}")
            fileName = fileName.replace('.apk', "-${buildTime()}.apk")
            output.outputFile = new File(outputFile.parent, fileName)
        }
    }
}
下面是经过修改之后3.0里面批量修改APK名字的配置:
applicationVariants.all { variant ->    //批量修改Apk名字
    variant.outputs.all { output ->
        if (!variant.buildType.isDebuggable()) {
            //获取签名的名字 variant.signingConfig.name
            //要被替换的源字符串
            def sourceFile = "-${variant.flavorName}-${variant.buildType.name}"
            //替换的字符串
            def replaceFile = "_V${variant.versionName}_${variant.flavorName}_${variant.buildType.name}_${buildTime()}"
            outputFileName = output.outputFile.name.replace(sourceFile, replaceFile);
            //遗留问题:如何获取当前module的name,如CodeBooke这个名字怎么获取到
        }
    }
}
问题:对于如何在gradle中获取module的name,还是没有找到相关的方法,希望有知道的大神留言交流。
这是一个对AS 3.0变化总结比较全的博客:
 

升级到 Android Studio 3.0 + Gradle 4.1 遇到的一些坑及解决方案的更多相关文章

  1. android studio 2.0 Gradle HttpProxy 设置

    Android Studio 一直Failed to import Gradle project: Connection timed out: connect Android Studio 2.0 里 ...

  2. Android Studio 3.0 及个版本下载和 gradle 各版本下载

    Android Studio 3.0 下载地址: 链接:http://pan.baidu.com/s/1jHVuOQi 密码:3pd0 Android Studio 3.0 包含了三大主要功能: 一套 ...

  3. Android Studio 1.0.2项目实战——从一个APP的开发过程认识Android Studio

    Android Studio 1.0.1刚刚发布不久,谷歌紧接着发布了Android Studio 1.0.2版本,和1.0.0一样,是一个Bug修复版本.在上一篇Android Studio 1.0 ...

  4. 当一回Android Studio 2.0的小白鼠

    上个星期就放出了Android studio出2.0的消息,看了一下what's new 简直抓到了那个蛋疼的编译速度痛点.在网上稍微搜索了一下后发现基本都是介绍视频.一番挣扎后(因为被这IDE坑过几 ...

  5. Android Studio之回退Gradle版本方法

    Android Studio之回退Gradle版本方法 (Minimum supported Gradle version is 4.10.1. Current version is 4.6.)   ...

  6. Gradle sync failed: /Applications/Android Studio.app/Contents/gradle/gradle-2.14.1/lib/plugins/gradle-diagnostics-2.14.1.jar (No such file or directory) Consult IDE log for more details (Help | Sh

    上面出现的错误是,我从Android Studio 2.2 升级到2.3后,出现的问题, 找到方法: http://stackoverflow.com/questions/30526613/andro ...

  7. Android Studio 3.0 新特性

    最新Android Studio版本是Android Studio 3.0,本文提供了所有新功能和更改的摘要. 所有这些功能都可以在最新的金丝雀版本中发布,但beta测试版本可能尚未提供. 核心IDE ...

  8. Android Studio 3.0正式版填坑之路

    原文:https://www.jianshu.com/p/9b25087a5d7d   Android Studio 3.0启动图 序言 总看别人的文章,今天尝试着自己来写一篇.在逛论坛时候,无意间发 ...

  9. Android Studio 3.0 下载 使用新功能介绍

    谷歌2017发布会更新了挺多内容的,而且也发布了AndroidStudio3.0预览版,一些功能先睹为快.(英语一般,有些翻译不太好) 下载地址 https://developer.android.g ...

随机推荐

  1. 手写代码注意点--java.util.Stack相关

    1-Stack的基本函数为: 注意: 取栈顶的函数为peek(),不是top()... 测试stack是否为空的函数为empty(),不是isEmpty()...

  2. mysql5.7 版本中 timestamp 不能为零日期 以及sql_mode合理设置

    ---恢复内容开始--- 摘要: mysql5.7版本相比较之前的版本有很多的特性的增加以及默认配置的改变,在使用中难免会遇到与之前的使用习惯或者项目需求不符的情况.就需要调整相应的变量的值,比如sq ...

  3. 【VMware vSphere】Veeam备份

    前言 刚刚整理自己的Onenote笔记,发现有一篇笔记没有整理到博客上面来.因为没有许可证书,所以最后也没有成功,但是还是写在这里吧,万一哪儿天有了许可证书就又可以做试验了~ Veeam Backup ...

  4. 【转】Python之向日志输出中添加上下文信息

    [转]Python之向日志输出中添加上下文信息 除了传递给日志记录函数的参数(如msg)外,有时候我们还想在日志输出中包含一些额外的上下文信息.比如,在一个网络应用中,可能希望在日志中记录客户端的特定 ...

  5. 设计模式C++学习笔记之十七(Chain of Responsibility责任链模式)

      17.1.解释 概念:使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系.将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它为止. main(),客户 IWom ...

  6. SSH远程联机Linux服务器简易安全设定

    分别可以由底下这三方面来进行: 1.服务器软件本身的设定强化:/etc/ssh/sshd_config 2.TCP wrapper 的使用:/etc/hosts.allow, /etc/hosts.d ...

  7. (转!)Pyinstaller 打包发布经验总结

    原文地址 https://blog.csdn.net/weixin_42052836/article/details/82315118 具体的实现图待本人实现后贴上 原 Pyinstaller 打包发 ...

  8. 请求头缺少 'Access-Control-Allow-Origin'

    报错: 火狐上运行,出现报错信息.已拦截跨源请求:同源策略禁止读取位于 https://xxxxxxx 的远程资源.(原因:CORS 头缺少 'Access-Control-Allow-Origin' ...

  9. HDU 5297

    用x ^ (1 / n) 来求个数,容斥原理 , Num会向后移动, 迭代到不再变化,退出循环 #include<iostream> #include<cstdio> #inc ...

  10. Android Studio下载

    最新版本的Android Studio 2.1 RC下载地址: Windows: https://dl.google.com/dl/android/studio/ide-zips/2.1.0.8/an ...