简体   繁体   中英

flutter: can not build android apk

FAILURE: Build failed with an exception.
  • What went wrong: Execution failed for task ':app:lintVitalRelease'.

    Could not resolve all artifacts for configuration ':app:debugRuntimeClasspath'. Failed to transform libs.jar to match attributes {artifactType=processed-jar, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}. Execution failed for JetifyTransform: E:\AndroidStudioProjects\FlutterProject\EduyaariGuruFlutter\eduyaari_guru_flutter\build\app\intermediates\flutter\debug\libs.jar. Failed to transform 'E:\AndroidStudioProjects\FlutterProject\EduyaariGuruFlutter\eduyaari_guru_flutter\build\app\intermediates\flutter\debug\libs.jar' using Jetifier. Reason: FileNotFoundException, message: E:\AndroidStudioProjects\FlutterProject\EduyaariGuruFlutter\eduyaari_guru_flutter\build\app\intermediates\flutter\debug\libs.jar (The system cannot find the path specified). (Run with --stacktrace for more details.) Please file a bug at http://issuetracker.google.com/issues/new?component=460323 .

  • 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

BUILD FAILED in 1m 8s

Step 1. flutter build apk --debug

Step 2. flutter build apk --profile

Step 3. flutter build apk --release

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.

I found the workaround I needed for my case, I believe it will work for you as well.

I've set the checkReleaseBuilds flag to false in the android's app-level build.gradle like so:

android {
    ...
    lintOptions {
        checkReleaseBuilds false
    }
}

Found it here

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'

Running these two commands worked for me:

flutter build apk --profile
flutter build apk --release

I was having the same issue and tried building --debug and then --release and it still didn't work. However, if you look at the path in your specific error, it should either end with debug/libs.jar or profile/libs.jar. This indicates which apk you need to build first. In OP's case it is debug/libs.jar so building --debug first and then --release worked. In my case, it was profile/libs.jar so building --profile and then --release worked. I'm pretty sure building the --release shouldn't have to access the debug or profile directories though.

If your error says debug/libs.jar, build --debug then --release.
If your error says profile/libs.jar, build --profile then --release.

Reference Link: https://github.com/flutter/flutter/issues/58247#issuecomment-636500680

try running flutter clean on the project folder and then trying again. it seems a file got missing from the build folder

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

In android build.gradle,

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

didn't work for me and throwed cloud firestore error while executing flutter run. So I changed my gradle version to 4.0.1. where flutter run executed successfully, but flutter build apk fails, so I changed its version to 3.5.4.

In android/gradle/wrapper/gradle-wrapper.properties set,

distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip

which works perfectly for both flutter run and flutter build apk. In future this gradle version may not support few plugins that we use in our project, in that case upgrade to the next gradle version. refer gradle versions here: How Do I Fix "unexpected element <queries> found in <manifest>"?

If you see this error because you would like to run certain task on gradle for example lintDebug then you do not need to build the apk that might be slow. You can run this command to execute tasks for generating lint dependencies:

./gradlew generateProfileDependenciesForLint generateReleaseDependenciesForLint

After you run these commands then the lib.jar for each respective build tyoe will be generated and then you can run your gradle task that need lib.jar . It will safe you a lot of time.

Permanent fix

To fix this issue permanently, type in terminal

  1. flutter doctor

This will give you summary like this

在此处输入图像描述

You need to fix all those red marks!!

Fixing android licenses

type flutter doctor --android-licenses

if you encounter this error

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema

Try to install Android SDK command-line tools from Android Studio (Tools > SDK Manager)

  1. Unfold Appearance & Behavior
  2. Unfold System Settings
  3. Click Android SDK
  4. Click tab of SDK Tools
  5. Check Android SDK Command-line Tools (latest)
  6. Click Apply button

在此处输入图像描述

Then run once again

flutter doctor --android-licenses

Fixing Flutter plugin not installed

  1. Check your Android Studio Version (For Mac go to ~/Library/Application Support/Google/AndroidStudio{Version}. In my case, the {Version} is 2020.3)
  2. Then type

ln -s ~/Library/Application\ Support/Google/AndroidStudio2020.3/plugins ~/Library/Application\ Support/AndroidStudio2020.3

This command just redirects flutter doctor to the different folder to find plugins (where they are now). This is called symbolic link

Fixing unable to find bundled Java version

This solution is for Mac User

  1. Find your local Java version by typing /usr/libexec/java_home -V
  2. Set Java_Home path by typing /usr/libexec/java_home /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
  3. Type all of these in terminal
cd /Applications/Android\ Studio.app/Contents/jre ln -s../jre jdk ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk
  1. Finally run flutter doctor -v to see all the details changes

Happy Ending

After fixing all those issues, run

flutter clean
flutter run

to build release apk

flutter build apk --split-per-abi

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM