Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running #2

Open
timscott opened this issue Oct 28, 2016 · 4 comments
Open

Error running #2

timscott opened this issue Oct 28, 2016 · 4 comments
Labels

Comments

@timscott
Copy link

timscott commented Oct 28, 2016

When I follow the README setup instructions exactly, I get this error when I run:

MainApplication.java:42: error: cannot find symbol
          new LANScanReactModule()

If I do what has worked with other native modules, that is run react-native link react-native-lanscan and also add an import to MainApplication.java like so:

import com.example.reactnativelanscan.LANScanReactModule;

I get this error (in addition to the above error):

MainApplication.java:18: error: cannot find symbol
import com.example.reactnativelanscan.LANScanReactModule;
                                     ^

Thoughts?

@Odinvt
Copy link
Owner

Odinvt commented Oct 28, 2016

Hi !

Did you try importing from the correct package in MainApplication.java that is import com.odinvt.lanscan.LANScanReactModule ?

If so then you probably didn't put the include lines in the correct gradle files.

You should put this :

project(':react-native-lanscan').projectDir = new File(settingsDir, '../node_modules/react-native-lanscan/android')

inside the file MyReactNativeProject/android/settings.gradle. This basically tells gradle that if you include a module with the id :react-native-lanscan it should look for the source files of the module in the folder mentioned.
Then in the same file there should be a line include ':app' you just need to add there the ':react-native-lanscan module so the line should look like include ':app', ':react-native-lanscan' or if you use other react native plugins that have native code it looks like include ':app', ':react-native-lanscan', ':plugin2', ':plugin3'.

Then look for the file MyReactNativeProject/android/app/build.gradle (the one inside the app folder not the one inside the android folder) and look for the dependencies block and add the line compile project(":react-native-lanscan") to it so it should look something like this :

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
    compile project(':react-native-lanscan')
    compile project(':plugin2')
    compile project(':plugin3')
}

again depending on which modules your project depends on.

If you went through all these steps correctly and still get the error then probably gradle didn't compile the module correctly or has corrupt dependencies cached if so try deleting the .gradle/ folder inside your project's android folder and the one in your home folder under %USER_HOME%/.gradle/caches. Try also deleting the MyReactNativeProject/android/app/build/ folder if you have one then run react-native run-android inside your project folder.

If your project compiles correctly and you don't get any errors in your command line but you still do in Android Studio then try refreshing your project and using the gradle clean feature of android studio as that clears AS's cache as well and rerun.

Let me know how that works for you. Cheers !

@timscott
Copy link
Author

timscott commented Oct 28, 2016

The problem is here:

package="com.example.reactnativelanscan">

I guess react-native link uses AndroidManifest.xml to generate the import line in MainActivity.java.

That line should be:

package="com.odinvt.lanscan">

@Odinvt Odinvt added bug and removed help wanted labels Oct 28, 2016
@Odinvt
Copy link
Owner

Odinvt commented Oct 28, 2016

Yes you're right ! I'll solve that as soon as I can. Thanks !

@thecodecafe
Copy link

Hi @timscott, were you able to resolve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants