async-storage: ERROR: Could not find method android()

can’t build the application on android studio

        android {
            buildToolsVersion '28.0.0'
            compileSdkVersion rootProject.ext.compileSdkVersion
            buildToolsVersion rootProject.ext.buildToolsVersion
            defaultConfig {
                minSdkVersion rootProject.ext.minSdkVersion
                targetSdkVersion rootProject.ext.targetSdkVersion
            }

Environment

  • Async Storage version:
  • React-Native version:
  • Platform tested:
  • Logs/Error that are relevant:

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (8 by maintainers)

Most upvoted comments

@HelSirius Right, so in your root build.gradle you have subprojects { afterEvaluate { } } configurations. This goes through all modules that are added to your project, including AsyncStorage.

If Async Storage is used a module (in your case, it is) it does not include android plugin, hence no android block is available.

To fix that, add a check if android block exists:

subprojects{
    afterEvaluate {
        // check if `android` block is available
        if(it.hasProperty('android')){
            android {
               // your content here
            }
        }
    }
}

Hello. I’m getting this error.

FAILURE: Build failed with an exception.

  • Where: Script ‘/Users/user/mobile-app/node_modules/@react-native-community/cli-platform-android/native_modules.gradle’ line: 124
  • What went wrong: A problem occurred evaluating root project ‘unifiedApp’.

Could not find method implementation() for arguments [DefaultProjectDependency{dependencyProject=‘project ‘:react-native-async-storage_async-storage’’, configuration=‘default’}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

BUILD FAILED in 6s

at makeError (/Users/user/mobile-app/node_modules/@react-native-community/cli-platform-android/node_modules/execa/index.js:174:9)
at /Users/user/mobile-app/node_modules/@react-native-community/cli-platform-android/node_modules/execa/index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (/Users/user/mobile-app/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
at async Command.handleAction (/Users/user/mobile-app/node_modules/@react-native-community/cli/build/index.js:192:9)

Did you get any solution to this problem?

@tido64 Yes I did and thank you @Krizzu

@HelSirius Please add if(it.hasProperty('android')), like in my example. This will ensure that android block will be used in modules that use android build tools.