16

When I use the command : ionic cordova build android here is what I get :

cp: copyFileSync: could not write to dest file (code=ENOENT):/Users/mehdigriche/work/cam1/test/platforms/android/res/xml/config.xml

Parsing /Users/mehdigriche/work/cam1/test/platforms/android/res/xml/config.xml failed (node:2306) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: ENOENT: no such file or directory, open '/Users/mehdigriche/work/cam1/test/platforms/android/res/xml/config.xml'

[10:50:14] lint finished i

Tolga E
  • 10,188
  • 15
  • 44
  • 57
mehdigriche
  • 394
  • 1
  • 3
  • 12

9 Answers9

22

Add this hook to cordova project: patch-android-studio-check.js

  1. Put the file patch-android-studio-check.js in the directory hooks of your project

  2. Add the following lines to the config.xml of your project:

    <platform name="android">
        <hook src="hooks/patch-android-studio-check.js" type="before_plugin_install" />
        <hook src="hooks/patch-android-studio-check.js" type="before_plugin_add" />
        <hook src="hooks/patch-android-studio-check.js" type="before_build" />
        <hook src="hooks/patch-android-studio-check.js" type="before_run" />
        <hook src="hooks/patch-android-studio-check.js" type="before_plugin_rm" />
    </platform>
    
  3. Delete the plugins directory:

    rm -rf plugins
    
  4. Reinstall the plugins:

    ionic build
    
  5. Reinstall the platform android:

    cordova platform rm android
    cordova platform add android@latest
    
Michael0x2a
  • 41,137
  • 26
  • 119
  • 175
dtmp
  • 415
  • 1
  • 5
  • 14
15

Your command: ionic cordova build androird is wrong
I think you means: ionic cordova build android

But try also: ionic cordova build --release android

I had the same error, after 2 days of debugging I found a solution for me:

in the directory: platforms/android/cordova I updated in the file Api.js the locations object, because the path are not correct.

current locations object look like this in my Api.js:

    this.locations = {
    root: self.root,
    www: path.join(self.root, 'assets/www'),
    res: path.join(self.root, 'res'),
    platformWww: path.join(self.root, 'platform_www'),
    configXml: path.join(self.root, 'app/src/main/res/xml/config.xml'),
    defaultConfigXml: path.join(self.root, 'cordova/defaults.xml'),
    strings: path.join(self.root, 'app/src/main/res/values/strings.xml'),
    manifest: path.join(self.root, 'app/src/main/AndroidManifest.xml'),
    build: path.join(self.root, 'build'),
    javaSrc: path.join(self.root, 'app/src/main/java/'),
    // NOTE: Due to platformApi spec we need to return relative paths here
    cordovaJs: 'bin/templates/project/assets/www/cordova.js',
    cordovaJsSrc: 'cordova-js-src'
};

After these change I was able to build my app. I had also errors because of plugins like cordova-sqlite-storage so I removed it and build the app.

I hope it helps

Apophis
  • 233
  • 1
  • 8
  • i've tried that but with no success sorry to not mention that everything was ok when i build with ionic 1 everything goes well but when i use ionic 3 it gives me this also this problem is in the platforms folder when i use another folder from an ionic 1 project it fixed – mehdigriche Dec 29 '17 at 16:48
8

To solve this problem

cp: copyFileSync: could not write to dest file (code=ENOENT):/Users/mehdigriche/work/cam1/test/platforms/android/res/xml/config.xml

Create a folder named xml in platforms/android/res

Black Mamba
  • 8,408
  • 4
  • 52
  • 84
6

Apparently, some files are not generated correctly when adding android +7 so, I solved this problem by the following:

Firstly remove your platform,

ionic cordova platform rm android

then reinstall a lower version (6.3 worked for me )

ionic cordova platform add android@6.3.0
zuest
  • 147
  • 1
  • 14
  • 1
    @Vivek Android 7+ broke a lot of things, so it's easier to roll back to 6.4.0 for now if your pressed for time and can't find alternative plugins. – Trevor Jun 28 '18 at 20:10
5

I have faced the same issue this morning and my (rather drastic) solution was this:

  1. Remove the platform:
ionic cordova platform rm android
  1. Delete the following folders from your app folder: platforms,plugins & www
  2. Make sure your dependencies are available by running: npm install
  3. Add back the platform, this step will recreate the folders deleted in step 2 above:
ionic cordova platform add android
  1. Finally, build your app:
ionic cordova build android
Zoe
  • 23,712
  • 16
  • 99
  • 132
Richie254
  • 464
  • 5
  • 7
  • 4
    I would keep the "www" folder when you're doing this reset! You may have important asset files in there. :) – xke Mar 12 '18 at 04:48
  • 4
    They already present in src folder so no need to worry about that although deleting www will not have any effect @xke – Black Mamba Apr 08 '18 at 16:58
  • That depends on your Ionic version - for Ionic v1 projects, you shouldn't delete the 'www' folder! – kolli Jun 08 '18 at 16:50
1

Note on dtmp's Answer, using the hooks directory seems to be deprecated. Using 'scripts' directory instead might be more appropriate.

When trying to make a build using ionic 2, using a 'hooks' directory lead to the hook js not being found.

Mark Thompson
  • 245
  • 1
  • 7
0

Assuming the

Androird

part is just a typo here.

Check this out: https://github.com/ionic-team/ionic/issues/13702

It is a known issue and not fixed yet!

MaxFot
  • 89
  • 8
0

If you are like me trying to overcome same issue and try all the way written as solution but not. Try this solution;

  1. Open your project folder's project.json file.
  2. Add this "android-versions" : "1.3.0" dependency.
  3. Run npm i.
  4. Run command sudo ionic cordova run android

Happy coding!

0
ionic cordova rm platform android

remove the www and plugins folder

npm cache clean
npm install audit fix
ionic cordova build  android
Siundu254
  • 31
  • 4