简体   繁体   中英

Can't build Phonegap app with plugin from npm

Phonegap Build throws an error during build. I've just added this string to "config.xml".

<plugin name="cordova-plugin-mauron85-background-geolocation" source="npm" spec="^2.2.0"/>

This is my "config.xml" file.

 <?xml version='1.0' encoding='utf-8'?> <widget id="com.phonegap.helloworld" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0"> <name>MyApp</name> <description> My new app </description> <author email="support@phonegap.com" href="http://phonegap.com"> PhoneGap Team </author> <content src="index.html" /> <preference name="DisallowOverscroll" value="true" /> <preference name="android-minSdkVersion" value="14" /> <preference name="android-build-tool" value="gradle" /> <plugin name="cordova-plugin-mauron85-background-geolocation" source="npm" spec="^2.2.0"/> <plugin name="cordova-plugin-battery-status" source="npm" spec="~1.1.1" /> <plugin name="cordova-plugin-camera" source="npm" spec="~2.1.1" /> <plugin name="cordova-plugin-media-capture" source="npm" spec="~1.2.0" /> <plugin name="cordova-plugin-console" source="npm" spec="~1.0.2" /> <plugin name="cordova-plugin-contacts" source="npm" spec="~2.0.1" /> <plugin name="cordova-plugin-device" source="npm" spec="~1.1.1" /> <plugin name="cordova-plugin-device-motion" source="npm" spec="~1.2.0" /> <plugin name="cordova-plugin-device-orientation" source="npm" spec="~1.0.2" /> <plugin name="cordova-plugin-dialogs" source="npm" spec="~1.2.0" /> <plugin name="cordova-plugin-file" source="npm" spec="~4.1.1" /> <plugin name="cordova-plugin-file-transfer" source="npm" spec="~1.5.0" /> <plugin name="cordova-plugin-geolocation" source="npm" spec="~2.1.0" /> <plugin name="cordova-plugin-globalization" source="npm" spec="~1.0.3" /> <plugin name="cordova-plugin-inappbrowser" source="npm" spec="~1.3.0" /> <plugin name="cordova-plugin-media" source="npm" spec="~2.2.0" /> <plugin name="cordova-plugin-network-information" source="npm" spec="~1.2.0" /> <plugin name="cordova-plugin-splashscreen" source="npm" spec="~3.2.1" /> <plugin name="cordova-plugin-statusbar" source="npm" spec="~2.1.2" /> <plugin name="cordova-plugin-vibration" source="npm" spec="~2.1.0" /> <plugin name="cordova-plugin-whitelist" source="npm" spec="~1.2.1" /> <platform name="android"> <icon density="ldpi" src="www/res/icon/android/drawable-ldpi-icon.png" /> <icon density="mdpi" src="www/res/icon/android/drawable-mdpi-icon.png" /> <icon density="hdpi" src="www/res/icon/android/drawable-hdpi-icon.png" /> <icon density="xhdpi" src="www/res/icon/android/drawable-xhdpi-icon.png" /> <icon density="xxhdpi" src="www/res/icon/android/drawable-xxhdpi-icon.png" /> <icon density="xxxhdpi" src="www/res/icon/android/drawable-xxxhdpi-icon.png" /> <splash density="land-ldpi" src="www/res/screen/android/drawable-land-ldpi-screen.png" /> <splash density="land-mdpi" src="www/res/screen/android/drawable-land-mdpi-screen.png" /> <splash density="land-hdpi" src="www/res/screen/android/drawable-land-hdpi-screen.png" /> <splash density="land-xhdpi" src="www/res/screen/android/drawable-land-xhdpi-screen.png" /> <splash density="land-xxhdpi" src="www/res/screen/android/drawable-land-xxhdpi-screen.png" /> <splash density="land-xxxhdpi" src="www/res/screen/android/drawable-land-xxxhdpi-screen.png" /> <splash density="port-ldpi" src="www/res/screen/android/drawable-port-ldpi-screen.png" /> <splash density="port-mdpi" src="www/res/screen/android/drawable-port-mdpi-screen.png" /> <splash density="port-hdpi" src="www/res/screen/android/drawable-port-hdpi-screen.png" /> <splash density="port-xhdpi" src="www/res/screen/android/drawable-port-xhdpi-screen.png" /> <splash density="port-xxhdpi" src="www/res/screen/android/drawable-port-xxhdpi-screen.png" /> <splash density="port-xxxhdpi" src="www/res/screen/android/drawable-port-xxxhdpi-screen.png" /> </platform> <access origin="*" /> <allow-intent href="http://*/*" /> <allow-intent href="https://*/*" /> <allow-intent href="tel:*" /> <allow-intent href="sms:*" /> <allow-intent href="mailto:*" /> <allow-intent href="geo:*" /> <platform name="android"> <allow-intent href="market:*" /> </platform> </widget> 

