Reputation: 407
I tried to get APK of my flutter app using
flutter build APK
but it returned this error. I have no idea what does it means. I will be glad if you try to help me. comment in this post if you need any extra details to solve the error
Running Gradle task 'assembleRelease'... R8: Type com.google.firebase.iid.zzbb is referenced as an interface from com.google.firebase.messaging.zzf.
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:transformClassesAndResourcesWithR8ForRelease'. com.android.tools.r8.CompilationFailedException: Compilation failed to complete
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run wit h --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 7m 32s Running Gradle task 'assembleRelease'... Running Gradle task 'assembleRelease'... Done 456.4s (!) [!] The shrinker may have failed to optimize the Java bytecode. To disable the shrinker, pass the
--no-shrink
flag to this command. To learn more, see: https://developer.android.com/studio/build/shrink-code Gradle task assembleRelease failed with exit code 1
Upvotes: 3
Views: 1633
Reputation: 1502
I'm answering this question because it was one of the first results I got when I searched for the error message.
I had the same error. R8
turns out to be a "shrinker" of binary java files and it was masking the issue behind the error. In gradle.properties
, I change android.enableR8
from true
to false
then rebuilt the apk. I got a different error:
...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkReleaseDuplicateClasses'.
> 1 exception was raised by workers:
java.lang.RuntimeException: Duplicate class androidx.lifecycle.ViewModelLazy found in modules lifecycle-viewmodel-2.4.0-runtime.jar (androidx.lifecycle:lifecycle-viewmodel:2.4.0) and lifecycle-viewmodel-ktx-2.2.0-runtime.jar (androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0)
Duplicate class androidx.lifecycle.ViewModelProviderKt found in modules lifecycle-viewmodel-2.4.0-runtime.jar (androidx.lifecycle:lifecycle-viewmodel:2.4.0) and lifecycle-viewmodel-ktx-2.2.0-runtime.jar (androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0)
Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
...
The error was because I had two versions of lifecycle-viewmodel runtime: 2.2.0 and 2.4.0. I searched the project and plugins and turns out that only one of them uses V2.4.0 and the rest are using V2.2.0:
def lifecycle_version = "2.4.0"
def arch_version = "2.1.0"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
// Lifecycles only (without ViewModel or LiveData)
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
I just changed lifecycle_version
to 2.2.0
and I was able to build the apk with no errors.
Don’t forget to turn android.enableR8
back to true
.
Upvotes: 1