'Cannot resolve symbol 'build' on line import com.android.build.OutputFile in app/build.gradle

So I just created a react native project using the command

react-native init "project-name"

I went into the app level build.gradle to connect firebase and I had an error saying could not resolve symbol 'android' on the line

import com.android.build.OutputFile

However, it popped up saying "android framework is detected in the project click to configure" so I did this, but then it said cannot resolve symbol 'build' on the same line, I have no idea why it's saying this as I have made the project the same way before and never had this problem, any ideas?



Solution 1:[1]

In my case I was able to solve this by following those steps:

  1. Comment out the line like this: // import com.android.build.OutputFile
  2. Sync the project (click "Sync now")
  3. Comment in the line again like this: import com.android.build.OutputFile
  4. Sync again.

This might not work for everybody. In my case said import worked until I changed something somewhere in the project and suddenly the import failed. If the import never worked for you, this might not be the solution, but otherwise worth a try.

Solution 2:[2]

the thing that worked for me was

1- replace this line in build.gradle(:app)

def abi = output.getFilter(OutputFile.ABI)

with:

def abi = output.getFilter(com.android.build.OutputFile.ABI)

2- and click on sync project with gradle files (the elephant with blue arrow)

enter image description here

Solution 3:[3]

Try double click on build word in your code such as Build.VERSION, not in the import com.android.build.OutputFile. then if it show press ALT + Enter, you should do it.

Solution 4:[4]

Change the classpath 'com.android.tools.build:gradle:3.4.1' to 3.4.2 in your package build.gradle file

For me, i was using

classpath 'com.android.tools.build:gradle:3.4.1'

Then i have just changed the version to 3.4.2 an the problem was fixed.

Solution 5:[5]

if you want to find the exact problem, go to the android folder and assembleRelease using cmd:

 cd android
 gradlew assembleRelease

my problem was with the crashlytics package that was needing another version of the react-native-firebase/app package

installing the recommended version solved my problem

Solution 6:[6]

Be sure you have classpath 'com.android.tools.build:gradle:2.2.0' in the dependencies block of your app level build.gradle file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nick
Solution 2 shiraz27
Solution 3 Billal Begueradj
Solution 4 Wasi Sadman
Solution 5 Mahdieh Shavandi
Solution 6 Code-Apprentice