I am building an android React Native module and my code imports classes from a 3rd party SDK which is provided as an aar file. How should I bundle this file into my module? I tried adding
allprojects {
repositories {
flatDir {
dirs: 'libs'
}
}
}
and
dependencies {
... other deps ...
compile (name:'my-external-lib', ext:'aar')
}
to the build.gradle file and putting this my-external-lib.aar file into libs/
folder, but still getting an error when building MyApp react-native application with react-native-my-module included:
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration
':app:_developmentDebugApkCopy'.
> Could not find :my-external-lib:.
Required by:
MyApp:app:unspecified > MyApp:react-native-my-module:unspecified
Any advice?
Add your AAR or JAR as a dependency Navigate to File > Project Structure > Dependencies. In the Declared Dependencies tab, click and select Jar Dependency in the dropdown. In the Add Jar/Aar Dependency dialog, first enter the path to your . aar or .
On the React Native side, you can call both iOS and Android native modules. This is a complete example of a React Native component calling the native module: And that's it for coding, now for the final results.
You will need Node, the React Native command line interface, a JDK, and Android Studio. While you can use any editor of your choice to develop your app, you will need to install Android Studio in order to set up the necessary tooling to build your React Native app for Android.
Looks like I managed to solve this question by myself.
It seems that you need to define repositories
in the main project to allow sub-projects locate their dependencies.
Putting this to the main project build.gradle file:
repositories {
flatDir {
dirs: 'libs'
}
}
did the trick.
I believe though, that this is not the correct way to include sub-projects with dependencies, because you're obviously can't know how to amend your build.gradle file if this library is a 3rd party lib from npm. So, can someone explain why this worked and how should it be done in the right way?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With