This is my error log:

 -------------------------------------------------------------------------------- PLUGIN OUTPUT -------------------------------------------------------------------------------- Fetching plugin "cordova-plugin-mauron85-background-geolocation@^2.2.0" via npm Installing "cordova-plugin-mauron85-background-geolocation" at "2.2.5" for android Fetching plugin "cordova-plugin-battery-status@~1.1.1" via npm Installing "cordova-plugin-battery-status" at "1.1.2" for android Fetching plugin "cordova-plugin-camera@~2.1.1" via npm Installing "cordova-plugin-camera" at "2.1.1" for android Fetching plugin "cordova-plugin-media-capture@~1.2.0" via npm Installing "cordova-plugin-media-capture" at "1.2.0" for android Fetching plugin "cordova-plugin-file" via npm Installing "cordova-plugin-file" at "4.3.1" for android Fetching plugin "cordova-plugin-compat" via npm Installing "cordova-plugin-compat" at "1.1.0" for android The Android Persistent storage location now defaults to "Internal". Please check this plugin's README to see if your application needs any changes in its config.xml. If this is a new application no changes are required. If this is an update to an existing application that did not specify an "AndroidPersistentFileLocation" you may need to add: "<preference name="AndroidPersistentFileLocation" value="Compatibility" />" to config.xml in order for the application to find previously stored files. Fetching plugin "cordova-plugin-console@~1.0.2" via npm Installing "cordova-plugin-console" at "1.0.5" for android Fetching plugin "cordova-plugin-contacts@~2.0.1" via npm Installing "cordova-plugin-contacts" at "2.0.1" for android Fetching plugin "cordova-plugin-device@~1.1.1" via npm Installing "cordova-plugin-device" at "1.1.4" for android Fetching plugin "cordova-plugin-device-motion@~1.2.0" via npm Installing "cordova-plugin-device-motion" at "1.2.3" for android Fetching plugin "cordova-plugin-device-orientation@~1.0.2" via npm Installing "cordova-plugin-device-orientation" at "1.0.5" for android Fetching plugin "cordova-plugin-dialogs@~1.2.0" via npm Installing "cordova-plugin-dialogs" at "1.2.1" for android Plugin "cordova-plugin-file" already installed on android. Making it top-level. Fetching plugin "cordova-plugin-file-transfer@~1.5.0" via npm Installing "cordova-plugin-file-transfer" at "1.5.1" for android Dependent plugin "cordova-plugin-file" already installed on android. Fetching plugin "cordova-plugin-geolocation@~2.1.0" via npm Installing "cordova-plugin-geolocation" at "2.1.0" for android Fetching plugin "cordova-plugin-globalization@~1.0.3" via npm Installing "cordova-plugin-globalization" at "1.0.5" for android Fetching plugin "cordova-plugin-inappbrowser@~1.3.0" via npm Installing "cordova-plugin-inappbrowser" at "1.3.0" for android Fetching plugin "cordova-plugin-media@~2.2.0" via npm Installing "cordova-plugin-media" at "2.2.0" for android Dependent plugin "cordova-plugin-file" already installed on android. Fetching plugin "cordova-plugin-network-information@~1.2.0" via npm Installing "cordova-plugin-network-information" at "1.2.1" for android Fetching plugin "cordova-plugin-splashscreen@~3.2.1" via npm Installing "cordova-plugin-splashscreen" at "3.2.2" for android Fetching plugin "cordova-plugin-statusbar@~2.1.2" via npm Installing "cordova-plugin-statusbar" at "2.1.3" for android Fetching plugin "cordova-plugin-vibration@~2.1.0" via npm Installing "cordova-plugin-vibration" at "2.1.3" for android Fetching plugin "cordova-plugin-whitelist@~1.2.1" via npm Installing "cordova-plugin-whitelist" at "1.2.2" for android This plugin is only applicable for versions of cordova-android greater than 4.0. If you have a previous platform version, you do *not* need this plugin since the whitelist will be built in. -------------------------------------------------------------------------------- COMPILE OUTPUT -------------------------------------------------------------------------------- Configuration on demand is an incubating feature. Incremental java compilation is an incubating feature. :preBuild UP-TO-DATE :preDebugBuild UP-TO-DATE :checkDebugManifest :preReleaseBuild UP-TO-DATE :CordovaLib:preBuild UP-TO-DATE :CordovaLib:preDebugBuild UP-TO-DATE :CordovaLib:compileDebugNdk UP-TO-DATE :CordovaLib:compileLint :CordovaLib:copyDebugLint UP-TO-DATE :CordovaLib:mergeDebugProguardFiles :CordovaLib:packageDebugRenderscript UP-TO-DATE :CordovaLib:checkDebugManifest :CordovaLib:prepareDebugDependencies :CordovaLib:compileDebugRenderscript :CordovaLib:generateDebugResValues :CordovaLib:generateDebugResources :CordovaLib:packageDebugResources :CordovaLib:compileDebugAidl :CordovaLib:generateDebugBuildConfig :CordovaLib:mergeDebugShaders :CordovaLib:compileDebugShaders :CordovaLib:generateDebugAssets :CordovaLib:mergeDebugAssets :CordovaLib:processDebugManifest :CordovaLib:processDebugResources :CordovaLib:generateDebugSources :CordovaLib:incrementalDebugJavaCompilationSafeguard :CordovaLib:compileDebugJavaWithJavac :CordovaLib:compileDebugJavaWithJavac - is not incremental (eg outputs have changed, no previous execution, etc.). Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. :CordovaLib:processDebugJavaRes UP-TO-DATE :CordovaLib:transformResourcesWithMergeJavaResForDebug :CordovaLib:transformClassesAndResourcesWithSyncLibJarsForDebug :CordovaLib:mergeDebugJniLibFolders :CordovaLib:transformNative_libsWithMergeJniLibsForDebug :CordovaLib:transformNative_libsWithSyncJniLibsForDebug :CordovaLib:bundleDebug :CordovaLib:preReleaseBuild UP-TO-DATE :CordovaLib:compileReleaseNdk UP-TO-DATE :CordovaLib:copyReleaseLint UP-TO-DATE :CordovaLib:mergeReleaseProguardFiles :CordovaLib:packageReleaseRenderscript UP-TO-DATE :CordovaLib:checkReleaseManifest :CordovaLib:prepareReleaseDependencies :CordovaLib:compileReleaseRenderscript :CordovaLib:generateReleaseResValues :CordovaLib:generateReleaseResources :CordovaLib:packageReleaseResources :CordovaLib:compileReleaseAidl :CordovaLib:generateReleaseBuildConfig :CordovaLib:mergeReleaseShaders :CordovaLib:compileReleaseShaders :CordovaLib:generateReleaseAssets :CordovaLib:mergeReleaseAssets :CordovaLib:processReleaseManifest :CordovaLib:processReleaseResources :CordovaLib:generateReleaseSources :CordovaLib:incrementalReleaseJavaCompilationSafeguard :CordovaLib:compileReleaseJavaWithJavac :CordovaLib:compileReleaseJavaWithJavac - is not incremental (eg outputs have changed, no previous execution, etc.). Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. :CordovaLib:processReleaseJavaRes UP-TO-DATE :CordovaLib:transformResourcesWithMergeJavaResForRelease :CordovaLib:transformClassesAndResourcesWithSyncLibJarsForRelease :CordovaLib:mergeReleaseJniLibFolders :CordovaLib:transformNative_libsWithMergeJniLibsForRelease :CordovaLib:transformNative_libsWithSyncJniLibsForRelease :CordovaLib:bundleRelease :prepareComAndroidSupportSupportCompat2510Library :prepareComAndroidSupportSupportCoreUi2510Library :prepareComAndroidSupportSupportCoreUtils2510Library :prepareComAndroidSupportSupportFragment2510Library :prepareComAndroidSupportSupportMediaCompat2510Library :prepareComAndroidSupportSupportV42510Library :prepareComGoogleAndroidGmsPlayServicesBase1001Library :prepareComGoogleAndroidGmsPlayServicesBasement1001Library :prepareComGoogleAndroidGmsPlayServicesLocation1001Library :prepareComGoogleAndroidGmsPlayServicesTasks1001Library :prepareProjectCordovaLibUnspecifiedDebugLibrary :prepareDebugDependencies :compileDebugAidl :compileDebugRenderscript :generateDebugBuildConfig :mergeDebugShaders :compileDebugShaders :generateDebugAssets :mergeDebugAssets :generateDebugResValues :generateDebugResources :mergeDebugResources :processDebugManifest :processDebugResources/project/res/xml/authenticator.xml:5:19-31: AAPT: No resource found that matches the given name (at 'icon' with value '@mipmap/icon'). /project/res/xml/authenticator.xml:6:24-36: AAPT: No resource found that matches the given name (at 'smallIcon' with value '@mipmap/icon'). FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':processDebugResources'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/android-sdk/build-tools/24.0.1/aapt'' finished with non-zero exit value 1 * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 3.188 secs Error: /project/gradlew: Command failed with exit code 1 Error output: Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. /project/res/xml/authenticator.xml:5:19-31: AAPT: No resource found that matches the given name (at 'icon' with value '@mipmap/icon'). /project/res/xml/authenticator.xml:6:24-36: AAPT: No resource found that matches the given name (at 'smallIcon' with value '@mipmap/icon'). FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':processDebugResources'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/android-sdk/build-tools/24.0.1/aapt'' finished with non-zero exit value 1 * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. at ChildProcess.whenDone (/project/cordova/node_modules/cordova-common/src/superspawn.js:169:23) at emitTwo (events.js:106:13) at ChildProcess.emit (events.js:191:7) at maybeClose (internal/child_process.js:877:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5) 

How to configure the plugin properly to be built?

Short answer

Add <preference name="phonegap-version" value="cli-6.4.0" /> to your config.xml

Long answer

The plugin includes the Android Support Library and specifies version + - ie the latest version syndicated by Google, which is currently v41 and requires a compile SDK of Android API 24+.

In Cordova/Phonegap projects, the Android compile SDK version is implicilty tied to the version of the Cordova Android platform:

`cordova-android@5.2.1` => API 23
`cordova-android@6.1.0` => API 25

Phonegap Build pins the version of cordova-android based on the CLI version ( see here ) which currently defaults CLI version 6.3.0 => cordova-android@5.2.1 => Android compile SDK v23 . By specifying CLI v6.4.0, cordova-android platform is set to v6.1.0 => Android compile SDK v25. Hence this will work with the latest version of the Android Support Library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM