Android Studio升级3.0遇到的小坑

        Android Studio3.0的正式版上线,给我们的开发又带来了更多的新特性,也方便了许多,看着大家都在升级,我也迫不及待的把我的Studio进行一下改革,话说我也中间隔了几个小版本一直没有升级处理,下面我就给大家说一下我遇到的几个小坑:

       首先我在官网下载了最新的安装包,下载安装完毕都很顺利,但是在运行编译的时候遇到了小插曲:

    1.Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com

      意思是:所有的flavors都必须属于同一个风格。

看官方文档:

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;

defaultConfig {
    ...
    versionName "1.0.0"
    flavorDimensions "versionCode"
    ...
}

只需在gradle中配置defaultConfig同步一下就好;


        同步完之后又遇到了第二个坑:

        2.Warning:The `android.dexOptions.incremental` property is deprecated and it has

原来在Android开发过程中突破的方法数的限制,就在build.gralde中做了解决操作,其中有个如下的配置

dexOptions {
    preDexLibraries false
    jumboMode true
    javaMaxHeapSize "2g"
    incremental false
}

现在android studio在不断优化,更新之后貌似不需要再特意配置了,直接将dexOptions删除即可。

   

      3.Annotation processors must be explicitly declared now.

      

      我在studio中用到了butterknife:7.0.1注解,没想到在编译的时候报错,



只需配置:

defaultConfig {
   ...
   javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
}


   经历了三个小坑之后,我的项目才正式在3.0上运行起来,Studio的不断更新升级,配置也越来越高,替代了原有需要手动升级的配置,插件或者jar包,都需要我们重新进行学习,代码再次敲起来。。。






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章