一、升级Android studio3.0后新建一个project。

1.目录结构


2.build.gradle文件


3.gradle-wrapper.properties文件


4.app/build.gradle文件


划重点:(1)buildToolsVersion 不见了

(2)依赖 compile 换成了 implementation(实现)

compile和api

api完全等同于compile,二者没有区别。我们大家都知道,随着Android版本的更新,有很多过时的类和方法,compile亦是如此,我们可以把compile理解成api的过去式。

api和implementation

这两个是AS3.0版本中新增的指令,下面用一张图来说明一啊两者的区别:


5.failed(modules-2.lock问题)

C:\Users\Administrator\.gradle\caches\modules-2

解决办法:暴力删除,再重新build,成功


二、打开原有的项目或导入新项目

1.出现提示(需要更新gradle plugin和gradle)


2.之前指定的Android SDK Build Tools版本(24.0.2)将被忽略,因为它低于Android Gradle Plugin 3.0.0的最低支持版本(26.0.2)。 将使用Android SDK Build Tools 26.0.2。 要禁止此警告,请从build.gradle文件中删除“buildToolsVersion ‘24.2’”,因为每个版本的Android Gradle Plugin现在都具有默认版本的构建工具。 

更新Build Tools版本并同步项目Open File


5.run app failed

原因:aapt2 error;

解决方法:在gradle.properties中关闭AAPT2编译

android.enableAapt2=false

6.Error:All flavors must now belong to a named flavor dimension. (所有的flavors都必须属于同一个风格。

解决方案: 在主app的build.gradle里面的
defaultConfig {  targetSdkVersion:***  minSdkVersion :***  versionCode:***  versionName :***  //版本名后面添加一句话,意思就是flavor dimension 它的维度就是该版本号,这样维度就是都是统一的了  flavorDimensions "versionCode"}

7.refreshing gradle project 卡住

解决方法:试试Offline work


8.gradle打包,自定义apk名称代码报错(Cannot set the value of read-only property 'outputFile' )

    //打包apk名称构成//    applicationVariants.all { variant ->//        variant.outputs.each { output ->//            def outputFile = output.outputFile//            if (outputFile != null && outputFile.name.endsWith('.apk')) {//                def fileName = outputFile.name.replace(".apk", "_${releaseTime()}.apk")//                fileName = fileName.replace("app", "seatel")//                fileName = fileName.replace("-release", "")//                output.outputFile = new File(//                        outputFile.parent + "/${variant.buildType.name}",//                        fileName)//            }//        }//    }    //as更新3.0->    //Use all() instead of each()    //Use outputFileName instead of output.outputFile if you change only file name (that is your case)    // 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 = "seatel-${variant.buildType.name}_${releaseTime()}.apk"        }    }

9.Warning:The `android.dexOptions.incremental` property is deprecated and it has no effect on the build process

解决方法:在gradle中将 incremental 注释或删除

dexOptions { javaMaxHeapSize “4g” //incremental true } 

10.报错:

Error:Cannot choose between the following configurations of project :mylibrary:

- debugApiElements
- debugRuntimeElements
- releaseApiElements
- releaseRuntimeElements
  All of them match the consumer attributes:

这是apt插件问题导致!

解决方法:

//1.在project的build.gradle中删除classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'//2.在module的build.gradle中删除apply plugin: 'android-apt'//3.将module的build.gradle文件中的dependencyapt 'com.jakewharton:butterknife-compiler:8.1.0'//改为annotationProcessor 'com.jakewharton:butterknife-compiler:8.1.0'
其他使用apt的依赖,也要这样修改。


更多相关文章

  1. Android: 缩放图片文件引起的OOM异常
  2. Android(安卓)gradle 统一依赖库版本
  3. AccountManager getAccount 在Android(安卓)O 8.0版本中获取为 n
  4. Graphical layout无法正确显示的解决方法
  5. 关于 android 远程控制(pc 控制手机)
  6. 将Android下的可执行文件以静态库的形式进行编译
  7. Android开发环境配置之ADT怪异问题
  8. Failed to resolve: com.android.support.constraint:constraint
  9. Android(安卓)animation学习笔记之view/drawable animation

随机推荐

  1. Android崩溃日志获取与解析
  2. Android 使用Glide4.9 压缩并保存图片(jp
  3. android 使用html做应用程序界面初探
  4. 一个大四毕业生想对自学Android的大学生
  5. Android生成自定义二维码(三)--保存和分享
  6. Android学习与推广
  7. Android(安卓)ActionBar使用方法(一)
  8. 美剧追剧
  9. Android入门前言(一)之---------> Androi
  10. Android客户端与服务器端交互,如何保持ses