Async-storage: Build Failed in Android

Created on 17 May 2019  ·  10Comments  ·  Source: react-native-async-storage/async-storage

error
I have tried to run app android version. but build failed with following error.
node_modules\@react-native-community\async-storage\android\src\main\java\com\reactnativecommunity\asyncstorage\ReactDatabaseSupplier.java:17: error: package com.facebook.common.logging does not exist
import com.facebook.common.logging.FLog

Package.json file

{
"name": "example",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"android-windows": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res && react-native run-android"
},
"rnpm": {
"assets": [
"src/assets/fonts"
]
},
"dependencies": {
"@react-native-community/async-storage": "^1.4.0",
"@react-native-community/netinfo": "^2.0.10",
"axios": "^0.18.0",
"crypto-js": "^3.1.9-1",
"react": "16.8.3",
"react-native": "0.59.8",
"react-native-barcode-scanner-google": "git+https://github.com/ekreutz/react-native-barcode-scanner-google.git#v1.3.0",
"react-native-cache-image": "^1.0.0",
"react-native-camera": "git+https://[email protected]/react-native-community/react-native-camera.git",
"react-native-device-info": "^1.4.2",
"react-native-gesture-handler": "1.1.0",
"react-native-orientation": "3.1.3",
"react-native-picker-select": "^6.1.0",
"react-native-snackbar": "^0.4.6",
"react-native-super-grid": "^2.1.0",
"react-native-table-component": "^1.2.0",
"react-navigation": "3.6.0",
"react-navigation-backhandler": "1.1.1",
"url-parse": "^1.2.0"
},
"devDependencies": {
"babel-jest": "^24.6.0",
"jest": "^24.6.0",
"metro-react-native-babel-preset": "0.53.1",
"react-test-renderer": "^16.8.6"
},
"jest": {
"preset": "react-native"
}
}

I have no idea why its not building suddenly. it was working few weeks ago. please anyone tell me the way to resolve this error.

bug Android

Most helpful comment

Right, seems like deps are in place. What you can try:

  • Remove node_modules
  • Remove android/build and android/app/build dirs
  • Install deps yarn install
  • In android dir, run ./gradlew installDebug

Hopefully that clean will be sufficient to get it working.

All 10 comments

Hey @ananth10,

Did you try to clean restart it? rm modules, install them again, in android/ run ./gradlew clean. Then back in the root, yarn start --clearCache ?

thanks.

@Krizzu i have tried it many times, but still i am getting same error. i have no idea why it suddenly happened it was working some while ago. can you suggest me any other solutions?

@ananth10 This shows that FLog dependency is missing, although this is bundled with RN, so looks like syncing problem.

Are you able to build the project without AsyncStorage?

@Krizzu No, I have removed AsyncStorage and Tried. but this time react-native-orientation displays same error.

So it appears that you have some issue with dependencies. Likely forgot to add implementation ('com.facebook.react:react-native:+') in you app/build.gradle file.

You can post it here, so I could have a look into it.

@Krizzu please look on it.

app/build.gradle

