Cordova Plugin - Add third party sdk

白昼怎懂夜的黑 提交于 2019-12-11 07:39:41

问题


I am trying to create the plugin for the following sdk - https://ktplayhelp.zendesk.com/hc/en-us/articles/221071888-Android

In the setup project configuration point it is telling to setup the sdk by importing module in Android studio and add the dependency in our application's build.gradle file.

Can anyone please help and tell me how can I import the Android native module in Cordova without using Android studio?


回答1:


As you can't modify cordovas .gradle file you have to add your own and reference it in your plugin.xml you can do that like this:

<framework src="src/android/*.gradle" custom="true" type="gradleReference" />

This will allow you to do things like compiling an external module. To make this actually work you will have to create an .aar library out of the project you want to integrate.

The resulting gradle-extension will look something like this:

repositories {    
    jcenter()
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    compile(name:'KTplay', ext:'aar')
}

android {
    packagingOptions {
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
    }
}

This assumes that you have put your .aar library in a subdirectory of your plugin named libs. Whats left to do is to ensure that the library actually gets copied during the build process, this is why we have to add it as a resource file in plugin.xml:

<resource-file src="libs/KTplay.aar" target="libs/KTplay.aar" />


来源:https://stackoverflow.com/questions/46199606/cordova-plugin-add-third-party-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!