C Code in G1? JF? Anyone? - G1 Android Development

I'm just wondering is anyone trying this yet? i mean is it even possible?
Just a thought for you big shot android devs out there JF, Haykuro, LucidREM

Google "android jni"

Well, a quick trip around google would have helped you.
Android is using java, and currently it's not possible to use anything else.
But anyway, would you rather compile all of your code for multiple architectures? J makes things easier here...
You can write cli-apps in C though... i heard something about that there was plans to make other languages available in android, but i wouldn't hold my breath
Also, why is this related to JF/Haykuro/LucidREM?

I think you can do this with JNI: http://en.wikipedia.org/wiki/Java_Native_Interface

Using an ARM native compiler (such as the ones at CodeSourcery, http://www.codesourcery.com/sgpp/lite/arm/portal/[email protected]=lite) you can compile your apps and run them fine on the G1
Code:
$ arm-none-linux-gnueabi-gcc -static foo.c -o foo
$ adb push foo /data/foo # we are pushing to /data as it is +rwx (read, write, execute) for a standard user.
$ adb shell /data/foo
a=1
b=2
foo=a+b
foo=3

^^^
OH I love when I stumble across a post like this and have something new to play with.

The problem is due to the different location of the linker and mainly the different libc you have to statically link everything.
I have been having a hell of a time getting DPKG to build statically.

I picked up a copy of the newly released book, Unlocking Android, at Barnes and Noble yesterday. There is a whole chapter devoted to writing native apps using C (and ARM assembler) with the CodeSourcery tools linked above. The author walks through the steps you need to do to dynamically link the libraries so you don't end up with enormous statically linked executables. Well worth the price.

It is surprising what you can do with C on the phone, its actually not too difficult. The method outlined below doesn't use the non native toolchains and if you use the sourcery toolchain (as mentioned above) you will end up with bigger binaries as you need to link in a standard glibc and not androids bionic libc. This may or may not be important for your project.
The other advantage of the steps below is that you will build and link against any library that is available to the android platform
The easiest way that I've found to start when porting or writing new applications is this method.
1) Check out the current git android source.
2) Build the entire tree, "make" in the top level directory.
3) Create a new directory in mydroid/external/packagename/
4) Copy one of the simple android Android.mk (Make) files from a "like" target.
(If doing a library, choose a library, if coding an executable , choose that).
5) source the mydroid/build/envsetup.sh in the users bashrc
6) cd to your directory, then instead of the usual "make" do an mm.
This should create a binary, which you can adb push to the phone and run at the console.
You can do all the usual things if linked properly, like write the framebuffer using sdl, play sounds, create network connections.
Just remember that you dont have a standard libc (glibc) to play around with you have "bionic". If you are missing your favourite glibc function , it is probably intention and not abug. You'll either need to port it or make do with the functions provided by bionic.
These instructions are for a "pure" C program. you can mix the java like dex calling by 'shelling' out to the C application when you need performance, however premature optimization is the root of all evil, you'll be surprised what performance you can pull from davlik (And I expect the VM guys to improve this even further).
I know that is a lot to digest. Will do the best I can to answer your questions. I'm by no means an expert in the area, but have learned a bit about C on android.

