Note: This steps are specific to include aar file, I assume you have created a phoneGap plugin before if not go here after that follow these steps.
Step 0:
This is just a structure of how your plugin folder should look like.
pluginFolder/
build-extras.gradle
plugin.xml
aar/yourAarFile.aar
src/
android/
yourFile.gradle
myPlugin.java
Step 1:
Create plugin folder with this sub-folders: src, www and aar (if there is one).
Step 2:
Create these files in the plugin folder plugin.xml, build-extras.gradle and package.json (this is only need it if is going to be public).
Step 3:
In your plugin.xml file insert the following lines:
<platform name="android”>
<config-file target="res/xml/config.xml" parent="/*">
<feature name=“myPlugin.java” > <!—add this without the .java extension just the name —>
<param name="android-package" value=“myPlugin.java"/>
</feature>
</config-file>
<feature name=“myPlugin.java” > <!—add this without the .java extension just the name —>
<param name="android-package" value=“myPlugin.java"/>
</feature>
</config-file>
<!-- your configuration elements, references, source files, etc... —>
<framework src="src/android/yourFile.gradle" custom="true" type="gradleReference" />
<resource-file src=“aar/yourAarFile.aar" target=“aar/yourAarFile.aar" />
</platform>
Step 4:
In yourFile.gradle put the following lines:
repositories{
jcenter()
flatDir{
dirs ‘aar’
}
}
dependencies {
compile(name:'yourAarFile', ext:'aar’)
}
android { packagingOptions { exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' }
}
Step 5:
In build-extras.gradle put the following lines:
android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
}
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE
’
}
}
Step 6:
Create your java file myPlugin.java and put it in the src/android/ folder
Step 7:
Now you can use the aar file from your plugin java Class.
But .class file is not found at runtime
ReplyDeleteCan you describe the issue you are having a little more so I can try to help you.
Deleteplease, where should i put the plugin folder from my root project folder ? I have www, hooks, platform, plugins folders and a file "config.xml".
ReplyDeleteYou should install the plugin you want using the terminal(mac) or command(windows), example:
Deletemac:
1-go to your application folder from terminal and do
sudo cordova plugin add ~/path/where/your/plugin/is
That should do it for you. Hope it helps
Thank you
DeleteHi
ReplyDeleteI have been given a .aar file as part of android sdk. I need to convert it to cordova plugin. Guide me
Hi Vag, the first thing you need to do is follow this https://cordova.apache.org/docs/en/dev/guide/hybrid/plugins/index.html tutorial on how to do your plugin without the .arr file after that come here and follow this steps and if you have any more questions feel free to ask me. :D
Deletei have done ionic 1 project, may i know where to put the myPlugin.java exactly, platforms/android or platforms/android/src/com/...
ReplyDeleteHi ombalakumar, this is a plugin and not an application project, in the plugin directory structure there is a path like this src/android/ and there is where your java file should go. Hope it help.
Deleteyes i got it already, anyways thanks for the fast reply, continue with your great work.
Deletecan you please elaborate the myPlugin.java file or post the coding in this example. It will be helpful for me and other developers too thanks.
DeleteEverything is working perfect but when i try to add plugin with aar file, i am getting
DeleteFailed to install 'cordova-plugin-sdk':Error: ENOENT:
no such file or directory, open 'C:\Users\user27\Documents\sdk_plugin_test\platforms
\android\cordova-plugin-sdk\filename.aar\build.gradle'
Can you share github url to sample project
ReplyDeleteAdd AAR file in ionic 3 application by creating custom cordova plugin
ReplyDeleteat build time it show error
I've error "failed to resolve 'yourAarFile'".
ReplyDeleteCan someone help?
fix it changing dirs field to src/main/libs and using 'libs' as name folder instead of 'aar' (maybe this is the same):
Deleterepositories{
jcenter()
flatDir{
dirs 'src/main/libs'
}
}
How would you know if the AAR plugin is included inside the project?
ReplyDeleteHow to Play Baccarat in the United States - Wolverione
ReplyDeleteBaccarat is the first to make use of the fun88 vin traditional 52-card 1xbet korean deck of cards. 바카라 사이트 This deck of playing cards is also called the Blackjack.