Android Studio升级到3.0.0后构建项目时出现的问题总结

如果Android Studio升级到3.0.0,Android Studio会提示你推荐使用3.0.0的构建插件,同时要求Gradle的版本必须是4.1以上。下面是具体的修改步骤:

1. 修改Gradle的版本,在gradle-wrapper.properties里编辑distributionUrl,如下:

  distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip  //修改为4.1或者更高版本,更多版本详情查看 http://services.gradle.org/distributions/

2. 在项目顶级build.gradle里,修改构建插件版本为3.0.0,如下:

  buildscript {

      repositories {

        google()  //需要添加这个仓库,去下载3.0.0构建插件

      }

      dependencies {

        classpath 'com.android.tools.build:gradle:3.0.0'

      }

  }

3. 修改依赖配置

  implementation project(':library')  //将之前的compile改为implementation

  debugImplementation 'com.example.android:app-magic:12.3'  //将之前的debugCompile改为debugImplementation

  //provided改为compileOnly

4.修改apk输出目录的脚本需要改为类似如下:

  android.applicationVariants.all { variant ->     

    variant.outputs.all { output->  //把each改为all       

      outputFileName = "${variant.name}-${variant.versionName}.apk"  //把output.outputFile改为outputFileName     

    }   

  }

5. android-apt修改为annotationProcessor,如下:

    1)//classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'  //去掉顶级build.gradle下的android-apt依赖

    2)//apply plugin: 'android-apt'      

      //apt { arguments { } }  //去掉项目build.gradle里的apt加载和设置

    3)添加依赖

        dependencies{  //这里是androidannotations4.1.0的依赖           

            implementation "org.androidannotations:androidannotations-api:4.1.0"           

            annotationProcessor "org.androidannotations:androidannotations:4.1.0"         

        }

        dependencies {  //这里是dagger2.0的依赖            

            compile 'com.google.dagger:dagger:2.0'            

            annotationProcessor 'com.google.dagger:dagger-compiler:2.0'         

        }

    4.annotationProcessor添加到编译路径

        android {           

           defaultConfig {             

               javaCompileOptions {               

                  annotationProcessorOptions {                 

                    includeCompileClasspath true

                     //还可以添加参数,比如arguments = [ foo : 'bar' ]
                  }

               }             }          }

6. multidex的配置,如下: 

    //MultiDex.install(this); //去掉,同时去掉 'com.android.support:multidex:1.0.1' 依赖

 

    defaultConfig{   //直接启用multiDexEnabled true 即可
        multiDexEnabled true
    }

 

 

 

 

 

posted @   yongfengnice  阅读(948)  评论(3编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示