sampart / cordova-plugin-app-version

Cordova plugin to return the version number of the current app [not maintained]
MIT License
401 stars 198 forks source link

Is not compatible with Cordova 8.0.0 #99

Closed gbgelado closed 5 years ago

gbgelado commented 6 years ago
Installing "cordova-plugin-app-version" for android
Failed to install 'cordova-plugin-app-version': Error: ENOENT: no such file or directory, open '/app/cordova/platforms/android/AndroidManifest.xml'
    at Object.fs.openSync (fs.js:663:18)
    at Object.fs.readFileSync (fs.js:568:33)
    at Object.parseElementtreeSync (/app/cordova/platforms/android/cordova/node_modules/cordova-common/src/util/xml-helpers.js:180:27)
    at new AndroidManifest (/app/cordova/platforms/android/cordova/lib/AndroidManifest.js:29:20)
    at AndroidProject.getPackageName (/app/cordova/platforms/android/cordova/lib/AndroidProject.js:99:12)
    at Api.addPlugin (/app/cordova/platforms/android/cordova/Api.js:223:57)
    at handleInstall (/app/.npm-packages/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:594:10)
    at /app/.npm-packages/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:357:28
    at _fulfilled (/app/.npm-packages/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:787:54)
    at self.promiseDispatch.done (/app/.npm-packages/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:816:30)
(node:68912) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/app/cordova/platforms/android/AndroidManifest.xml'
    at Object.fs.openSync (fs.js:663:18)
    at Object.fs.readFileSync (fs.js:568:33)
    at Object.parseElementtreeSync (/app/cordova/platforms/android/cordova/node_modules/cordova-common/src/util/xml-helpers.js:180:27)
    at new AndroidManifest (/app/cordova/platforms/android/cordova/lib/AndroidManifest.js:29:20)
    at AndroidProject.getPackageName (/app/cordova/platforms/android/cordova/lib/AndroidProject.js:99:12)
    at Api.addPlugin (/app/cordova/platforms/android/cordova/Api.js:223:57)
    at handleInstall (/app/.npm-packages/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:594:10)
    at /app/.npm-packages/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:357:28
    at _fulfilled (/app/.npm-packages/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:787:54)
    at self.promiseDispatch.done (/app/.npm-packages/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:816:30)
Drarok commented 6 years ago
MyApp $ cordova --version
8.0.0
MyApp $ cordova plugin add cordova-plugin-app-version
Installing "cordova-plugin-app-version" for android
Android Studio project detected
Adding cordova-plugin-app-version to package.json
Saved plugin info for "cordova-plugin-app-version" to config.xml
l0stpenguin commented 6 years ago

Hi, im am upgrading my project from cordova 6.5.0 to 8.0.0. When installing i get the following error:

Installing "cordova-plugin-app-version" for android
Failed to install 'cordova-plugin-app-version': Error: ENOENT: no such file or directory, open '/home/travis/build/SharinPix/sharinpix-app/platforms/android/AndroidManifest.xml'
    at Object.fs.openSync (fs.js:646:18)
    at Object.fs.readFileSync (fs.js:551:33)
    at Object.parseElementtreeSync (/home/travis/build/SharinPix/sharinpix-app/platforms/android/cordova/node_modules/cordova-common/src/util/xml-helpers.js:180:27)
    at new AndroidManifest (/home/travis/build/SharinPix/sharinpix-app/platforms/android/cordova/lib/AndroidManifest.js:29:20)
    at AndroidProject.getPackageName (/home/travis/build/SharinPix/sharinpix-app/platforms/android/cordova/lib/AndroidProject.js:99:12)
    at Api.addPlugin (/home/travis/build/SharinPix/sharinpix-app/platforms/android/cordova/Api.js:223:57)
    at handleInstall (/home/travis/.nvm/versions/node/v8.9.4/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:594:10)
    at /home/travis/.nvm/versions/node/v8.9.4/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:357:28
    at _fulfilled (/home/travis/.nvm/versions/node/v8.9.4/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:787:54)
    at self.promiseDispatch.done (/home/travis/.nvm/versions/node/v8.9.4/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:816:30)
Failed to restore plugin "cordova-plugin-app-version" from config.xml. You might need to try adding it again. Error: Error: ENOENT: no such file or directory, open '/home/travis/build/SharinPix/sharinpix-app/platforms/android/AndroidManifest.xml'

Nodejs version: 8.9.4

I have this in my config.xml

<plugin name="cordova-plugin-app-version" spec="^0.1.9" />

As from cordova v7, there was a breaking change which may be the root of this issue: https://cordova.apache.org/announcements/2017/12/04/cordova-android-7.0.0.html The path of the android manifest has changed, but since you are not referring the manifest in your plugin, i don't see why it is not working.

znegva commented 6 years ago

This is not a problem in cordova-plugin-app-version and not Cordova 8.0.0 in general, but with cordova-android 7.0.0. The main problem can be found in platforms/android/cordova/lib/AndroidStudio.js, see here. There the check if your project is an AndroidStudio-project (which it is) fails and therefore the wrong path to the AndroidManifest.xml is chosen.

In my case the presence of a res directory fooled the function to think I am using eclipse and therefore using the wrong path to the manifest-file.

Check if there exists any of these files or directories inside your platform/android: ['AndroidManifest.xml', 'libs', 'res'] If so, find out which of your other plugins creates it.


In my case I had the following in my config.xml: <resource-file src="model/icon_push.png" target="res/drawable/icon_push.png" /> So I was the cause of the problem :)

Firzenizer commented 6 years ago

I had the same issues as @znegva, but the problem has to do with this plugin and any other relying on old manifest location AFAIK.

See: https://cordova.apache.org/announcements/2017/12/04/cordova-android-7.0.0.html

joeljeske commented 6 years ago

I have found success overriding the bad function using a hook:

https://gist.github.com/joeljeske/68121fa6d643e0937f50458d0172e16e

dtmp commented 6 years ago

@joeljeske thanks. added a bit: https://stackoverflow.com/a/49770295/4384751

fishgrind commented 6 years ago

just to let you know, cordova has a fix for it too.

add this to your config.xml:

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" />

source: http://cordova.apache.org/announcements/2017/12/04/cordova-android-7.0.0.html

just tested it and it works!

m-thompson-code commented 6 years ago

Adding <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" /> did nothing for me. Using the above hook did.

fishgrind commented 6 years ago

@moomoomamoo hmm strange, solved it for me. But I guess if the hook works, why not use that :)

DennisSmolek commented 5 years ago

From the above thread it seems this is an issue with the projects config.xml/plugins.xml and not with the code in the plugin.

I'm going to close this for now unless more feedback comes up

AlexPashley commented 5 years ago

I've just tried this with phonegap build, v8.0.0 and it doesnt work, I cant use hooks either because pgb doesnt allow/support these.

Any other ideas?

Im trying to an image into the res folder so its available for phonegap-plugin-push

postersw commented 5 years ago

If you are using PhoneGap build V 8.0.0, you need to change the path on your resource file copies. If you copied a file into 'res/' under PGB v 7.x.x, you now need to copy it into 'app/src/main/res/'. For example: '<resource-file src="push.png" target="app/src/main/res/push.png" />