Lokesh
Lokesh

Reputation: 425

flutter build apk --release command not work

TYSONs-MacBook-Air:chats jeshurun$ flutter build apk --release
You are building a fat APK that includes binaries for android-arm, android-arm64, android-x64.
 If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.
To generate an app bundle, run:
    flutter build appbundle --target-platform android-arm,android-arm64,android-x64
    Learn more on: https://developer.android.com/guide/app-bundle
To split the APKs per ABI, run:
    flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi
    Learn more on:  https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
 Plugin project :firebase_core_web not found. Please update settings.gradle.
 Plugin project :cloud_firestore_web not found. Please update settings.gradle.

FAILURE: Build failed with an exception.                                

* What went wrong:                                                      
Execution failed for task ':device_info:verifyReleaseResources'.        
> A failure occurred while executing 
com.android.build.gradle.internal.tasks.Workers$ActionFacade
> 1 exception was raised by workers:                                 
 com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
 /Users/jeshurun/.gradle/caches/transforms-2/files-2.1/8caf43a43008a17794fe6e0dd5ac61b7/core-1.1.0/res/values/values.xml:142:5-173:25: AAPT: error: resource android:attr/fontVariationSettings not found.

 /Users/jeshurun/.gradle/caches/transforms-2/files-2.1/8caf43a43008a17794fe6e0dd5ac61b7/core-1.1.0/res/values/values.xml:142:5-173:25: AAPT: error: resource android:attr/ttcIndex not found.



* 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 14s                                                     
Running Gradle task 'assembleRelease'...                                
Running Gradle task 'assembleRelease'... Done                      15.6s
The built failed likely due to AndroidX incompatibilities in a plugin. 
The tool is about to try using Jetfier to solve the incompatibility.
Building plugin agora_rtc_engine...
Running Gradle task 'assembleAarRelease'...                             
Running Gradle task 'assembleAarRelease'... Done                    1.7s


FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':compileReleaseAidl'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/jeshurun/flutter/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-1.0.12/android/local.properties'.

BUILD FAILED in 1s

The plugin agora_rtc_engine could not be built due to the issue above.

Upvotes: 1

Views: 8122

Answers (2)

Blasanka
Blasanka

Reputation: 22437

First, flutter build apk by default uses argument --release.

Next, May be you are using AndroidX packages within your app but your app not migrated to use AndroidX. To ensure that:

In an app or module project, the file android/gradle.properties or .android/gradle.properties must contain:

android.useAndroidX=true
android.enableJetifier=true

Or else maybe because your compileSdkVersion is lower than 28,

Try setting compileSdkVersion 28 or 29 to app/build.gradle. If this not solved your problem may be one of your plugin is the problem. Ofcourse you can edit your plugin build gradle but I do not recommend that.

First, Try upgrading packages that are not updated. If not upgarded those packages, you can follow below by opening flutter root android directory in android studio.

Steps:

  1. Go to External libraries
  2. Locate the library that raised the issue
  3. Open it's app/build.gradle
  4. Update the compileSdkVersion to 28 or 29

Also you can cloned the packages that causes the problem and do aboves and push it to github and in the pubspec.yaml, access from github like below:

dependencies:
  #...
  repo_name:
    git:
      url: git://github.com/your_github/repo_name.git

If none of them worked, worth trying below options :D,

  1. Flutter clean / Deleted build folder
  2. Deleted pubspec.lock, .packages, .flutter-plugins
  3. Flutter pub cache repair
  4. Ensured compileSdkVersion is 28 in app/build.gradle
  5. finally, try Deleting flutter/.pub-cache

Upvotes: 1

Adelina
Adelina

Reputation: 11891

In android build.gradle file try to change the compileSdkVersion to: compileSdkVersion 28

Upvotes: 1

Related Questions