How to enable third-party aura in Android React Native?

I am creating a React Native android module and my code imports classes from a third-party SDK, which is provided as aar file. How to link this file with my module? I tried adding

allprojects { repositories { flatDir { dirs: 'libs' } } } 

and

 dependencies { ... other deps ... compile (name:'my-external-lib', ext:'aar') } 

in the build.gradle file and placing this my-external-lib.aar file in the libs/ folder, but still getting an error message when creating an application with the MyApp active response with adaptive-my-module enabled:

 * 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 tips?

+5
source share
4 answers

It seems that I managed to resolve this issue myself. It seems that you need to define repositories in the main project in order to allow subprojects to find their dependencies.

Put this in the main build.gradle file of the project:

 repositories { flatDir { dirs: 'libs' } } 

did the trick.

I believe that this is not the right way to include subprojects with dependencies, because you obviously cannot know how to modify the build.gradle file if this library is a third-party lib from npm. So, can someone explain why this worked and how it should be done correctly?

+2
source

In your android/build.gradle you want to add .aar as an artifact.

 configurations.maybeCreate("default") artifacts.add("default", file("NAME_OF_YOUR_FILE.aar")) 
+2
source

What you wrote is absolutely correct, but you just wrote in the wrong place
you wrote the code in build.gradle (Project: project_name)
you just need to write the code in the build.gradle file (Module: app) and the .arr file needs to be inserted into the lib projects folder

those. repositories {
& EPRS; flatDir {
& EPRS; & EPRS; dirs 'libs'
& EPRS; }
}

dependencies {
& EPRS; & EPRS; ... other dep ... & EPRS; & EPRS; compile (name: 'my-external-lib', ext: 'aar')
}

+2
source

In your .gradle settings you should enable this lib eg.g:

 include ':app', ':my-external-lib' 

And you can compile it as a regular project, for example: compile project(':my-external-lib')

Also your my-external-lib build.gradle should look like this:

 configurations.maybeCreate("default") artifacts.add("default", file('my-external-lib.aar')) 
+1
source

Source: https://habr.com/ru/post/1272339/


All Articles