Android Studio 升級gradle異常

升級gradle
dependencies {
    classpath 'com.android.tools.build:gradle:3.4.1'
    classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
}

各種驚喜:

Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=choutiDebug, filters=[], versionCode=300330, versionName=3.3.3}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.

 解決方法:

 applicationVariants.all { variant ->
    variant.outputs.each { output ->
          def outputFile = output.outputFile
          def fileName = "name_${getVersionName()}_${variant.productFlavors[0].name}.apk"
          output.outputFileName = fileName
                }
       }

ERROR: The Android Gradle plugin supports only Butterknife Gradle plugin version 9.0.0-rc2 and higher.
The following dependencies do not satisfy the required version:
root project 'chouti-android' -> com.jakewharton:butterknife-gradle-plugin:8.5.1
Affected Modules: chouti-android

解決方法:

升級Butterknife 版本,並且把compile 全部替換爲implementation

ERROR: All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html
Affected Modules: chouti-android

解決方法:

flavorDimensions "channel"
productFlavors {
    productFlavors.all { flavor ->
         dimension "channel"
    }
 }

ERROR: The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin. Perhaps you misspelled something?
Affected Modules: chouti-android

解決方法:

instrumentTest.setRoot('tests') 替換爲:androidTest.setRoot('tests')

> Task :mergeExtDexChoutiDebug FAILED
AGPBI: {"kind":"error","text":"Static interface methods are only supported starting with Android N (--min-api 24): void butterknife.Unbinder.lambda$static$0()","sources":[{}],"tool":"D8"}

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':mergeExtDexChoutiDebug'.
> Could not resolve all files for configuration ':choutiDebugRuntimeClasspath'.
   > Failed to transform artifact 'butterknife-runtime.aar (com.jakewharton:butterknife-runtime:9.0.0-rc2)' to match attributes {artifactType=android-dex, dexing-is-debuggable=true, dexing-min-sdk=16}.
      > Execution failed for DexingTransform: ******\.gradle\caches\transforms-2\files-2.1\e7c412e8645b205cce2243e763339353\jars\classes.jar.
         > Error while dexing.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 19s
56 actionable tasks: 6 executed, 50 up-to-date
 

解決方法:

 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
 }

D:\chouti\chouti-android\AndroidManifest.xml:28:13-35 Error:
    Attribute meta-data#android.support.VERSION@value value=(26.0.0) from [com.android.support:design:26.0.0] AndroidManifest.xml:28:13-35
    is also present at [com.android.support:support-v4:26.1.0] AndroidManifest.xml:28:13-35 value=(26.1.0).
    Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:26:9-28:38 to override.

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':processChoutiDebugManifest'.
> Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(26.0.0) from [com.android.support:design:26.0.0] AndroidManifest.xml:28:13-35
      is also present at [com.android.support:support-v4:26.1.0] AndroidManifest.xml:28:13-35 value=(26.1.0).
      Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:26:9-28:38 to override.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 11s
 

解決方法:

在build.gradle中添加如下內容

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '26.1.0'//support版本號
            }
        }
    }
}

 

ERROR: The minSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file.
Remove minSdkVersion and sync project
Affected Modules: chouti-android

解決方法:

刪除AndroidManifest.xml中

 <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="26" />

 

所有問題解決 編譯成功運行正常。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章