31

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?

BanAnanas
  • 478
  • 8
  • 17
Dfarrelly
  • 695
  • 2
  • 7
  • 24

6 Answers6

23

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.

Nick
  • 2,576
  • 1
  • 23
  • 44
  • I'm really surprised, but this solution worked for me!! Thanks for the posting! My problem was with com.android.build.gradle.LibraryExtension, but it basically was the same issue. By the way, I was using that import in a number of places, so I commented out all usages before I ran the gradle sync. – Tom Rutchik Jan 25 '23 at 21:29
  • Thanks for the suggestion. Unfotunately it' hasn't worked for me... – Lauro235 Feb 27 '23 at 20:10
7

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

shiraz27
  • 1,898
  • 18
  • 14
  • 1
    As I set import of Output file, it was automatically removing the line for import, replacing this code really helped, Thank you for saving my day!! – Ayush Katuwal Apr 02 '22 at 09:26
  • Thanks for the suggestion, unfortunately it hasn't worked for me. – Lauro235 Feb 27 '23 at 20:11
  • @Lauro235 could you give more input, maybe I can help. – shiraz27 Mar 01 '23 at 06:56
  • Thanks Shiraz. I initialised with npx create-react-ntaive-app "dependencies": { "expo": "~47.0.12", "expo-splash-screen": "~0.17.5", "expo-status-bar": "~1.4.2", "react": "18.1.0", "react-native": "0.70.5", "react-native-auth0": "^2.17.1" }, "devDependencies": { "@babel/core": "^7.12.9", "metro-react-native-babel-preset": "^0.75.1", "react-native-dotenv": "^3.4.7" }, Android has always had a problem with BuildConfig I can run app with dev-client, but attempting development builds fail due to build config.. – Lauro235 Mar 01 '23 at 11:01
  • this might be coming late but here's my try: 1. try my solution 2. try cleaning the project and rebuilding it by selecting Build > clean project and then build > rebuild project from the Android studio menu. 3. select file > invalidate caches / restart from the Android studio menu. – shiraz27 Mar 09 '23 at 22:17
3

if you want to find the exact problem, go to the Android folder and assembleRelease using the terminal window:

 cd android
 .\gradlew assembleRelease

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

installing the recommended version solved my problem

Mahdieh Shavandi
  • 4,906
  • 32
  • 41
2

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.

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
1

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.

Wasi Sadman
  • 1,382
  • 1
  • 15
  • 27
-1

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

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • 1
    classpath 'com.android.tools.build:gradle:2.2.0' should be in the dependencies of Buildscript block not in the dependencies block of app level build.gradle – Habib Kazemi Jul 25 '19 at 18:47