美文网首页
androidstudio Gradle升级到3.0以上后遇到的

androidstudio Gradle升级到3.0以上后遇到的

作者: emdd2016 | 来源:发表于2018-08-22 17:13 被阅读164次

    升级后出现第一个问题:

    1. Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated

    解决方案:

    官方给出的Api变更如下 (from: https://developer.android.google.cn/studio/build/gradle-plugin-3-0-0-migration#variant_api):

    Android 插件 3.0.0 引入了一些移除特定功能的 API 变更,可能会破坏您现有的构建。 后期版本的插件可能会引入新的公共 API 来取代破坏的功能。
    
    变体输出
    
    使用 Variant API 操作变体输出在新插件中已不再受支持。 不过,这种方式仍然适用于简单任务,例如在构建时更改 APK 名称,如下所示:
    
    // 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 = "${variant.name}-${variant.versionName}.apk"
        }
    }
    不过,涉及访问 outputFile 对象的更复杂任务不再奏效。 这是因为配置阶段期间不再创建变体特定的任务。 这就让插件无法提前了解其全部输出,不过,这会加快配置速度。
    

    按照上边的文档改一下就好

    2. 上边的改好了,跑一下就出现了下边的问题

    Error:Cannot choose between the following configurations of project :android_sdk:
      - debugApiElements
      - debugRuntimeElements
      - releaseApiElements
      - releaseRuntimeElements
    All of them match the consumer attributes:
      - Configuration 'debugApiElements':
          - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
          - Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.
      - Configuration 'debugRuntimeElements':
          - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
          - Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.
      - Configuration 'releaseApiElements':
          - Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
          - Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.
      - Configuration 'releaseRuntimeElements':
          - Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
          - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
          - Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.
    

    解决:
    android studio更新到3.0后,不支持apt了,适配仅需要修改以下两点:

    • 1.移除module目录下的build.gradle中的 apply plugin: 'android-apt'
    • 2.将apt改成annotationProcessor

    第三个问题:

    Configuration 'androidTestCompile' is obsolete and has been replaced with 'androidTestImplementation' and 'androidTestApi'.
    It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
    

    解决:
    直接根据提示,将过时不用的api换掉就行了。 具体的变化请看:http://www.baidu.com/

    • compile 改成implementation 或 api
    • androidTestCompile改成androidTestImplementation
    • testCompile 改成testImplementation

    第四个问题

    Unable to load class 'org.gradle.api.internal.component.Usage'.
    

    解决方案:

    • classpath 'com.novoda:bintray-release:0.3.4' 修改为
      classpath 'com.novoda:bintray-release:0.5.0'
      去掉bintray相关的引用

    第五个问题

    error: style attribute '@android:attr/windowEnterAnimation' not found.
    

    解决方案:

    • 当前已经不支持@开头使用android自带的属性,我们只要把@符号删掉就可以了。

    目前升级到3.1.3只遇到上边几个问题,一切源于自己实践,如有不对,多多指教。

    相关文章

      网友评论

          本文标题:androidstudio Gradle升级到3.0以上后遇到的

          本文链接:https://www.haomeiwen.com/subject/wemyiftx.html