0

I'm not an Android developer but I do other stuff.

I just rooted my phone so I was playing around with a shell and I was trying to compile some C packages and realized there is no C compiler, OK.

Surely there must be Java right? Tried it and I can't get a java or javac command to work either.

How is that possible when Android apps are written in Java?

Andrew T.
  • 15,988
  • 10
  • 74
  • 123
Joff
  • 101
  • 1
  • 3
  • 2
    First, because Android devices are intended for end-users (sure also for developers, but they are in a minority ;) Second, your PC didn't ship with a compiler either, right? So third, you might have to install one. There are several IDEs available which run on Android – but this site here isn't for software recommendations :) – Izzy Nov 03 '16 at 21:46
  • I get that part....but how do the apps run with no Java? – Joff Nov 03 '16 at 21:54
  • 1
    Running already compiled apps doesn't need a compiler being installed, right? We don't run them from source :) Depending on the Android version, there's some bytecode optimization done by either the Dalvik (< 5.0) or the ART (5.0+) engine, though, but that's something different. To give you a hint: To run a Java app on a PC, you need the JRE (Java Runtime Environment) – to compile a Java app from its source you need the JDK (Java Development Kit). Two different pairs of shoes, though the latter contains the former :) – Izzy Nov 03 '16 at 21:59
  • OK I guess I thought the java command i tried to run was part of the jre? No? – Joff Nov 03 '16 at 22:03
  • You might wish to check our chat room – comments are not for discussion :) Short answer: for compiling, definitely no. And while Android apps are mostly written in Java, things are a bit different here. Goes to deep for this site, which is for end-users. – Izzy Nov 03 '16 at 22:06
  • Apps are launched by the Application Manager, which is a part of am.jar. To start an Android app, you need to use the am command, which calls a script, which sets the am.jar as CLASSPATH and then executes exec app_process $base/bin com.android.commands.am.Am "$@" (base being /system). Look inside /system/bin/am for details. – Grimoire Nov 03 '16 at 22:20
  • Android doesn't run Java bytecode because it uses Dalvik VM. And developers distribute apk packages, not Java/C#/kotlin source code – phuclv Mar 09 '18 at 13:38

3 Answers3

1

If you have Android 5.0 (lollipop) or later, use termux. (Terminal IDE is great but only works up to android 4.*). It's on the google play store, and the source is on github.

It has an apt repository with several compilers, including ecj, the Eclipse Compiler for Java, and is much faster than javac.

There's also golang, clang, gcc, node, python and a whole bunch of other stuff (tmux, vim, ctags, cscope, emacs, latexetc etc etc).

NB: this doesn't actually answer your "why" question, but might be helpful...

hyperpallium
  • 123
  • 9
0

Yes you can install a Java compiler but don't expect to be able to create your own applications for Android on Android.

I asked a similar question here.

William
  • 635
  • 2
  • 14
  • 31
0

ECJ (Eclipse Compiler for Java) can be ported very easily on Android. I've done it - but no support for Java 8 though.

Also, it is possible to build Android apps on Android, there are apps that already exist for that, JavaIDEdroid is one.

francogrex
  • 21
  • 1
  • 7