0
点赞
收藏
分享

微信扫一扫

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
    }








举报

相关推荐

0 条评论