Reputation: 99
I am working in a flutter plugin and want to import an .aar
project in android part of the plugin. I have tried opening the android project and importing the .aar
project by importing the module, including it in setting.gradle
and adding it in dependency of build.grade
(like any other native android project). However, when I run the flutter project, the .aar
project is not found.
The error I get is
A problem occurred evaluating project ':flutter_plugin_andriod'
Project with path ':commonlib' could not be found in project ':flutter_plugin_andriod'.
Anybody with the fix ?
Upvotes: 8
Views: 13056
Reputation: 1
This took me some time to figure out.
Create an empty folder in your Flutter android and add your aar file in my case the folder was called ftsdk and excute this command (you might need to brew install maven)
mvn install:install-file -Dfile=facetec-sdk-9.6.51-minimal.aar \
-DgroupId=com.facetec.sdk \
-DartifactId=default \
-Dversion=1.0.0 \
-Dpackaging=aar \
-DlocalRepositoryPath=./repository
This will generate a local maven repository in the same folder (if you leave out '-DlocalRepositoryPath' then it will default to your main maven folder usually '/Users/myUser/.m2'
In my Flutter Android build. gradle I included this directory under repositories (make sure its the allprojects repositories)
allprojects {
repositories {
google()
mavenCentral()
//mavenLocal() use this line if you let it generate in the default maven folder in /Users/myUser/.m2
maven {
url "$projectDir/ftsdk/repository"
}
}
}
Then in your build gradle dependencies you can add it as follows
android{
...
dependencies {
implementation 'com.facetec.sdk:default:1.0.0';
}
...
}
Answer inspired by this king: https://alessiobianchi.eu/blog/obfuscated-aar-local-maven/
Upvotes: 0
Reputation: 389
There is an open issue at Flutter's Github which at this day is still open.
The only way I could solve and import an AAR library into a Flutter Plugin was following these steps:
.aar
file to .zip
classes.jar
into libs
folder of you Flutter plugin.aar
file, so you won't get lost when importing it.jar
to your dependencies
:dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
}
Upvotes: 1
Reputation: 99
I finally found the answer.
Upvotes: 1
Reputation: 837
Follow these steps:
Create folder libs
in plugin_folder/android/ and put your *.aar file there.
In plugin_folder/android/build.gradle
rootProject.allprojects {
repositories {
google()
mavenCentral()
flatDir {
dirs project(':plugin_name').file('libs')
}
}
}
...
dependencies {
implementation (name: 'file-sdk-name', ext: 'aar')
...
}
Good luck!
Upvotes: 3
Reputation: 888
Put your .aar in Android/app/libs In Android/app/build.gradle you import the aar :
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation files('libs/myaarlibr.aar')
}
After this your .aar is ready for use
Upvotes: 3