I've written a Flutter plugin to use an SDK that requires the inclusion of some .aar modules. It builds and runs perfectly in the example app for the plugin, but when I import the plugin in a different app and try to build it, the build immediately fails with a message saying that one of the .aar modules could not be found in the plugin. This makes no sense because the module is definitely there - the platform channels to use the SDK would fail in the example app if the module wasn't there.
Why would the example app build and run without any problems but a different app won't? The only thing I can think of is that I import the plugin from path in my pubspec but it seems unlikely to me that this is the culprit.
Any advice or assistance here would be appreciated. TIA!
I got it!!!!
The answer is as found here: How to add .aar dependency in library module?
The way this adapts to a Flutter plugin is as follows:
libs
folder at the root of the android
project in the plugin. Add the .aar
files there.build.gradle
file, update rootProject.allProjects
to look as follows: repositories {
google()
jcenter()
flatDir {
dirs 'libs'
dirs project(':your_plugin_name_here').file('libs')
}
}
}
.aar
file(s) as dependencies as follows:implementation(name:'aar_name_here', ext:'aar')
build.gradle
file and add the plugin itself as a dependency, like so:android {
...
dependencies {
implementation project(':your_flutter_plugin');
}
}
settings.gradle
file for the app that us using the plugin, changeinclude ':app'
to
include ':app', ':your_flutter_plugin'
And this should do it!!