In my case I want to write an app which is totally symetrical (not client-server) with identical functionality at two PCs, one a 'standard' Windows or Linux box and the other an Android slate.
Can I run the same program on both or do I nneed to wrap it in an Android package for persmissioons, etc?
The two PCs will communciate by TCP/IP, sort of peer-to-peer, but I suspect that as a generic question this might be of interest to many.
Well you cannot run an independent java application on Android. Android applications are compiled to dalvik bytecode and really are just written in java but not run on the java vm (Android does not have a java vm). However you can create a jar library that can be consumed by both a desktop and android application and that should provide reuse of platform independent code.
You can run command-line Java programs on an Android device. An example of a simple "hello, world" program is described here.
As noted previously, though, you can't use the Android framework for UI, and unless you have a rooted phone you won't be able to install it in /data or access "protected" features like talking to the Internet.
Related
I know an open source project coded in C, which compiles as system executable for Linux, Windows, OS X, iOS and Android.
On Linux/Windows/OSX it can be just executed with ./example_programm or C:\>exeample_program.exe and it starts serving it's API through http://127.0.0.1:port_number, example: http://127.0.0.1:7778
on Desktop platforms this API can be used by GUI application.
I need to know how this can be done on Android ?
I know on Android adb shell we can do su and then run android compiled program executable, and then probably use open the HTML GUI from android web browser and use it. But, this shouldn't be the case I guess.
The executable doesn't need ANY root or superuser privileges. a limited user account if run the executable makes this executable run and the program starts serving API on 127.0.0.1.
As and alternative I heard Android can either use Cordova wrapper to include this android compiled executable in it and when the Android App starts the App can trigger to execute this android executable in backend. But, I'm not so sure at the moment, if that way will work or not, or what challenges will there be. This probably needs to be tested.
Another alternate way I heard is to have this C code compiled as a library. I have no idea of C coding done in this project, and I don't know what changes I need to make to compile it as Android library. Anyway if with some help I could have this C code compiled for Android as a library, can someone please let me know how this library can be called by the Android App, and it will behave exactly the same ways it behaves on Desktop platform ? like executing the executable and it starts serving API on 127.0.0.1:7778 ?
Thanks for help :)
At a high level, you can use the Android NDK to run C or C++ code in an Android application: https://developer.android.com/ndk/index.html
Whether or not "it will behave exactly the same ways it behaves on Desktop platform" is unknown because I don't know any details about this library. If it's a simple web service, it's likely that it will work.
Regarding making design decisions, I'd leave that alone and just go in with the knowledge that C code can run on Android, then have someone familiar with Android and/or the NDK determine the best way to use the code.
I am learning python and i don't know that it will be helpful to me if i want to make android apps.I have read somewhere that python can make android app.But I want to ask you that is it a good option or we should always use andriod studio to make android apps because that is developed particularly for creating android apps.
I'm a core developer of Kivy, which has been mentioned in some of the other answers. I think it's the main option you have for making python apps for android, and it has both advantages and disadvantages.
The main technical disadvantages are (both in my opinion and I think the main problems I see people raise):
Startup speed: if the app isn't already running it takes a short time to spin up the python interpreter, up to a few seconds on older devices (or much longer if you code some things badly but that's avoidable), during which time a loading screen is displayed.
Lack of native look and feel: Kivy is its own opengl-based graphical framework, so it doesn't look like default android apps (it's customisable but still very hard to perfectly emulate something like that)
APK size: Because you have to package the python interpreter, the minimum apk size is about 7MB.
Ther are other potential disadvantages, such as the standard non-java problem of having to catch up the android api when it changes, but I consider these more minor issues, e.g. in this case since you can actually call much of the java api directly from python with pyjnius. I have a blog post about this. Another problem is that kivy's community is small compared to that of the java app community, though it's also quite active.
For some people, one or more of these are immediate or eventual barriers to using Kivy. For others they don't matter or are outweighed by the advantages, and for these reasons there are people using Kivy commercially on Android (and iOS). Personally I'm most interested in the wide space between 'I wrote a simple script' and 'I made a big polished android app', because I think it should be easier than it currently is to bundle simple things as simple apps, but that's just my own reason for using kivy.
If the question is,can i run python programs on android then by all means yes.
But if the intent is to create a mobile app usibg python then please look at kivy which is yet to support python 3.
But outside the love of python ,its best to stick to android studio for native android apps.
Chaquopy (https://chaquo.com/chaquopy/) is an option for Python on Android. It is a plugin for Android Studio so could include the best of both worlds - using the Android Studio interface and Gradle, with code in Python.
From the Chaquopy page:
With the Python API , you can write an app partly or entirely in Python. The complete Android API and user interface toolkit are directly at your disposal.
A in-depth review of Chaquopy is at http://blog.codelv.com/2018/02/a-look-at-chaquopy-python-sdk-for.html
The creator of Chaquopy also commented on that review with this:
I think there's room for many different approaches to Python on Android. Chaquopy focuses on giving complete access to all the features of the standard Android API and build tools. (For example, the XML layout file you mentioned was generated using Android Studio's WYSIWYG editor: it didn't have to be written by hand.) But if you want something more Pythonic, or portable to other platforms, then enaml-native or Kivy is the way to go.
CAVEAT: I have not (yet) tested this personally, so I cannot verify how well it works. It is rather complicated.
Additional: It appears to require a license key to run for more than 5 min and requires payment. If you decide to develop open source, there is an open source license which "will always be free of charge."
try kivy https://github.com/kivy/python-for-android
It can be used to create android apps.
Android doesn't come with a Python interpreter. So if you want to distribute an application written in Python, you will have to bundle a Python interpreter along with it. In other words, even a "Hello World!" app will be huge.
So yes, it's possible. But not recommended.
Yes you can using
1- Kivy library
2- install Ubuntu on a versatile machine
3- run buildozer to transfer your main.py file into APK file
I'm going to implement aodv protocol as a linux module for a research project, and I need to implement it on Android later.I wonder if I could compile my codes into the android kernel and have my module work as in Linux (kernel 2.6 up).
Any suggestions would be greatly appreciated.
(P.S. There are already some aodv implementations on Android, such aodv-on-android and UoB JAdhoc, however, those are implemented in Java, not involving kernels)
The tagline goes: Android is Linux, so anything (portable) you do on Linux should be simple to make happen on Android.
This is mostly true, however there are a few things you'll want to keep in mind:
Portability: If you're writing your implementation on x86 and then moving the module to ARM for Android, be careful not to use any capabilities that don't exist on both. However, for something like a network protocol, you probably won't be running into a lot of these. The only one that comes to mind is the NIC.
Dalvik: Generic Linux distributions tend to run fairly close to the OS, meaning they regularly make system calls or libc calls, and the semantics of interactions with the kernel mostly carry over to the application. Android, however, has essentially a Java environment build on top of that, and the majority of applications only interact with that framework. For you, this means you will want to be aware of the possible need to modify the Android framework in order to make changes visible to applications.
The above point depends on your use case, however. If you plan on augmenting routing for existing applications to use aodv, then you'll want to hack around with Dalvik. If you'll be writing one proof of concept application, then you can write the portions that interact with aodv in C using the NDK, and avoid having to modify the application framework.
You probably already know this, but the kernel built system is sophisticated enough that you should be able to get away with writing your module once and compiling it for two architectures or platforms just by changing your configuration.
Hope this helps.
Can I port existing python scripts on android using SL4A or ASE ? What I specifically want to do is to create an android application with normal UI elements and run the python scripts from the application itself, get the output and display it. Is this possible ?
Personnaly I think that you ask implicitly for three points:
Compatibility Desktop/Mobile
The first is the compatibility between the python library on the phone and the python library in your computer. If you don't use third party library and be sure to include the extra python library provided by sl4a, you should generally be ok.
Packaging
The second point is about how to package a Python app for android. It can easily be done with a wrapper as well described on the sl4a website. In fact they distribute a copy of a chapter of a book about SL4A that describes how to do that. So that is possible, but bear in mind that the user will be required to install python if he hasn't done so already (this is a sort of alert at the launch of the app)
UI
The third thing that you should have in mind is that you are not a 100% free concerning the widget/layout you can use with sl4a. Namely you can't really do whatever you would be able to do in Java or Scala. So you might have to consider altering your UI and do a webview instead (that can communicate back and forth with the python) with a framework to obtain a "mobile look and feel"
Hope this helps.
I think, what you want to do is make an independently apk file, that includes the python interpret and your script code.
I don't know if this can be done in Android. The only whay I know is running your script from Android Scripting Environment.
If web interface is normal UI then look at this discussion http://groups.google.com/group/android-scripting/browse_thread/thread/f86812549d2686e2/f828f916411d7a95 . You can use Python, webView, HTML5 and JavaScript
I had a similar problem and finally solved it by writing a small singleton class in Java that runs the Python-4-Android binary from the SL4A installation in a subprocess created using java.lang.ProcessBuilder. So I'm not using the SL4A mechanisms at all (triggers, upcalls, etc), just borrowing Python.
This seems cleaner than trying to start and connect to a Python process through SL4A.
This is Python 2.7.1, cross-compiling extensions from Mac OS X Snow Leopard. My Python modules are doing only text input and output, accepting socket connections, etc. No interaction with the Android API. It all works fine: writing a Java stream to Python input and reading a Java stream to get Python output. C extensions are build using the P4A instructions . (Android could not find .so dynalibs until I added
[build_ext]
inplace=1
to setup.cfg during the build. I think this is because setup 'install' is never invoked on the Android. I'm just pushing with adb.
All the activity lifecycle states seem to be working, but I can't yet determine whether the sub-process is automatically suspended while the main process is in the stopped state.
I can post code in a couple of weeks if this is of interest. (Just departing on vacation.)
My plan for packaging is to put a ZIP archive of the Python code in /assets and have the app unzip during the first onCreate. I haven't implemented this yet, but I don't expect any problems.
I am currently pondering the feasability of implementing part of the Android APIs on a desktop JVM and I was wondering whether you had already heard of such a project.
If there aren't, and you know good reasons why (beyond "no one has begun that yet"), I would be glad to read them.
There is another project (apparently in its infancy) to bring the Android API on Linux Desktop. It is called IcedRobot. On the project's home page, it states its goals as:
Have Dalvik completely separated from the usual Android infrastructure
so that it runs as any other *unix
program in the Linux environment (and
non Linux, I personally want it to
work on OSX and QNX).
Avoid Dalvik and Harmony as much as possible and put the Android stack on
top of the OpenJDK class library, and
run the whole thing in Hotspot (this
is cool, ins’t it?).
Some related resources:
The GNUlization of Android (PDF of FOSDEM presentation)
IcedRobot Dev mailing list
Running HelloAndroid
The False Dawn of IcedRobot
FOSDEM: Icing the robot
I'm not entirely certain I understand your goal, but I'll assume you do not want to emulate ARM execution and therefore not run the whole Android stack, but instead implement some subset of the Android Java APIs running on standard JVM running standard Java byte code right? If so, I do not know of any similar projects.
However, if you'd like to run the full Android stack (including Dalvik VM) on an arbitrary desktop machine (without emulation), take a look at the android-x86.org project. There are instructions for running a complete Android image within a virtual machine so that you could host Android applications within the same box.
There is also a project supplying a LiveAndroid CD image suitable for running in VirtualBox, VMWare or Microsoft Virtual PC which may expedite proof of concept.
Hope that helps.