flutter: can not build android apk

前端 未结 9 2404
心在旅途
心在旅途 2020-12-16 18:35
FAILURE: Build failed with an exception.
  • What went wrong: Execution failed for task \':app:lintVitalRelease\'.

    Coul

相关标签:
9条回答
  • 2020-12-16 19:12

    Step 1. flutter build apk --debug

    Step 2. flutter build apk --profile

    Step 3. flutter build apk --release

    0 讨论(0)
  • 2020-12-16 19:14

    I have found a solution mentioned here

    I got this problem in Android Studio 4.0 when I did a Gradle sync. I fixed it by doing the following:

    1. Open top-level build.gradle and change the gradle classpath to:

      classpath 'com.android.tools.build:gradle:4.0.0'
      
    2. Open gradle\wrapper\gradle-wrapper.properties and change the distribution URL to:

      distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
      
    3. Copy in .idea\jarRepositories.xml from a new project

    Here's my new flutter project jarRepositories.xml, you can get your own.

    <?xml version="1.0" encoding="UTF-8"?>
    <project version="4">
      <component name="RemoteRepositoriesConfiguration">
        <remote-repository>
          <option name="id" value="central" />
          <option name="name" value="Maven Central repository" />
          <option name="url" value="https://repo1.maven.org/maven2" />
        </remote-repository>
        <remote-repository>
          <option name="id" value="jboss.community" />
          <option name="name" value="JBoss Community repository" />
          <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
        </remote-repository>
        <remote-repository>
          <option name="id" value="BintrayJCenter15" />
          <option name="name" value="BintrayJCenter15" />
          <option name="url" value="https://jcenter.bintray.com/" />
        </remote-repository>
        <remote-repository>
          <option name="id" value="Google17" />
          <option name="name" value="Google17" />
          <option name="url" value="https://dl.google.com/dl/android/maven2/" />
        </remote-repository>
        <remote-repository>
          <option name="id" value="maven2" />
          <option name="name" value="maven2" />
          <option name="url" value="https://storage.googleapis.com/download.flutter.io" />
        </remote-repository>
        <remote-repository>
          <option name="id" value="maven5" />
          <option name="name" value="maven5" />
          <option name="url" value="https://google.bintray.com/exoplayer/" />
        </remote-repository>
        <remote-repository>
          <option name="id" value="maven4" />
          <option name="name" value="maven4" />
          <option name="url" value="https://maven.fabric.io/public" />
        </remote-repository>
        <remote-repository>
          <option name="id" value="MavenLocal" />
          <option name="name" value="MavenLocal" />
          <option name="url" value="file:$USER_HOME$/.m2/repository" />
        </remote-repository>
      </component>
    </project>
    

    No idea how or why, but it worked for me

    0 讨论(0)
  • 2020-12-16 19:18

    The problem is related to the version. Try changing the version of the plugin. This worked for me.

    https://developer.android.com/studio/releases/gradle-plugin?authuser=1&hl=pt-br#updating-gradle

    Example:

    distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
    
    classpath 'com.android.tools.build:gradle:3.6.4'
    
    0 讨论(0)
  • 2020-12-16 19:18

    The Android Gradle LintPerVariantTask now appears to be adding JARs from all build variants to its inputs: https://android.googlesource.com/platform/tools/base/+/1f9787310d64a66370627a2aaefa1e616565c17d

    The libapp.so libraries containing the app's compiled Dart code are packaged in a JAR, and a different JAR is generated for each variant. I'm not sure how dynamically generated per-variant JARs are supposed to be handled if the lint task expects all variants' JARs to be available.

    As a hack workaround you could change the lintOptions in app/build.gradle to disable the lint task:

    lintOptions {
        checkReleaseBuilds false
    }
    
    0 讨论(0)
  • 2020-12-16 19:25

    Running these two commands worked for me:

    flutter build apk --profile
    flutter build apk --release
    
    0 讨论(0)
  • 2020-12-16 19:27

    The only solution that worked for me was downgrading the gradle.build from

    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
    

    to

     dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
    

    and changed the gradle-warpper.properties from

    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
    

    to

    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
    

    Here you can see why you should not just add lintOptions { checkReleaseBuilds false } on the gradle.

    0 讨论(0)
提交回复
热议问题