今天时隔一年为毕设重新打开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这条路,只要能把毕设搞定就好了...
先睡为敬。
网友评论