【问题标题】:Add "useLibrary" to build.gradle in android cordova plugin在 android cordova 插件中将“useLibrary”添加到 build.gradle
【发布时间】:2017-02-24 13:36:19
【问题描述】:

我正在开发一个 cordova 插件。在这个插件中,我使用库org.apache.http.legacy。我成功地将这个库复制到我的 lib 文件夹中。但我需要在我的 build.gradle 文件中写 useLibrary 'org.apache.http.legacy'

我该怎么做?

我的插件.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>
[...]

我尝试使用&lt;framework src="src/gradle/buildExtension.gradle" custom="true" type="gradleReference" /&gt;,其中buildExtension.gradle 包含

android {
    useLibrary 'org.apache.http.legacy'
}

但它没有用。顺便说一句,框架标签也不起作用。

有没有人可以解决这个问题?

【问题讨论】:

  • 我也遇到了同样的问题,你找到解决办法了吗?
  • 我认为这是我刚刚发布的解决方案。希望能帮助到你。祝你好运!

标签: android cordova cordova-plugins build.gradle


【解决方案1】:

这可能是解决方案:

我添加了一个 build-extras.gradle 文件,其中添加了 gradle 部分:

plugin.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'
}

【讨论】:

    猜你喜欢
    • 2018-12-07
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 2018-07-17
    • 1970-01-01
    • 2022-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多