37

I am working in Cordova and AndroidStudio to create Android/iOS apps. Everything was working fine until I updated my Cordova to 8 yesterday. I also updated Node to the latest. When I create a Cordova project and add the Android platform. It yields a totally different directory structure. I cannot see assets, res and src folders in project's platform directory D:\testApp1\platforms\android. More importantly, the above directory is missing AndroidManifest.xml, which is causing the admob plugin to fail in getting added.

Here is the error that I get while adding the plugin:

Failed to install 'cordova-plugin-admobpro': Error: ENOENT: no such file or directory, open 'D:\Projects\testApp1\platforms\android\AndroidManifest.xml' at Object.fs.openSync (fs.js:646:18) at Object.fs.readFileSync (fs.js:551:33) at Object.parseElementtreeSync (D:\Projects\testApp1\platforms\android\cordova\node_modules\cordova-common\src\util\xml-helpers.js:180:27) at new AndroidManifest (D:\Projects\testApp1\platforms\android\cordova\lib\AndroidManifest.js:29:20) at AndroidProject.getPackageName (D:\Projects\testApp1\platforms\android\cordova\lib\AndroidProject.js:99:12) at Api.addPlugin (D:\Projects\testApp1\platforms\android\cordova\Api.js:223:57) at handleInstall (C:\Users\Rao\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\plugman\install.js:594:10) at C:\Users\Rao\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\plugman\install.js:357:28 at _fulfilled (C:\Users\Rao\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:787:54) at self.promiseDispatch.done (C:\Users\Rao\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:816:30)

Can someone please help?

dda
  • 6,030
  • 2
  • 25
  • 34
Kamran
  • 591
  • 1
  • 5
  • 9
  • I also ran into the same problem with a missing AndroidManifest.xml file. Although a simple move, this change will incur an ungodly number of hours in required downstream changes. I sure hope this break in compatibility was worth it. BTW, I also noticed that edit-config support is broken on IOS to add plugin usage descriptions to *-Info.plist. Using config-file tag in the interim. Unfortunately, backing up to cordova 7.1.0 works until the change is supported in all dependent plugins. – jmelvin Dec 23 '17 at 17:16

9 Answers9

45

Cordova CLI v8.0 will use cordova-android@7.0.0 by default.

As most of the cordova plugins do not support cordova-android@7.0.0 yet, you can also try using the older one by specifying version:

cordova platform add android@6.4.0

Or, if you feel comfortable to use cordova-android@7.0.0, you can also wait for a update on cordova-plugi-admobpro to support the cordova-android@7.0.0, it's coming soon.

Raymond Xie
  • 1,486
  • 12
  • 20
35

Final edit:

cordova-android 7.1.4 is out, it should fix most of this kind of problems.

edit:

As people keep upvoting the answer I'll give more details about the problem.

The problem isn't really the plugin writing on the AndroidManifest.xml or on the config.xml. It's true that the location changed and plugins should update the path, but it's not mandatory and Cordova takes care of the new paths.

The problem is some plugins using source-file tag for things that are not source code. (i.e, using it for copying images instead of using resource-file tags) That creates a res folder (or lib) that confuses Cordova, making it believe it's an old Eclipse project, while it's really an Android studio project, and searches for the files on the old locations instead of looking into the new locations.

This has been patched in cordova-android and will be fixed in next release. The workaround is to look for the plugin using source-file tag and update it to use resource-file tag

OLD ANSWER:

It is now in app/src/main/AndroidManifest.xml.

If the plugin is writing on it, it should be updated to write on the right place.

Read the cordova-android 7.0.0 release blog post

jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
  • 3
    If you have a 'res' folder in the root of your project you will still get this error even after updating the path inside plugin.xml (Due to Eclipse project detection) – Ryan Williams Jan 18 '18 at 06:19
  • @RyanWilliams if you are using Cordova CLI 8 yo don't have to change paths inside plugin.xml, only paths in hooks or other things writing the files. Whatever is creating that res folder should be modified. As you say, Cordova check for that folder to know if it's an Android Studio project or an Eclipse project, so if it's and Android Studio project but finds the res folder it goes crazy and make strange things. – jcesarmobile Jan 18 '18 at 11:04
  • I am using this plugin which doesn't even specify AndroidManifest in plugin.xml yet it still doesn't install. What gives? – huggie Mar 26 '18 at 09:52
  • this is sort of a bug in cordova. When a plugin uses source-file tags for files that are not source files (i.e. images), they get copied to the root and reate a res folder. That folder turn Cordova crazy and start looking for files in the old path and prevents plugins from installing, not the plugin that is wrong, but the next plugin that it tries to install. – jcesarmobile Mar 26 '18 at 09:55
  • @jcesarmobile I was facing the same problem and updated the xml files as you suggested. It's still showing the same error. Any suggestions? – bharat Jun 10 '18 at 07:02
  • @jcesarmobile Manifest doesn't create when create the plugin using plugmen – Kishore Jethava Jun 29 '18 at 09:51
  • The manifest is not from the plugins, is from the Android project in platforms/android – jcesarmobile Jun 29 '18 at 09:53
  • @jcesarmobile I have set `` in `plugin.xml` but it doesn't create in my demo project. – Kishore Jethava Jul 04 '18 at 12:26
  • That is for writing on the file, not for creating it. The file changed location, but it’s there. You shouldn’t worry about that – jcesarmobile Jul 04 '18 at 13:30
  • When you say that plugins are "using" source-file rather than resource-file... which file inside the plugin will be using this? How do I find source-file and change it? – William Whyte Aug 25 '18 at 12:14
  • 1
    In the plugin.xml – jcesarmobile Aug 25 '18 at 12:57
22

In config.xml file of the cordova project, under xml tag <platform name="android"> section, Add the following tag:

<resource-file src="platforms/android/app/src/main/AndroidManifest.xml" target="AndroidManifest.xml" />
nyluje
  • 3,573
  • 7
  • 37
  • 67
3

Downgrading from 7.0 to 6.4 did the trick for me

cordova platform rm android
cordova platform add android@6.4
cordova build
Solvik
  • 51
  • 2
2

I simply fixed the error by copying AndroidManifest.xml in

platforms\android\app\src\main\

to

platforms\android\

sqlchild
  • 8,754
  • 28
  • 105
  • 167
JeffNhan
  • 363
  • 3
  • 3
  • 5
    no, don't do that. You'll get rid of the error, but you are not fixing anything. – jcesarmobile Mar 20 '18 at 14:54
  • @jcesarmobile: would be great if you can please guide me on this https://stackoverflow.com/questions/50017635/google-plus-plugin-and-push-notification-plugin-conflict-on-phonegap-build-buil – sqlchild Apr 25 '18 at 08:40
1

This worked for me.

In package.json add cordova-android version

 "cordova-android": "~6.3.0"

Then add platform

cordova platform add android
Maheshvirus
  • 6,749
  • 2
  • 38
  • 40
0
  1. Firstly make sure the plugin supports cordova android 7.0.0+
  2. Delete all of these folder or file: ['AndroidManifest.xml', 'libs', 'res'] in the platforms/android root directory.

Cordova use these files to determine if your project is an eclipse project. If they are existed, your project will be treated as an eclipse project with the old path structure. Some plugin may create these files/folders on your android folder.

johnny
  • 5,077
  • 1
  • 16
  • 9
0

The problem appears to be when you try to build for release at the same time you are running the App locally. I stop the App on localhost and then build for release. Problem solved.

0

My problem was a custom plugin creating the libs folder in platforms\android. That made Cordova believe that my project was an eclipse project and therefore it was looking for the AndroidManifest in the old place.

If you upgrande to Cordova Android +7.0.0 make sure that platforms\android doesn't contain the following items:

  • AndroidManifest.xml
  • libs
  • res

this link helped

Alessandro Lallo
  • 741
  • 11
  • 21