34

I am on android studio 4. Gradle is 6.1.1. And I created a new flutter project from android studio. Then I opened the project as an android project. There is such an option in Tools->Flutter. Which resulted in gradle sync. That was successful. But when I try to generate signed apk with my keys. I get this. error

\path\to\my\project\build\app\intermediates\flutter\profile\libs.jar (The system cannot find the path specified)

There is no profile directory at the given location. But there are Debug and Release directories both of which contains libs.jar. I searched all other the net for this issue. Found Nothing.

Additional: I can build debug apk with no issues.

GunJack
  • 1,928
  • 2
  • 22
  • 35

8 Answers8

56

I found a fix for this issue as I was searching through various issues people had reported on github regarding this.

This is just a workaround.

You can get two kinds of error. For me the system could not find profile/libs.jar, for some people the error was for debug/libs.jar. If the issue is profile, you should first run your app in profile mode and then Generate signed apk (or build and run in release mode). To run in profile mode use flutter run --profile. There is also a profile option under Run menu in Android Studio.

If the error is about debug/libs.jar, first build the debug version (and also the profile mode) and then try to Generate signed apk. By default, flutter run compiles to debug mode.

This issue evidently arises from the updated Gradle and android studio gradle plugin.

Here is the workaround by Jwiggiff on the github page.

GunJack
  • 1,928
  • 2
  • 22
  • 35
  • 1
    i never even noticed there is a profile folder in src\app\ together with main folder. wonder what this is for :D profiing? i also had a prob with debug/libs.jar but once i compiled to emulator, it went back to profile/libs.jar error. somehow now i cant deploy to emulator as well. might be gradle issue ... and i think this mess started after i was forced to upgrade to gradle 6.1.1 from 5.6.2 – chitgoks Jun 03 '20 at 12:02
  • 3
    for now i reverted back to the original 5.6.2 gradle zip and com.android.tools.build:gradle:3.5.2 in build.gradle. that upgrade to 4.0.0 and 6.1.1.zip is the cause of the problem – chitgoks Jun 03 '20 at 12:27
  • 7
    Updates are supposed to make these things easier and more convenient. Now I am wasting more time figuring out what went wrong in the build system than the actual problem solving in my code. What a waste of progress. – GunJack Jun 04 '20 at 05:16
  • Now everytime I have to get the apk. I need to build it three time with three options. – GunJack Jun 04 '20 at 05:18
  • lol im not wasting time with that. i reverted back to the old version till they fix it. they confirmed it as a bug. – chitgoks Jun 04 '20 at 10:10
  • 3
    Running Run->Profile and then I was able to build apk successfully – Raja C Jul 05 '20 at 19:03
  • as @chitgoks mentioned I replaced com.android.tools.build:gradle:4.0.0 ~> 3.5.2 That did the trick. The error is gone now! – Pavan Oct 30 '20 at 08:31
15

This problem is with latest gradle 4.0.0

Switch from classpath 'com.android.tools.build:gradle:4.0.0'

to classpath 'com.android.tools.build:gradle:3.6.3'

or classpath 'com.android.tools.build:gradle:3.5.0' (Worked for me)

Munish Thakur
  • 926
  • 1
  • 8
  • 25
10

If you don't care about lintOptions you can add this code in app's build.gradle file:

android {
    lintOptions { 
        checkReleaseBuilds false
        abortOnError false
    }
}
Sukhchain Singh
  • 834
  • 1
  • 8
  • 26
1

this will work.

flutter build apk --debug && flutter build apk --profile && flutter build apk --release

but test the apk before sharing it.

even it doesn't work the change the gradle from 4.x to 3.6.x this will work.

Corentin Houdayer
  • 988
  • 2
  • 8
  • 19
xbadal
  • 1,284
  • 2
  • 11
  • 24
1

This should also work fine

flutter build apk --profile
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
0

This is a trick

Run terminal for current flutter project, then type

flutter run

to get this success result :

Running Gradle task 'assembleDebug'...                                  
Running Gradle task 'assembleDebug'... Done                        22.7s
✓ Built build/app/outputs/flutter-apk/app-debug.apk.

then, type

flutter build apk

to get

Running Gradle task 'assembleRelease'...                                
Running Gradle task 'assembleRelease'... Done                      41.8s
✓ Built build/app/outputs/flutter-apk/app-release.apk (23.6MB).

then, install this Release APK to device.

flutter install build/app/outputs/flutter-apk/app-release.apk

Now, you got Release App on your device.

p/s : This case skip error

  • Execution failed for task ':app:lintVitalRelease'.

  • Failed to transform libs.jar to match attributes

  • Execution failed for JetifyTransform

  • Transform's input file does not exist

you already got.

Huy Tower
  • 7,769
  • 16
  • 61
  • 86
0

In my case, I forgot that I'm using flavors. Maybe this caused the issue. Now I let flutter build the app with the following command:

flutter build apk --flavor <flavorname> -t <path/to/main.dart>
st3ffb3
  • 398
  • 3
  • 15
0

Permanent fix

To fix this issue permanently, type in terminal

  1. flutter doctor

This will give you summary like this

enter image description here

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

enter image description here

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
Alphapico
  • 2,893
  • 2
  • 30
  • 29