将旧项目迁移到AndroidStudio3.0
1.aapt2编译不过去
Error:Execution failed for task ':app:mergeDebugResources'. > Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
原来的项目用到了kotlin以及kapt,升级到了androidstudio 3.0报了上面的错误,需要在项目的gradle.properties中添加:
android.enableAapt2=false
关闭aapt2。
2.All flavors must now belong to a named flavor dimension
All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html
官方文档:
Plugin 3.0.0 includes a new dependency mechanism that automatically matches variants when consuming a library. This means an app's debug variant automatically consumes a library's debug variant, and so on. It also works when using flavors—an app's redDebug variant will consume a library's redDebug variant. To make this work, the plugin now requires that all flavors belong to a named flavor dimension —even if you intend to use only a single dimension. Otherwise, you will get the following build error:
Android Plugin3.0的依赖机制:在使用library时会自动匹配variant(debug, release),就是说app的debug会自动匹配library的debug,相信大多数人也像我一样,当library多了,不会手动选择每个Library的variant。现在好了,它会自动匹配了。同样如果使用flavor的时候,比如app的redDebug同样会自动匹配library的readDebug。虽然有这样的优势,但是在使用flavor时,必须定义flavor dimension,否则会提示错误:
Error:All flavors must now belong to a named flavor dimension. The flavor 'flavor_name' is not assigned to a flavor dimension.
现在使用flavor,必须像下面一样配置:
// Specifies a flavor dimension. flavorDimensions "color" productFlavors { red { // Assigns this product flavor to the 'color' flavor dimension. // This step is optional if you are using only one dimension. dimension "color" ... } blue { dimension "color" ... } }
- 注意:如果library有两个dimensions:color,shape,但是app只有color,那么会如下的编译错误:
Error:Could not resolve all dependencies for configuration ':bar:redDebugCompileClasspath'. Cannot choose between the following configurations on project :foo: - redCircleDebugApiElements - redSquareDebugApiElements ...
- 在APP使用flavorSelection选定使用某个flavor dimension,注意如下配置:
android { ... // The flavorSelection property uses the following format: // flavorSelection 'dimension_name', 'flavor_name' // Chooses the 'square' flavor from libraries that specify a 'shape' // dimension. flavorSelection 'shape', 'square' }
3.Cannot set the value of read-only property 'outputFile’….
Android plugin 3.0 migration guide 建议:
- 使用 all()代替 each()
- 使用 outputFileName代替 output.outputFile,如果你只想更改文件名称
// 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 = "${variant.name}-${variant.versionName}.apk" } }
参考如下:
applicationVariants.all { variant -> variant.outputs.all { output -> def newApkName = applicationId + "-" + variant.versionName + "(" + variant.versionCode + ")" + ".apk"; outputFileName = new File("${project.projectDir}/../outputs/apks/" + variant.name, newApkName); } }
3.You should manually set the same version via DependencyResolution
另一种姿势:
configurations.all { resolutionStrategy.force 'rubygems:rb-inotify:0.9.5' }

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
老司机教你如何假装拥有一部 iPhone X
天气冷了,加上双11将至,各路单身狗们纷纷活跃起来,在朋友圈花式推销自己,其中当属晒 iPhone X最为装逼。 比如这样, 这样, 这样。 但是,这些都是真的吗?当然不是,距离 iPhone X 开启预售还有几天,难不成能从天上摘台 iPhone X?其实,图是P的。 雷锋网(公众号:雷锋网)编辑在这里就给大家八一八某些装逼神器。 第一个就是名字真实不做作的 iPhone X 订单生成器,这货⇊ iPhone X 订单生成器可以帮助用户在线生成购买 iPhone X截图的手机装逼神器,只要输入购买人的姓名、就可以制作出订购的截图。 这款软件的宣传语也十分接地气:让你在朋友圈当中享受尊贵的首批iphoneX体验用户,方便简洁的操作,真实逼真的订单模拟,还在等什么,9388买不起咱还不能P个图装下逼了啊?赶紧来下载吧~ 第二款APP就是名叫哈你的小妖
- 下一篇
[Android]Google 开源的 Android 排版库:FlexboxLayout
近Google开源了一个项目叫「FlexboxLayout」。 1.什么是 Flexbox 简单来说 Flexbox 是属于web前端领域CSS的一种布局方案,是2009年W3C提出了一种新的布局方案,可以简便、完整、响应式地实现各种页面布局,并且 React Native 也是使用的 Flex 布局。 你可以简单的理解为 Flexbox 是CSS领域类似 Linearlayout 的一种布局,但是要比 Linearlayout 要强大的多。 2.什么是 FlexboxLayout? 刚才说了 Flexbox 是CSS领域的比较强大的一个布局,我们在 Android 开发中使用 Linearlayout + RelativeLayout 基本可以实现大部分复杂的布局,但是Google就想了,有没有类似 Flexbox 的一个布局呢?这使用起来一个布局就可以搞定各种复杂的情况了,于是 FlexboxLayout 就应运而生了。 所以 FlexboxLayout 是针对 Android 平台的,实现类似 Flexbox 布局方案的一个开源项目,开源地址:https://github.com...
相关文章
文章评论
共有0条评论来说两句吧...