How to run Android command line from root on ubnutu


#1

i need ur help
when i accede in my root on ubuntu i got a problem frown emoticon i can’t run android command line
and he said me :android command not found but another side when run it without root tamchi normale
i did everything i added environment variables
th main problem when run the command 'ionic build android ’ from user i got the problema permission
in this case cordova cannot delete some file bcz don’t have permission
like superuser from root

root@lakb:/home/lakhdar/Public/appsionic/myApp# ionic build android

Running command: /home/lakhdar/Public/appsionic/myApp/hooks/after_prepare/010_add_platform_class.js /home/lakhdar/Public/appsionic/myApp
add to body class: platform-android
Running command: /home/lakhdar/Public/appsionic/myApp/platforms/android/cordova/build
[Error: ANDROID_HOME is not set and “android” command not in your PATH. You must fulfill at least one of these conditions.]
ERROR building one of the platforms: Error: /home/lakhdar/Public/appsionic/myApp/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /home/lakhdar/Public/appsionic/myApp/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:134:23)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
root@lakb:/home/lakhdar/Public/appsionic/myApp#

and when run ionic build command from user i got this result :
akhdar@lakb:~/Public/appsionic/myApp$ ionic build android
cp: copyFileSync: could not write to dest file (code=EACCES):/home/lakhdar/Public/appsionic/myApp/platforms/android/res/xml/config.xml

rm: could not remove file (code EACCES): /home/lakhdar/Public/appsionic/myApp/platforms/android/assets/www/cordova-js-src/android/nativeapiprovider.js

rm: could not remove file (code EACCES): /home/lakhdar/Public/appsionic/myApp/platforms/android/assets/www/cordova-js-src/android/nativeapiprovider.js
rm: could not remove file (code EACCES): /home/lakhdar/Public/appsionic/myApp/platforms/android/assets/www/cordova-js-src/android/promptbasednativeapi.js

rm: could not remove file (code EACCES): /home/lakhdar/Public/appsionic/myApp/platforms/android/assets/www/cordova-js-src/android/nativeapiprovider.js
rm: could not remove file (code EACCES): /home/lakhdar/Public/appsionic/myApp/platforms/android/assets/www/cordova-js-src/android/promptbasednativeapi.js
rm: could not remove directory (code EACCES): /home/lakhdar/Public/appsionic/myApp/platforms/android/assets/www/cordova-js-src/android

rm: could not remove file (code EACCES): /home/lakhdar/Public/appsionic/myApp/platforms/android/assets/www/cordova-js-src/android/nativeapiprovider.js
etc etc …
thank you ionic’ers :smile:


#2

So you seem to have several problems.

If you are sure that ANDROID_HOME and PATH env variables are correctly set, then make sure that all folders permissions are correct in ANDROID_HOME (a+rx) and that all executable shell scripts are also correct (a+rx).

Make sure that you are the owner of /home/lakhdar/Public/appsionic, use chown -R

You have probably installed nodejs using sudo which is a source of problems unless you really require it, uninstall it and install using nvm, it will bring 2 benefits: clean install without root access and ability to switch between node versions.

Once done never use sudo anymore for node commands like npm, ionic, cordova, gulp, bower, …


#3

thanks a lot Mr.Gmarziou i’ll try with it