4

I was running my existing React Native Project in my real android device. Then somehow this error pop up. The error are always about "cannot find symbol". I have JDK and SDK and add into my system variables. But I still do not know why it gives me error like this. As I remember, I just downgrade the version of react-native.

:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.). D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainApplication.java:5: error: cannot find symbol import com.facebook.react.ReactApplication; ^ symbol: class ReactApplication location: package com.facebook.react D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainApplication.java:6: error: cannot find symbol import com.facebook.react.ReactNativeHost; ^ symbol: class ReactNativeHost location: package com.facebook.react D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainApplication.java:14: error: cannot find symbol public class MainApplication extends Application implements ReactApplication { ^ symbol: class ReactApplication D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainApplication.java:16: error: cannot find symbol private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { ^ symbol: class ReactNativeHost location: class MainApplication D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainApplication.java:36: error: cannot find symbol public ReactNativeHost getReactNativeHost() { ^ symbol: class ReactNativeHost location: class MainApplication D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainActivity.java:5: error: MainActivity is not abstract and does not override abstract method getPackages() in ReactActivity public class MainActivity extends ReactActivity { ^ D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainApplication.java:16: error: cannot find symbol private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { ^ symbol: class ReactNativeHost location: class MainApplication D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainApplication.java:35: error: method does not override or implement a method from a supertype @Override ^ 8 errors :app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'. Compilation failed; see the compiler error output for details.

Build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
        repositories {
           jcenter()
        }
     dependencies {
         classpath 'com.android.tools.build:gradle:2.2.3'

         // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
     }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
             // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
             url "$rootDir/../node_modules/react-native/android"
        }
    }
}

Build.gradle/app:

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "com.emptyprojecttemplate"
    minSdkVersion 16
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }
}
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"
    }
}
// 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 {
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

 // 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'
 }
Liza Catherine Ombyaw
  • 804
  • 2
  • 11
  • 27
  • Have a look here: https://stackoverflow.com/questions/39812898/react-native-android-appcompiledebugjava-error. Are you using React Native Navigation? Also which versions are you using? – JRK Sep 24 '18 at 10:10
  • I'm not using React Native navigation because this project is new. I have react 16.3.1, react-native-cli 2.0.1 , react-native 0.55.4 – Liza Catherine Ombyaw Sep 24 '18 at 10:48

2 Answers2

4

Your stacktrace starts with : error: cannot find symbol import com.facebook.react.ReactApplication this seems to suggest it cannot find the React Library import.

I'm going to include a answer on Github for you, read here:

https://github.com/transistorsoft/react-native-background-geolocation/issues/294

(Btw, this relates to your build.gradle in /your-project/android/build.gradle)

In case anyone else is experiencing the same issue: make sure you correctly add new repositories. According to Android docs every maven repo should be in its own maven {} block.

That's why

maven {
    // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
    url "$rootDir/../node_modules/react-native/android"
    url 'some new extra repo'
}

breaks dependencies. The correct version is

maven {
    // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
    url "$rootDir/../node_modules/react-native/android"
}
maven {
    url 'some new extra repo'
}

UPDATE

As the above isn't solving your issue and your build.gradle(s) look good (to me). I'll include some other solutions :

Upgrade RN and RN-cli as advised here:

Cannot resolve symbol ReactApplication/ReactNativeHost

Another here:

FAILURE: Build failed with an exception in react-native Android

Another here:

React native android error: cannot find symbol

Last resort

It may be worth in just creating a new test project (with the latest versions) like react-native init anotherproject to see if that runs.

JRK
  • 3,686
  • 1
  • 13
  • 19
  • So I will just copy it? – Liza Catherine Ombyaw Sep 24 '18 at 10:59
  • In my case there is no "url 'some new extra repo'" – Liza Catherine Ombyaw Sep 24 '18 at 11:00
  • Can you include your build.gradle in your original question. The 'some extra repo' is just an example of how to add another url in maven. It's not a valid URL. – JRK Sep 24 '18 at 11:03
  • @LizaCatherineOmbyaw - can you also include your app/build.gradle your root one looks good. – JRK Sep 24 '18 at 11:20
  • @LizaCatherineOmbyaw- it's located in `your-project/android/app/build.gradle` – JRK Sep 24 '18 at 11:23
  • It worked now by using `react-native init projectname'. I am just following the tutorial in udemy haha but gives me error. Because he is using `create-react-native-app projectname` for expo then ejecting the project. Can you explain why it gives me error like that? – Liza Catherine Ombyaw Sep 24 '18 at 14:08
  • @LizaCatherineOmbyaw I'm not sure, I haven't used that! If you could accept and upvote the answer that would be great :) – JRK Sep 24 '18 at 14:11
0

I ran into the same issue recently, so I would like the readers to know what I did to get the app working. Initially the app wouldn't even launch so I used 'react-native init' command to get it to work. But the app still wouldn't launch and it gave me a server error, so I found the solution on this link for it : https://github.com/facebook/react-native/issues/21310 and followed this suggestion:

npm add @babel/runtime
npm install

My app started working like a charm !

camille
  • 16,432
  • 18
  • 38
  • 60
Devashree
  • 201
  • 2
  • 4