dpa99c / cordova-custom-config

Cordova/Phonegap plugin to update platform configuration files based on preferences and config-file data defined in config.xml
318 stars 84 forks source link

cordova-custom-config@^5.0.2 with phonegap and cordova 7.0.0 don't find the correct AndroidManifest.xml path #146

Closed juanhuerta closed 6 years ago

juanhuerta commented 6 years ago

I'm submitting a ... (check one with "x"):

Bug report

Current behavior:

cordova-custom-config@^5.0.2 with phonegap and cordova 7.0.0 don't find the correct AndroidManifest.xml path

phonegap plugin add cordova-custom-config -d
No scripts found for hook "before_plugin_add".

No version specified for cordova-custom-config, retrieving version from package.json

Calling plugman.fetch on plugin "cordova-custom-config@^5.0.2"

Calling plugman.install on plugin "/Users/jc/Documents/Veteca/App/vetecaApp/plugins/cordova-custom-config" for platform "android

Installing "cordova-custom-config" for android

Running command: /Users/jc/Documents/Veteca/App/vetecaApp/platforms/android/cordova/version

Command finished with error code 0: /Users/jc/Documents/Veteca/App/vetecaApp/platforms/android/cordova/version

Finding scripts for "before_plugin_install" hook from plugin cordova-custom-config on android platform only.

No scripts found for hook "before_plugin_install".

Install start for "cordova-custom-config" on android.

PlatformApi successfully found for platform android

Failed to install 'cordova-custom-config': Error: ENOENT: no such file or directory, open '/Users/jc/Documents/Veteca/App/vetecaApp/platforms/android/AndroidManifest.xml'
    at Error (native)
    at Object.fs.openSync (fs.js:642:18)
    at Object.fs.readFileSync (fs.js:510:33)
    at Object.parseElementtreeSync (/Users/jc/Documents/Veteca/App/vetecaApp/platforms/android/cordova/node_modules/cordova-common/src/util/xml-helpers.js:180:27)
    at new AndroidManifest (/Users/jc/Documents/Veteca/App/vetecaApp/platforms/android/cordova/lib/AndroidManifest.js:29:20)
    at AndroidProject.getPackageName (/Users/jc/Documents/Veteca/App/vetecaApp/platforms/android/cordova/lib/AndroidProject.js:99:12)
    at Api.addPlugin (/Users/jc/Documents/Veteca/App/vetecaApp/platforms/android/cordova/Api.js:223:57)
    at handleInstall (/usr/local/lib/node_modules/phonegap/node_modules/cordova-lib/src/plugman/install.js:594:10)
    at /usr/local/lib/node_modules/phonegap/node_modules/cordova-lib/src/plugman/install.js:357:28
    at _fulfilled (/usr/local/lib/node_modules/phonegap/node_modules/cordova-lib/node_modules/q/q.js:787:54)

(node:10662) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: ENOENT: no such file or directory, open '/Users/jc/Documents/Veteca/App/vetecaApp/platforms/android/AndroidManifest.xml'

The cordova version:

/Users/jc/Documents/Veteca/App/vetecaApp/platforms/android/cordova/version
7.0.0
dpa99c commented 6 years ago

The stack trace in the error message indicates this error has arisen in the cordova-android scripts, specifically:

platforms/android/cordova/node_modules/cordova-common/src/util/xml-helpers.js:180:27

From v5.0.0, this plugin is able to detect and use the correct manifest filepaths for both cordova-android@6 and cordova-android@7.

Please check you are using the most recent version of the Cordova/Phonegap CLI (v8.0.0) - as you can see below, that works fine in my dev env:

console output ``` $ cordova -v 8.0.0 $ cordova create test && cd test Creating a new cordova project. $ cordova platform add android@7.0.0 Using cordova-fetch for cordova-android@7.0.0 Adding android project... Creating Cordova project for the Android platform: Path: platforms\android Package: io.cordova.hellocordova Name: HelloCordova Activity: MainActivity Android target: android-26 Subproject Path: CordovaLib Subproject Path: app Android project created with cordova-android@7.0.0 Android Studio project detected Android Studio project detected Discovered plugin "cordova-plugin-whitelist" in config.xml. Adding it to the project Installing "cordova-plugin-whitelist" 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. Adding cordova-plugin-whitelist to package.json Saved plugin info for "cordova-plugin-whitelist" to config.xml --save flag or autosave detected Saving android@~7.0.0 into config.xml file ... $ cordova plugin add cordova-custom-config Installing "cordova-custom-config" for android Android Studio project detected Adding cordova-custom-config to package.json Saved plugin info for "cordova-custom-config" to config.xml $ cordova prepare android cordova-custom-config: Skipping auto-restore of config file backup(s) Android Studio project detected ```
juanhuerta commented 6 years ago

That's very strange. After creating a new project using your same steps I can install the plugin. I'm using phonegap CLI 8.0.0 as you.

➜ test phonegap -v 8.0.0

So, I have the same CLI version, and same android version in both projects. What could it be?

dpa99c commented 6 years ago

Possible there's remnants of a previous cordova-android platform version in the other project?

Try removing /Users/jc/Documents/Veteca/App/vetecaApp/node_modules and then do:

cordova platform rm android --nosave && cordova platform add android --nosave

to rebuild the project.

I'm inclined to think it's a bug in either cordova (CLI) or cordova-android (platform) though.