Async-storage: D8: Program type already present: com.reactnativecommunity.asyncstorage.AsyncLocalStorageUtil

Created on 30 Mar 2020  路  8Comments  路  Source: react-native-async-storage/async-storage

Current behavior

gradlew buildRelease don't build my app because of an issue with async-storage.

Expected behavior

It should build without errors.

Repro steps

I added this library on my project.

Environment

  • Async Storage version: 1.8.1
  • React-Native version: 0.61.5
  • Platform tested: Android
  • Logs/Error that are relevant: `> Task :app:transformClassesAndResourcesWithR8ForRelease FAILED
    R8 is the new Android code shrinker. If you experience any issues, please file a bug at
    https://issuetracker.google.com, using 'Shrinker (R8)' as component name. You can
    disable R8 by updating gradle.properties with 'android.enableR8=false'.
    Current version is: 1.4.94 (build 390954928f0db9c3b888a367f7f128ce3bbfb160 from go/r8bot (luci-r8-ci-archive-0-5g74)).

D8: Program type already present: com.reactnativecommunity.asyncstorage.AsyncLocalStorageUtil
FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:transformClassesAndResourcesWithR8ForRelease'.
    > com.android.tools.r8.CompilationFailedException: Compilation failed to complete
bug

Most helpful comment

Is AsyncStorage linked manually? Have you tried to clean and rebuild? Or try to disable R8 to see if it can build without it?

@Krizzu thank you for your reply.
I solved it. At the time I installed this package at first I linked it manually, then, I unlinked it via react-native unlink @react-native-community/async-storage.
But I found out there were still some references in settings.gradle and build.gradle, I removed them and now it works fine!

All 8 comments

Is AsyncStorage linked manually? Have you tried to clean and rebuild? Or try to disable R8 to see if it can build without it?

Is AsyncStorage linked manually? Have you tried to clean and rebuild? Or try to disable R8 to see if it can build without it?

@Krizzu thank you for your reply.
I solved it. At the time I installed this package at first I linked it manually, then, I unlinked it via react-native unlink @react-native-community/async-storage.
But I found out there were still some references in settings.gradle and build.gradle, I removed them and now it works fine!

If i unlink i get error that async storage is not linked

I still get the same error even after I ran

  1. react-native unlink @react-native-community/async-storage
  2. Ensure no async-storage references in settings.gradle
  3. Ensure no async-storage references in app/build.gradle

Environment
"react-native": "0.62.2"
"@react-native-community/async-storage": "^1.11.0"

Error

> ./gradlew assembleRelease
.....
.....
Execution failed for task ':app:mergeDexRelease'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
     Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
     Program type already present: com.reactnativecommunity.asyncstorage.AsyncLocalStorageUtil

@focalsolution You should not have AsyncStorage entries (or any other auto-linkable libraries) in gradle.settings/build.gradle. Remove those and retry

@Krizzu Can you guide me how to know if any auto-link libraries in node_modules contain this AsyncStorage?

@Krizzu I figured it out and solved by excluding AsyncStorage from jitsi library.
Thanks a lot for your reply that can shed me some light.

I add these lines in the app/build.gradle

+     implementation (project(':react-native-jitsi-meet')) {
+         exclude group: 'com.facebook.react', module:'react-native-community-async-storage'
+     }

Uninstall async Storage it would work fine!

Was this page helpful?
0 / 5 - 0 ratings