0

I'd like to do some Apps for Android tablets but the only language I can find that can be used is Java and it doesn't support the data types that I need (mainly complex numbers).

Even worse, it doesn't even appear to support operator overloading, so I can't even create a pseudo data type.

I have decades worth of scientific and mathematical algorithms with thousands of complex equations that I would like to move over to Android but the compiler is a real sticking point.

I reckon it would be quicker for me to modify the compiler than it would be to try and unravel the equations and convert them to reverse polish suitable for function calls.

I know the sources for Android itself are available but is the compiler ?

Andy k
  • 1,056
  • 1
  • 11
  • 22
  • As Raghav says, the NDK is the way to go. I've recently ported a lot of ObjectiveC maths to both Java and as libraries using the NDK and it's quite straight forward. You didn't mention what language your algorithms are currently written in, but C++ has native support for complex numbers. – Simon Oct 29 '12 at 08:30
  • The current complex matrix and Complex math library are written in Delphi. They are highly optimised with code inlining and assembler for the intensive operations. There are Object pascal alternatives for the assembler routines. – Andy k Oct 29 '12 at 08:51
  • Hmm. The Delphi and inlining should convert as is. The assembler is a little trickier ;). It is possible to create native assembler libraries with the NDK but you might need to create a library for each CPU platform if you wanted generic support (e.g. ARM and Intel). See this answer which links to a post http://stackoverflow.com/questions/6506781/arm-assembly-code-in-an-android-project – Simon Oct 29 '12 at 15:00
  • @Simon Thanks for that, I have conditional compilation set up for the Assembler routines so I can switch to the pascal equivalents. If I go the NDK route, I'm thinking the easiest would be to compile using Free Pascal which has an ARM cross compiler for Android, it would not work on Intel or MIPS as you say. – Andy k Oct 29 '12 at 16:12
  • You're welcome. The cross-compiler sounds like a good option. Good luck! – Simon Oct 29 '12 at 17:01

3 Answers3

4

If you mean the Dalvik engine, I think that's not open source. But regarding your actual problem, you can always use Android's NDK to use native code languages such as C or C++.

Ridcully
  • 23,362
  • 7
  • 71
  • 86
  • As far as I am aware the Dalvik engine is part of Android and is the interpreter which compiles the pseudo java op codes produced by the compiler into machine code as it is loaded into the device memory. I'm not suggesting changing that but I'm interested in modifying the compiler to generate the necessary opcodes that the complex math would generate. – Andy k Oct 29 '12 at 08:16
  • @Andyk, mvp oh, I didn't know that. But as mvp says below, that doesn't help in solving the problem. – Ridcully Oct 29 '12 at 08:57
3

Android is fully open source, including its JVM engine Dalvik.

However, attempts to change compiler or JVM will not get you anywhere - you simply cannot change what runs today on millions of Android devices.

Now, if you want to create software that can run on these millions of devices, you have no choice but to adapt your software. If you require handling complex numbers, the only way to be successful is to create your own Complex class library and change your other numeric libraries to make use of it.

mvp
  • 111,019
  • 13
  • 122
  • 148
  • I'm not suggesting changing the device end or the VM. The VM just interprets opcodes produced by the compiler. Complex number support would just use a combination of existing opcodes so only the Java compiler that runs on Windows/Linux would need to be modified to add extra syntax. – Andy k Oct 29 '12 at 08:23
  • As far as I know, android 4 must be compiled by Oracle Java which is closed source (OpenJDK used to work in Gingerbread, but not anymore). But, I still fail to understand how is that different from you creating own Java class and using it throughout? Then no custom handling is necessary, would that be Android, Windows or Linux – mvp Oct 29 '12 at 08:29
  • I am not suggesting making any changes to Android itself. The Java compiler used for creating Android Apps in Eclipse has no physical connection to Android at all. All it does is compile the code you type into eclipse into a series of op-codes for some mythical microprocessor and store them in a file. When that file is loaded into an Android device that file is read and compiled into the physical machine opcodes for that processor it is using. Theoretically you don't need a Java compiler at all, you could use any programming language that has the capability of outputting Dalvik VM opcodes. – Andy k Oct 29 '12 at 08:43
2

You will not be able to do this as Java is an interpreted and compiled language language, and the interpretor runs on the device. So even if you do modify the compiler to add what you need, none of the devices you're running on will know what's happening.

Instead, you could:

  1. Use the Android NDK, which supports C and C++
  2. Modify your algorithm to works within Java

Also, keep in mind that Android uses the Dalvik VM, and not the Java VM, and while it is open source, you will be unable to push your modifications to your target devices without writing a custom ROM as well.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • NDK is a possibility but any code then becomes processor specific. It would work on ARM but not on Atom or MIPS devices. – Andy k Oct 29 '12 at 09:00
  • I haven't got much experience with the NDK personally, but from what I've read online it isn't very hard to compile the same code for different processors. And the latest NDK release supports MIPS, I believe. – Raghav Sood Oct 29 '12 at 10:15