Android Studio中关于gradle升级后的问题

    今天时隔一年为毕设重新打开Android Studio,我还是一年前的那个小白,但是AS已经不是一年前的AS了。给Android Gradle plugin升级到3.2.1,Gradle升级到4.6,各种问题不大的问题就出现了。做个总结,留给自己以后备用。


1.Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.

    如题,编译器报错出现:

    Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.

    It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

    同理还有:

    Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation' and 'testApi'.

    Configuration 'androidTestCompile' is obsolete and has been replaced with 'androidTestmplementationI'.

    原代码如图:(配置文件build.gradle(app)中)

    按照错误提示,把compile改成implementation或api;把testCompile改成testImplementation或testApi;把androidTestCompile改成androidTestmplementationI。改后代码如下,0错误:


2.Could not find com.android.tools.build:gradle:3.2.1.

    报错出现:

    Could not find com.android.tools.build:gradle:3.2.1.

    Searched in the following locations:

        https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom

        https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar

    Required by:

        project :

    Add Google Maven repository and sync project

    Open File

    Enable embedded Maven repository and sync project

    原代码如图:(配置文件build.gradle(Project)中)

    很简单,只需要在repositories里面加上google()即可。如下图所示:


3.DSL element 'DexOptions.incremental' is obsolete and will be removed at the end of 2018.

    报错如题。incremental属性弃用,需要删掉设置。直接注释掉后的代码如下:


4.Annotation processors must be explicitly declared now.  

    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-7.0.1.jar (butterknife-7.0.1.jar)

    报错如上。解决办法之一但并不推荐但是:在build.gradle(project)中加入代码:

    解决方法二是:先在build.gradle(project)中加入代码:

    然后在build.gradle(app)中加入代码:

    但是此时会报错,比如:

    错误: 找不到符号

    符号:   类 Bind

    位置: 程序包 butterknife

    此时要把  @Bind(R.id.et_employee_id)  改成  @BindView(R.id.et_employee_id)。搞定。


5.Compilation failed; see the compiler error output for details.

    Compilation failed; see the compiler error output for details.

    错误: 程序包com.loopj.android.http不存在

    找不到依赖module引用的包。build.gradle里用implementation的话会出现找不到某包,使用api才可以对外开放。原代码:

    所以将implementation改成api。如下:


6.support包的类找不到

    错误: 找不到符号

    符号:   类 KeyEventCompat

    位置: 程序包 android.support.v4.view

    可以将v4的包由27.1.0改为26.1.0,或者在build.gradle(Project)中的allprojects { }里加上ext { }及内部的代码:


7.文件命名问题

    Error: 'Z' is not a valid file-based resource name character: File-based resource names must contain only lowercase a-z, 0-9, or underscore.

    只需要根据这行报错下提示的文件路径,修改文件名称即可。代码文件和图片都不能用大写字母命名,只能用小写的a到z和0到9来命名。修改命名后即可。


    今天暂时到这里,太晚了,又困,有一些已经忘记了。其实都是配置上的问题,根据错误提示那些基础英文完全可以自己看着改好。本小白还是菜,不过还好未来不走Android这条路,只要能把毕设搞定就好了...

    先睡为敬。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 与茶相遇纯属偶然。我是不懂茶道的。但在红尘中走了太久,有的时候,也想寻一处清宁,来安放自己的灵魂,就这样,与茶相知...
    5ebc5e57260e阅读 2,953评论 0 0
  • 今天上午我终于付诸行动,早起记了单词,听了听力,又学了一会儿粤语和韩语。整个下午和晚上都在整理投资学,一会儿准备做...
    旧寐阅读 1,131评论 0 0
  • 2016.9.10 进入了一个新的企业,发现企业没有贯彻文化理念和人文关怀缺乏,特别是说工作流程上的一些重大缺陷时...
    Drei羽凡阅读 3,660评论 0 0
  • 南方的春天气候潮湿,早晨天色朦胧,想起老头的电话,想回家,想跟他一起从北方坐到终点站不远的家,想像中黑色栅栏门...
    李夭夭2012阅读 1,384评论 0 0