我正在开发一个 cordova 插件。在这个插件中,我使用库 org.apache.http.legacy
.我在我的 lib 文件夹中成功复制了这个库。但我需要写 useLibrary 'org.apache.http.legacy'
在我的 build.gradle 文件中。
我该怎么做?
我的插件.xml:
[...]
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="DownloaderActivity" android:launchMode="singleTop" android:name="[pluginPath].DownloaderActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustPan">
</activity>
<service android:name="[pluginPath].DownloaderService" />
<receiver android:name="d[pluginPath].DownloaderServiceBroadcastReceiver" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
</config-file>
<config-file target="res/xml/config.xml" parent="/*">
<feature name="ExpansionFileReader">
<param name="android-package" value="[pluginPath].ExpansionFileReader" />
</feature>
</config-file>
<source-file src="src/android/ExpansionFileReader.java" target-dir="src/de/[path]/cordova/plugin" />
<source-file src="src/android/expansion" target-dir="src/de/[path]/cordova/plugin" />
<source-file src="src/android/zipfile" target-dir="src/de/[path]/cordova/plugin" />
<source-file src="src/com" target-dir="src" />
<source-file src="src/android/org.apache.http.legacy.jar" target-dir="libs" framework="true" />
<framework src="com.google.http-client:google-http-client-android:+" />
<framework src="com.google.api-client:google-api-client-android:+" />
<framework src="com.google.api-client:google-api-client-gson:+" />
<framework src="com.google.code.gson:gson:2.2.4" />
</platform>
[...]
我尝试使用 <framework src="src/gradle/buildExtension.gradle" custom="true" type="gradleReference" />
, 其中buildExtension.gradle
包含
android {
useLibrary 'org.apache.http.legacy'
}
但是没有用。顺便说一下,框架标签也不起作用。
有人对此有解决方案吗?
最佳答案
这可能是解决方案:
我添加了一个 build-extras.gradle 文件,其中添加了 gradle 部分:
插件.xml:
[...]
<source-file src="src/android/ExpansionFileReader.java" target-dir="src/de/projektionisten/cordova/plugin" />
<source-file src="src/android/expansion" target-dir="src/de/projektionisten/cordova/plugin" />
<source-file src="src/android/zipfile" target-dir="src/de/projektionisten/cordova/plugin" />
<source-file src="src/com" target-dir="src" />
<source-file src="src/android/build-extras.gradle" target-dir="CordovaLib" />
<source-file src="src/android/org.apache.http.legacy.jar" target-dir="libs" framework="true" />
<framework src="src/android/build-extras.gradle" custom="true" type="gradleReference" />
[...]
build-extras.gradle:
android {
useLibrary 'org.apache.http.legacy'
}
关于android - 将 "useLibrary"添加到 android cordova 插件中的 build.gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42440001/