I am developing using React Native CLI as I need some Native Libraries in Android and iOS. Because of this I needed to use react-native link packagename
I then find out that the exposed methods for the Native Module in that package is not enough and I need to add some methods in the Native Module in Java (Android). Because of this I need to be able to debug in Java while I'm running React Native. I have tried System.out.println
and it does not work. How can I log some result or message in Java when it is being called in a React Native project????
On the native Android side, you need to use the Log
class from android.util.Log
for logging.
Then, use adb logcat
and filter the output for the tag provided to the function used from the Log
class.
For example, on native Android side:
Log.d("THIS IS MY TAG", "HELLO WORLD")
Then in a terminal (assuming you have adb
installed):
adb logcat -s "THIS IS MY TAG"
EDIT
Remember to add import android.util.Log
at the top of the file that uses Log.d
or anything else from the Log
class.
EDIT #2
Also, you will need to run a full rebuild of your React Native project so that the modified native files are updated.
You can do this by running the following command: react-native run-android
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.