Well I don't know much about all this but what i know is that e.g.
ScummVM IS written in C++ , and so is g-arcade.
His FAQ says:
"How did you do this? Is it Java?
No. ScummVM is a C++ program. For this port, I turned it into a really big JNI library so Android still thinks it's running a Java program, but almost all of it is implemented in C++."
(http://sites.google.com/site/scummvmandroid/faq#TOC-How-did-you-do-this-Is-it-Java-)
So if some1 wanna port MAME, feel free to xD

Related

GNU Standard compilers for android

Hi, I'm beginning c++ Development, Done a little stuff with OpenGL but love challenging myself with command line stuff. For this, I mostly use gcc, and either geany or nano.
I did have debian on my G1 so I could use nano and gcc. It worked well, but the only way of getting files to and from would be via ftp.
I was wondering if people who had experience compiling command line stuff for android (Hasn't Bash recently been ported?) could help or give me some tips? nano + gcc would be awesome, though gcc is a must, I'd be able to copy my app to my g1's SD card and have my terminal apps on the go, great for long journeys and stuff.
I'd even be tempted to look at writing an IDE in Java (though I've not much experience in GUI development, I have in programming theory).
Plus, are there instructions for actually compiling linux apps for android, I don't seem to have found any anywhere, and It'd be good, that we could maybe compile more apps like rtorrent and such.

[Q] Running a C++ binary

So this is probably a silly question.
I have this rather complicated app that would be a heck of a lot of work to convert to Java.
It runs in the command line and works fine in Linux.
Trying to run it fails, but x86 bytecode probably isn't very ARM friendly.
Is there a specific way I need to compile the application?
Is it even possible to run it from a console emulator?
Thanks.
Try Android NDK
I am also new to Android Dev ( 15+ years Linux, 10+ years Java, etc.)
I am not an expert but for your purposes you need the "Android NDK" in addition to the "Android SDK" that most developers utilize.
"The Android NDK is a toolset that lets you embed components that make use of native code in your Android applications.
Android applications run in the Dalvik virtual machine. The NDK allows you to implement parts of your applications using native-code languages such as C and C++. "
Basically the tools are needed to cross compile C++ source code for the target ARM environment.
I am prevented from posting the download URL for some bizarre reason, but it is listed under "Native Development Tools" on the left side of the web page for the standard "Android SDK" download.
Yeah that's because you are new. It's a system to prevent spammers from posting URLs.
When you have a couple of posts the restriction will disappear
Anyway; found it, seems to be what I'm looking for.
I'll check it out in the morning.
Big thanks
Dmitry Moskalchukhas written a patch for the ndk to better support c++ see crytax dot net there are posts on google groups android-ndk talking about it
Thxs for the info. I was aware that the NDK did not include all of the libs that desktop Linux/UNIX developers expect. The suggested patched version adds the STL libs back in.
Sent from my PC36100 using XDA App
There are A LOT of libraries missing
I guess I'll just keep it a hosted app.
Thanks for all the input

GCC make for Android?

Hello everyone. I'm looking for a way to use gcc make natively on Android. I know would supposedly be slow and heat up my cpu, but I don't get enough time on my computer to develop via a cross compiler.
Something like this would be ideal:
http://forum.xda-developers.com/showthread.php?t=1645182
I'd post there asking about a download link but the forums won't let me until I've made ten posts.
If anyone has any ideas how to get this working I'd love to hear them!
I found a gcc binary here:
rwiki.sciviews.org/doku.php?id=getting-started:installation:android
I don't know what version it us but it seems to run. I think I will try compiling gcc from scratch.
Can bionic libc be replaced with the full version of libc? Or would that break things?
Next up I think I'll try to get bash on this phone.
I'll post an update when I have gcc fully working.
I've found an app that does most of what I needed, called Terminal IDE on the play store. I now have a mostly functional development environment on my phone.
Next up, some of the open source software I want to port uses autoreconf, which is part of automake. Unfortunately, automake needs access to /tmp/ during configure, which doesn't exist. I guess I'll just have to edit the configure file on my PC and point it to a path that's accessible.
Does anyone know of an automake binary for Android?

How to Program Own Apps in Android 4.4.4 KitKat

I am a programmer who has programmed in x86 Assembler, Visual C++ under Windows and DOS.
I need to be able to do own applications for Android KitKat 4.4.4
I need any help and information such as manuals, books, lists of commands, lists of functions, C compiler or, best, Assembler compilers for a given processor, etcetera.
I would like to code in Assembler. I guess I need an Assembler for a given processor and cell phone. In case not possible, I need a C compiler for Android 4.4.4 KitKat. I need the basic rules on how to code for this OS as well as the OS calls which I can use, as well as a description of function libraries which may come with the C compiler.
I prefer pure C than C++ or Java.
I have briefly searched the Internet with various key words and I have not been able to find anything relevant.
Please, does anyone have any information where I can get anything helpful.
I am totally new to this OS and I do not even know the shell commands. I do not have much information of the shell, although I have found a basic list on this forum and I use ls and ? and go by the name as a dumb fool.
Please, advise.
While Android is in Java, it also allows you to run C/C++ native code.
Search "Android NDK" and you will find the relevant documentation.
Arws Apps said:
While Android is in Java, it also allows you to run C/C++ native code.
Search "Android NDK" and you will find the relevant documentation.
Click to expand...
Click to collapse
Thanks. I have tried NDK. I am not sure whether I have installed this correctly but I would keep this.
Because NDK is hardware specific and I am not sure whether and how much Moto E XT1023 and others are supported, I have installed Android Studio 1.2 ad started with XML and Java. I have done similar things with HTML and Java for web sites. I would use XML as much as I can and Java only to get and set some variables, then I would use C for programming and then I would set Java variables and methods. I am not very happy with Java but there is not any other way for now. Hopefully, in the future, they would make XML a real language with all the resources available, functions and methods.
At least Java has a very C-like syntax, so in general it shouldn't be that difficult. In some sense it would even be easier (no memory management).
Arws Apps said:
At least Java has a very C-like syntax, so in general it shouldn't be that difficult. In some sense it would even be easier (no memory management).
Click to expand...
Click to collapse
Yes. You are right. I would prefer, however, a pure ANSI C. This can be done either as an interpreter to be hardware independent or as a compiler upon launch, the system would have a compiler, the user would download only the ASCI text. Upon launch, the compiler would be called first to compile and then the application can be launched. Then, the user can either keep the .exe or keep just the ASCI text, in which case, new compilation has to be done with every launch. A compilation would normally take one or a few seconds only for normal applications.

Development Environment Setup: Hardware?

Asking this question because the attempt to get TWRP on my device is becoming a compound problem as the distance to being able to build it approaches 1. Otherwise known as the law of inverse noobness: Hindsight is always 20/20. Personally, not even half way to 1 in being able to do this, as am fairly new to doing things at the operating system level of programming. Not brand-new though, and knowing how and where to look things up helps, so if you have hints or can point me in the right direction that'd be great. First question is sort of along the lines of "how do you setup your dev environment" if you want to make it modular? More precisely:
So right now, the build page for AOSP concerning my device says to use Ubuntu 14.04 and do all those things to set it up for that. Do I need to do that in order to get TWRP built for my device? To have it set up the same way as the AOSP advises? Having a different computer for each dev environment would be a bit much, but running them in qemu seems even more ridiculous. Perhaps a better idea is to set up a "build environment" on bootable USB sticks that do all the work? That would simply a lot of things, like not having to swap out hard drives, and being able to easily clone a USB drive to "just work" and build AOSP/TWRP at will on any computer.
For reference, it is the Moto G Power (2021) "Sofia" device. They've released sources for it, but not much development going on. So learning how to do this for my device might just unlock TWRP (and with it, probably the Nethunter kernel/chroot environment) for other devices not yet supported.
Help me, help you. Thanks.
(Have other questions, too).
Why not use WSL2?
How to install Linux WSL2 on Windows 10 and Windows 11
The latest version of the Windows Subsystem for Linux is a significant upgrade; for most, it's now easier than ever to install.
www.windowscentral.com
jwoegerbauer said:
Why not use WSL2?
Click to expand...
Click to collapse
I don't use windows.
Bump.
Asking this because it seems that, being new to programming and having no formal training, I'm missing something from tutorials (like the TWRP git page, or some of the tutorials here on this forum that haven't been updated since 2013) and other material that might be thought to be "known" or "implied" and I just can't seem to understand what. Because when I go to build projects or whatever, following tutorials to the letter, still end up with errors and other problems that aren't covered in the tutorial. Part of that problem is installing dependencies, and then having them conflict with other installed things, like having two of python and three versions of java. So having a "build environment" to prevent conflicts is something that wasn't taught, but learned through trial and error, but that isn't the only problem I'm having.
McChadwicke said:
For reference, it is the Moto G Power (2021) "Sofia" device.
Click to expand...
Click to collapse
Hmm. I have the same model, but it's "borneo".
Did you build TWRP for your device? Any pointers or tips?
I usually just modify stock recovery to have rooted, permissive ADB.
I really don't need more than that in a recovery.
I haven't done much with my GP21 since the Firehose loader is restricted.
Renate said:
I usually just modify stock recovery to have rooted, permissive ADB.
I really don't need more than that in a recovery.
I haven't done much with my GP21 since the Firehose loader is restricted.
Click to expand...
Click to collapse
Not sure why the last reply didn't quote you...
Setting up a build environment is an evolving problem. As of this writing it seems the Ubuntu team is switching to a "pro version" system, a paywall, for some services...
Also, AOSP recommends Ubuntu 14 for a build environment. Gave up trying to run it from USBs lol, it is running on a dedicated system. But android-sdk is no longer available in apt, while running Ubuntu 14.04 + latest updates? So went to check why and now AOSP is using its own system for build environment setup and management. Tried running it in Ubuntu 14, but gave errors with the setup script provided.
Seeing now if I can't get the android sdk to run in Mint-XFCE... Will check back. TWRP build page says I need these things to build it (TWRP), right?
Also, how much of the preinstalled vendor crud can be pruned before it breaks?
Thanks.
Edit: reference on the TWRP guide I'm using is https://forum.xda-developers.com/t/...ompile-twrp-from-source-step-by-step.3404024/ (posted 2016)
I think that all build environments are getting more restricted.
"Just do it OUR way" seems to be the new corporate slogan.
I build Android apps without Android Studio, Gradle or an IDE.
Renate said:
I think that all build environments are getting more restricted.
"Just do it OUR way" seems to be the new corporate slogan.
I build Android apps without Android Studio, Gradle or an IDE.
Click to expand...
Click to collapse
Does TWRP have its own build control system? Considering all these changes, should it?
To keep things isolated, clean and manageable on host system, that has no dev tools
or anything extra besides standard desktop stuff. (under main linux distros)
#1 For smallest , fastest deployment of various build/dev environments i use schroot
on devuan/debian , it is a system to manage/automate the use of chrootable containers.
like regular manual chroot but most thigs are automated/preconfigured with
just a few commands and config files.
Basicaly a new root filesystem (userspace) that is independent of hosts root filesystem and just
uses hosts kernel (or as much/little acces to kernel as you give it trough schroot config files)
has its own packages and dependencies and will only see specific sections of hosts filesystem sections you give it access to like say /src/myproject from host. can be a separate /home
or shared with host, all depends on your config.
Using debootstrap to create the filesystems for containers of specific distributions/verions.
Or can just manualy copy an install and rip out the kernel etc...
(Can install ubuntu userspace in debian with debootstrap , if need be.)
(like lineageOS was hard to find all the correct/matching dev tools under devuan, so ubuntu it was)
#2 For something a bit beefier LXC on top of libvirt.
(regular chroot wont run services, or have its own networking , LXCs can , with some extra configuration)
#3 For when you just need an actual full blown VM os installation use KVM/qemu on top of libvirt .
(like installing 15 year old redhat 5.1 in a container wont work, kernels and main libs too far apart)
(or anything that is just too different from current linux kernel , other OS s etc...)
virt-manager is nice for graphicaly managing VMs and LXCs
#1 But schroot is essential and will suffice for more then 90% if not whole 100% of your needs.
if you want a clean host system from being clobbered by constant installing and testing and such . Keeps the environment contained in its own filesystem namespace , have as many as you need .
start fresh,rollback,clone etc.............
Once configured just start another tab in a terminal emulator and schroot in to the container
and your main host system in unaffected, always clean .
#4 Running all of this on top of ZFS takes it a step up, to the next level of effeciency.
zfs helps quite a bit with cloning,branching,snapshots, rollbacks but not essential,
like git versioning for things that are too big for or are not made for git management
(but is another system on to itself to learn, so ignore it if new to linux )
just cloning a 300Mb-1Gb base bootstrap install folder takes no time on regular filesystem on ssds .
With these 3 tools , you can have 10s if not 100s of different environments on a single host
quickly deployable once you get to know the procedures. all usable at the same time without
reboot,
#5 The most important is learning how to hunt for the right version of tools and all of the
dependencies and the correct versions of those , as each project will have their own
and will base it on their own distribution of choice at a specific point in time.
(by being able to install/test/restart in container makes this whole process , easier)
you can test many different ideas at the same time , and merge what works in
to your own dev-build-env for a specific project.
(like hunting down correct tutorial for specific/old/obscure phone and a rom and recovery
and rooting tools associate from a time long past. using wayback machine to source
correct versions of each , as normal web has erased them )
even used schroot to install games for nephew from untrusted sources without hesitation,
and just delete the container when done, but that was a bit more involved as proprietary
nvidia drivers had to be installed on host and partially in containers.
dandudikof said:
To keep things isolated, clean and manageable on host system, that has no dev tools
or anything extra besides standard desktop stuff. (under main linux distros)
#1 For smallest , fastest deployment of various build/dev environments i use schroot
on devuan/debian , it is a system to manage/automate the use of chrootable containers.
like regular manual chroot but most thigs are automated/preconfigured with
just a few commands and config files.
(like hunting down correct tutorial for specific/old/obscure phone and a rom and recovery
and rooting tools associate from a time long past. using wayback machine to source
correct versions of each , as normal web has erased them )
Click to expand...
Click to collapse
neat. schroot looks like a solution. answers a lot of questions, anyway. that last part scares me though. using the wayback machine to source things jeez. there's gotta be a better way, but probably not unless i want to do it myself which will only add time to "the project".
McChadwicke said:
neat. schroot looks like a solution. answers a lot of questions, anyway. that last part scares me though. using the wayback machine to source things jeez. there's gotta be a better way, but probably not unless i want to do it myself which will only add time to "the project".
Click to expand...
Click to collapse
That was just worse case scenario if you get in to very obsolete/old/abandoned stuff (10-20 year old) projects/hardware etc...
dandudikof said:
10-20 year old
Click to expand...
Click to collapse
yeah some of the hardware is in that range. actually upgraded one of the old rigs (because parts are cheap) from an athlon to a phenom lmao thing has 16gb ram, it is stacked now with top of the line things from that era. keeping it around for nostalgia's sake at this point since it still works.
xmrig gets abysmal hash rates, not even worth running on older hardware.

Categories

Resources