react-native-lanscan
react-native-lanscan copied to clipboard
Error running
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?
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 !
The problem is here: https://github.com/Odinvt/react-native-lanscan/blob/f9185b65163a3dad4ba6ce8704c7183ec971386a/android/src/main/AndroidManifest.xml#L2
I guess react-native link
uses AndroidManifest.xml
to generate the import line in MainActivity.java
.
That line should be:
package="com.odinvt.lanscan">
Yes you're right ! I'll solve that as soon as I can. Thanks !
Hi @timscott, were you able to resolve this?