`apply plugin: "com.android.application"

import com.android.build.OutputFile

/**

  • The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
  • and bundleReleaseJsAndAssets).
  • These basically call react-native bundle with the correct arguments during the Android build
  • cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
  • bundle directly from the development server. Below you can see all the possible configurations
  • and their defaults. If you decide to add a configuration block, make sure to add it before the
  • apply from: "../../node_modules/react-native/react.gradle" line.
    *
  • project.ext.react = [
  • // the name of the generated asset file containing your JS bundle
  • bundleAssetName: "index.android.bundle",
    *
  • // the entry file for bundle generation
  • entryFile: "index.android.js",
    *
  • // whether to bundle JS and assets in debug mode
  • bundleInDebug: false,
    *
  • // whether to bundle JS and assets in release mode
  • bundleInRelease: true,
    *
  • // whether to bundle JS and assets in another build variant (if configured).
  • // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
  • // The configuration property can be in the following formats
  • // 'bundleIn${productFlavor}${buildType}'
  • // 'bundleIn${buildType}'
  • // bundleInFreeDebug: true,
  • // bundleInPaidRelease: true,
  • // bundleInBeta: true,
    *
  • // whether to disable dev mode in custom build variants (by default only disabled in release)
  • // for example: to disable dev mode in the staging build type (if configured)
  • devDisabledInStaging: true,
  • // The configuration property can be in the following formats
  • // 'devDisabledIn${productFlavor}${buildType}'
  • // 'devDisabledIn${buildType}'
    *
  • // the root of your project, i.e. where "package.json" lives
  • root: "../../",
    *
  • // where to put the JS bundle asset in debug mode
  • jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
    *
  • // where to put the JS bundle asset in release mode
  • jsBundleDirRelease: "$buildDir/intermediates/assets/release",
    *
  • // where to put drawable resources / React Native assets, e.g. the ones you use via
  • // require('./image.png')), in debug mode
  • resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
    *
  • // where to put drawable resources / React Native assets, e.g. the ones you use via
  • // require('./image.png')), in release mode
  • resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
    *
  • // by default the gradle tasks are skipped if none of the JS files or assets change; this means
  • // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
  • // date; if you have any other folders that you want to ignore for performance reasons (gradle
  • // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
  • // for example, you might want to remove it from here.
  • inputExcludes: ["android/", "ios/"],
    *
  • // override which node gets called and with what additional arguments
  • nodeExecutableAndArgs: ["node"],
    *
  • // supply additional arguments to the packager
  • extraPackagerArgs: []
  • ]
    */

project.ext.react = [
entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

/**

  • Set this to true to create two separate APKs instead of one:

    • An APK that only works on ARM devices


    • An APK that only works on x86 devices

  • The advantage is the size of the APK is reduced by about 4MB.
  • Upload all the APKs to the Play Store and people will download
  • the correct one based on the CPU architecture of their device.
    */
    def enableSeparateBuildPerCPUArchitecture = false

/**

  • Run Proguard to shrink the Java bytecode in release builds.
    */
    def enableProguardInReleaseBuilds = false

android {
compileSdkVersion 28
buildToolsVersion "28.0.3"

defaultConfig {
    applicationId "com.sampleapp"
    minSdkVersion 19
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }
    multiDexEnabled true
    missingDimensionStrategy 'react-native-camera', 'general'
}
signingConfigs {
            release {
                if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                    storeFile file(MYAPP_RELEASE_STORE_FILE)
                    storePassword MYAPP_RELEASE_STORE_PASSWORD
                    keyAlias MYAPP_RELEASE_KEY_ALIAS
                    keyPassword MYAPP_RELEASE_KEY_PASSWORD
                }
            }
        }


 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  // If true, also generate a universal APK
        include "armeabi-v7a", "x86"
    }
}

buildTypes {
    release {
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        signingConfig signingConfigs.release
    }
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
    variant.outputs.each { output ->
        // For each separate APK per architecture, set a unique version code as described here:
        // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
        def versionCodes = ["armeabi-v7a":1, "x86":2]
        def abi = output.getFilter(OutputFile.ABI)
        if (abi != null) {  // null for the universal-debug, universal-release variants
            output.versionCodeOverride =
                    versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
        }
    }
}

}

dependencies {
implementation project(':react-native-orientation')
implementation project(':react-native-device-info')
implementation (project(':react-native-camera')){
exclude group: "com.google.android.gms"
exclude group: "com.android.support"
}
implementation project(':@react-native-community_netinfo')
implementation project(':@react-native-community_async-storage')
implementation project(':react-native-gesture-handler')
implementation (project(':react-native-barcode-scanner-google')){
exclude group: "com.android.support"
}
implementation (project(':react-native-snackbar')){
exclude group: "com.android.support"
}
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:28.0.0"
implementation 'com.android.support:design:28.0.0'
implementation "com.android.support:multidex:1.0.3"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.google.android.gms:play-services-vision:15.0.2'
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}

configurations.all {
resolutionStrategy {
force 'com.android.support:support:28.0.0'
}
}`

Right, seems like deps are in place. What you can try:

  • Remove node_modules
  • Remove android/build and android/app/build dirs
  • Install deps yarn install
  • In android dir, run ./gradlew installDebug

Hopefully that clean will be sufficient to get it working.

@Krizzu Its working now after i have explicitly added react-native version in app/gradle file
* implementation 'com.facebook.react:react-native:0.59.8' *
Thanks for your help!!!

Glad you got it working 🎉

I saw that in my package.json file react-native-vector-icons dependence is absent. I don't know why.

In my case i just run 'npm install react-native-vector-icons' and it works well (android build is success when i try to run run-android command).

Screenshot 2020-08-20 at 22 03 42

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Krizzu picture Krizzu  ·  36Comments

michaelsinatra picture michaelsinatra  ·  24Comments

burhanahmed92 picture burhanahmed92  ·  27Comments

StevenMasini picture StevenMasini  ·  22Comments

Waqas-Jani picture Waqas-Jani  ·  28Comments