Ionic cordova run android not working

When I run:

ionic cordova run android --verbose

I get:

[DEBUG] Reason for not using local CLI: LOCAL_CLI_NOT_FOUND
[DEBUG] CLI flags: { interactive: true, confirm: false }
[DEBUG] { cwd: '/home/isaacisback/dev/ionic/sopsi', local: false, binPath: 
        '/usr/local/lib/node_modules/ionic/bin/ionic', libPath: 
        '/usr/local/lib/node_modules/ionic/dist/index.js' }
[DEBUG] Daemon found (pid: 15717)
Running app-scripts build: --platform android --target cordova
[16:18:49]  build dev started ... 
[16:18:49]  clean started ... 
[16:18:49]  clean finished in 4 ms 
[16:18:49]  copy started ... 
[16:18:49]  deeplinks started ... 
[16:18:49]  deeplinks finished in 62 ms 
[16:18:49]  transpile started ... 
[16:18:52]  transpile finished in 2.75 s 
[16:18:52]  preprocess started ... 
[16:18:52]  preprocess finished in 1 ms 
[16:18:52]  webpack started ... 
[16:18:52]  copy finished in 2.97 s 
[16:18:58]  webpack finished in 5.87 s 
[16:18:58]  sass started ... 
Without `from` option PostCSS could generate wrong source map and will not find Browserslist config. Set it to CSS file path or to `undefined` to prevent this warning.
[16:18:59]  sass finished in 1.07 s 
[16:18:59]  postprocess started ... 
[16:18:59]  postprocess finished in 17 ms 
[16:18:59]  lint started ... 
[16:18:59]  build dev finished in 9.88 s 
> cordova run android
Android Studio project detected

will push strings array {"name":"lang","titles":["English (US)","English (UK)"],"values":["en-us","en-gb"]}
unhandled exception { Error: ENOENT: no such file or directory, mkdir 'platforms/android/res/xml'
  errno: -2,
  code: 'ENOENT',
  syscall: 'mkdir',
  path: 'platforms/android/res/xml' }
(node:3931) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: ENOENT: no such file or directory, mkdir 'platforms/android/res/xml'
(node:3931) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

[OK] Your app has been deployed.
     Did you know you can live-reload changes from your app with --livereload?

[16:19:01]  lint finished in 2.24 s 
[DEBUG] registerShutdownFunction process.exit/normal shutdown

But the app is not deployed on my device. I’ve also tried --device and --target without success.
My project is very basic. I’ve already tried to do ionic cordova remove platform android and readd it again. I think that the problem is with the ENOENT.
For some reason, it searches the files in that directory.

My directory tree is:

./android
./android/platform_www
./android/platform_www/plugins
./android/platform_www/plugins/cordova-plugin-app-preferences
./android/platform_www/plugins/cordova-plugin-app-preferences/www
./android/platform_www/cordova-js-src
./android/platform_www/cordova-js-src/android
./android/platform_www/cordova-js-src/plugin
./android/platform_www/cordova-js-src/plugin/android
./android/platform_www/task
./android/CordovaLib
./android/CordovaLib/src
./android/CordovaLib/src/org
./android/CordovaLib/src/org/apache
./android/CordovaLib/src/org/apache/cordova
./android/CordovaLib/src/org/apache/cordova/engine
./android/cordova
./android/cordova/lib
./android/cordova/lib/builders
./android/cordova/node_modules
./android/app
./android/app/src
./android/app/src/main
./android/app/src/main/res
./android/app/src/main/res/drawable-land-hdpi
./android/app/src/main/res/mipmap-xxhdpi
./android/app/src/main/res/drawable-land-ldpi
./android/app/src/main/res/drawable-land-xxxhdpi
./android/app/src/main/res/drawable-port-xhdpi
./android/app/src/main/res/xml
./android/app/src/main/res/drawable-port-mdpi
./android/app/src/main/res/drawable-port-ldpi
./android/app/src/main/res/mipmap-mdpi
./android/app/src/main/res/drawable-land-xhdpi
./android/app/src/main/res/drawable-port-hdpi
./android/app/src/main/res/mipmap-xhdpi
./android/app/src/main/res/drawable-port-xxhdpi
./android/app/src/main/res/mipmap-xxxhdpi
./android/app/src/main/res/drawable-land-mdpi
./android/app/src/main/res/drawable-land-xxhdpi
./android/app/src/main/res/drawable-port-xxxhdpi
./android/app/src/main/res/mipmap-hdpi
./android/app/src/main/res/mipmap-ldpi
./android/app/src/main/res/values
./android/app/src/main/assets
./android/app/src/main/assets/www
./android/app/src/main/assets/www/build
./android/app/src/main/assets/www/plugins
./android/app/src/main/assets/www/plugins/cordova-plugin-app-preferences
./android/app/src/main/assets/www/plugins/cordova-plugin-app-preferences/www
./android/app/src/main/assets/www/cordova-js-src
./android/app/src/main/assets/www/cordova-js-src/android
./android/app/src/main/assets/www/cordova-js-src/plugin
./android/app/src/main/assets/www/cordova-js-src/plugin/android
./android/app/src/main/assets/www/assets
./android/app/src/main/assets/www/assets/fonts
./android/app/src/main/assets/www/assets/icon
./android/app/src/main/assets/www/assets/imgs
./android/app/src/main/assets/www/assets/db
./android/app/src/main/assets/www/task
./android/app/src/main/java
./android/app/src/main/java/io
./android/app/src/main/java/io/ionic
./android/app/src/main/java/io/ionic/starter
./android/app/src/main/java/me
./android/app/src/main/java/me/apla
./android/app/src/main/java/me/apla/cordova
./android/app/src/main/libs

