In the rn development, if encountered a special function, if there is no ready-made wheels, we usually need to link the native libraries, and encapsulated into an rn components for js calls, as a front-end developer, usually we don’t understand, for the error on the native processing in processing and primary function related issues, recommend to use android – studi directly O to develop (project name -> Android ->app->build.gradle), it can assist us to easily download third-party libraries, and problems such as flashback can be clearly viewed in the log.
The following lists some of the common problems we encounter with linked native libraries
1.
This error often occurs when first encapsulating a higher version of the React-Native library or referencing an older version of the library because
Because the method you misreported exists in the old version of RN, I guess the three parties are the old version of RN, the new version does not have this method, just comment it out.
If you prefer to use a non-react-native link library, you may encounter this problem. The reason is simple: when importing the library, you need to specify the location of the library in setting. Gradle
implementation(name: 'x x x x x x x aar package'.ext: 'aar') {
exclude module: 'gson'
}
Copy the code
However, in our project, we tried many ways to filter it, so we adopted the second solution. We unpacked the AAR and copied the Java files inside. In addition, Provided is adopted to introduce Alipay, so that we can use the latest Alipay when compiling Compile, but it will not be packaged into our project eventually. In our project, we still use the old Alipay. If we want to use aar alipay later, we can directly change Provided into Compiled
compile "com.facebook.react:react-native:+"
compile files('libs/volley.jar')
provided files('libs/alipaySdk-20180403.jar')
compile files('libs/wechat - SDK - android - without - the mta - 5.1.6. Jar')
Copy the code
java.io.IOException: Could not delete path 'F:\xxxx\android\app\build\intermediates\transforms\dex\debug\folders\1000'.
Copy the code
Run the react-native run-Android on the console as an administrator. If an error occurs, delete the build folder in the ‘F: XXXX ‘android’ app directory manually.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-device-info:prepareComAndroidSupportAppcompatV72301Library'.
> Could not expand ZIP 'D: \ \ extras \ android SDK \ m2repository \ com \ android \ support \ appcompat - v7\23.0.1 \ appcompat - v7-23.0.1. Aar'.
Copy the code
Delete the build folder in F:\ XXXXX \node_modules\react-native device-info\android. (Note: the react-native device-info component is used as an example. If other components report similar problems, the directory is \node_modules\ component name \ Android.)
In Windows, it is often encountered that deleting folders requires administrator permission, but the administrator permission is still not deleted. At this time, we can use the compression tool to compress the corresponding files, and choose to delete the source files after compression to delete or restart the computer and then delete
The SDK Build Tools revision (23.0.1) is too low forProject ': the react - native - vector - the ICONS'. MinimumCopy the code
This error is also common when introducing third party libraries, and it is easy to change. Go to the build.gradle folder of the corresponding library and change buildToolsVersion to the corresponding version
Pay attention to
In RN, if we only change js code, we only need reload, but as long as we change native code, including Manifest and some resource files, we need to recompile and package to take effect. If we add libraries and other operations, it is recommended to clear build first and then build
The ultimate way to
Finally, if you find that your code is working correctly, the path is correct, etc., try deleting the Build folder under the Android directory and app directory (package the auto-generated files), and finally
If the fault persists, restart the port. The port may be occupied