AndroidStudiio升级到3.1.3编译兼容性问题

我的工程原来使用的AndroidStudio的版本号是2.2.3,因为开发Android P的应用,升级到了3.1.3,自带的gradle升级到了4.4。升级之后程序各种报错,总结下来有一下几点:

1.首先要更改主目录下的build.gradle文件,将

dependencies {
    classpath 'com.android.tools.build:gradle:3.1.3'
}

这个改成对应的3.1.3。同时“C:\Users\用户名\.m2”文件夹下的内容也要更新成AndroidStudio的安装目录下的“E:\Program Files\Android\Android Studio\gradle\m2repository”文件夹下的内容,同时将m2repository文件夹重命名为repository

2.报错信息如下:

* What went wrong:
Could not resolve all files for configuration ':UPTSM:lintClassPath'.
> Could not find com.android.tools.lint:lint-gradle:26.1.3.
  Searched in the following locations:
      file:/D:/android-sdk-windows/extras/m2repository/com/android/tools/lint/lint-gradle/26.1.3/lint-gradle-26.1.3.pom
      file:/D:/android-sdk-windows/extras/m2repository/com/android/tools/lint/lint-gradle/26.1.3/lint-gradle-26.1.3.jar
      file:/D:/android-sdk-windows/extras/google/m2repository/com/android/tools/lint/lint-gradle/26.1.3/lint-gradle-26.1.3.pom
      file:/D:/android-sdk-windows/extras/google/m2repository/com/android/tools/lint/lint-gradle/26.1.3/lint-gradle-26.1.3.jar
      file:/D:/android-sdk-windows/extras/android/m2repository/com/android/tools/lint/lint-gradle/26.1.3/lint-gradle-26.1.3.pom
      file:/D:/android-sdk-windows/extras/android/m2repository/com/android/tools/lint/lint-gradle/26.1.3/lint-gradle-26.1.3.jar
      https://jcenter.bintray.com/com/android/tools/lint/lint-gradle/26.1.3/lint-gradle-26.1.3.pom
      https://jcenter.bintray.com/com/android/tools/lint/lint-gradle/26.1.3/lint-gradle-26.1.3.jar
  Required by:
      project :UPTSM

解决办法:

主目录下的build.gradle文件下的

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenLocal()
        google()//新增该行
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
    }
}

allprojects {
    repositories {
        google()//新增该行
        jcenter()
    }
}


3.<uses-library android:name="org.simalliance.openmobileapi" android:required="false"/>


库工程的AndroidManifest文件有这行会报错,新的gradle要求<uses-library>一定要在<application>标签下。

4.老的gradle版本编译出来的的apk的路径在主工程的\build\outputs\apk目录下,新的gradle版本编译出来的apk路径在build\outputs\apk\release目录下,通过脚本拷贝apk时要注意路径是否正确。

5.库工程里的buildTypes和主工程的buildTypes要对应起来


没有更多推荐了,返回首页