I’ve tried to move src* in android/ but still gives error (cannot find the mainactivity).

My environment is (ionic info):

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.19.1
    ionic (Ionic CLI) : 3.19.1

global packages:

    cordova (Cordova CLI) : 8.0.0 

local packages:

    @ionic/app-scripts : 3.1.8
    Cordova Platforms  : android 7.0.0
    Ionic Framework    : ionic-angular 3.9.2

System:

    Android SDK Tools : 26.1.1
    Node              : v8.0.0
    npm               : 5.6.0 
    OS                : Linux 4.13

Environment Variables:

    ANDROID_HOME : /home/federicoponzi/Android/Sdk

Misc:

    backend : pro

Thanks for the help!

You might want to update your Node to the LTS. There are several bug fixes available. Might have nothing to do with your problem, but eliminates a possible issue.

Thanks, I’ve updated my node version.

In my project, I’m using AppPreference, installed as stated there: https://ionicframework.com/docs/native/app-preferences/.

Doing a grep -rnw "android/res", I’ve found this:

|plugins/cordova-plugin-app-preferences/bin/lib/browser.js:163:|||.then(function () { return fs.mkdir('platforms/android/res/xml'); })|
|---|---|---|---|
|plugins/cordova-plugin-app-preferences/bin/lib/browser.js:164:|||.then(function () { return fs.writeFile('platforms/android/res/xml/apppreferences.xml', preferencesDocument.write()); })|
|plugins/cordova-plugin-app-preferences/bin/lib/browser.js:167:|||.then(function () { return fs.mkdir('platforms/android/res/values'); })|
|plugins/cordova-plugin-app-preferences/bin/lib/browser.js:168:|||.then(function (prefs) { return fs.writeFile('platforms/android/res/values/apppreferences.xml', preferencesStringDocument.write()); })|
|plugins/cordova-plugin-app-preferences/bin/lib/browser.js:219:|||.then(function () { return fs.unlink('platforms/android/res/xml/apppreferences.xml'); })|
|plugins/cordova-plugin-app-preferences/bin/lib/browser.js:222:|||.then(function (prefs) { return fs.unlink('platforms/android/res/values/apppreferences.xml'); })|
|plugins/cordova-plugin-app-preferences/bin/lib/android.js:159:|||.then(function () { return fs.mkdir('platforms/android/res/xml'); })|
|plugins/cordova-plugin-app-preferences/bin/lib/android.js:160:|||.then(function () { return fs.writeFile('platforms/android/res/xml/apppreferences.xml', preferencesDocument.write()); })|
|plugins/cordova-plugin-app-preferences/bin/lib/android.js:163:|||.then(function () { return fs.mkdir('platforms/android/res/values'); })|
|plugins/cordova-plugin-app-preferences/bin/lib/android.js:164:|||.then(function (prefs) { return fs.writeFile('platforms/android/res/values/apppreferences.xml', preferencesStringDocument.write()); })|
|plugins/cordova-plugin-app-preferences/bin/lib/android.js:219:|||.then(function () { return fs.unlink('platforms/android/res/xml/apppreferences.xml'); })|
|plugins/cordova-plugin-app-preferences/bin/lib/android.js:222:|||.then(function (prefs) { return fs.unlink('platforms/android/res/values/apppreferences.xml'); })|

So it looks like that the plugin is using wrong path for the android platform. How can I fix this?

Yes , you are right … Ionic app-preference plugin is the problem . But I have another problem too

I could not remove ionic plugin cordova-plugin-app-preferences
through command :

ionic cordova plugin rm cordova-plugin-app-preferences

please help

Thanks

Anes

If think you should go ahead and write your own topic in order to have more chance to get an answer :slight_smile: