Android без Java
После выполнения всего «корпоративного» программирования какое-то время я серьезно разочарован самим языком и всегда чувствую себя довольно затрудненным, если мне нужно вернуться к нему. Размер проекта вашего обычного приложения для Android не слишком пугающий, и библиотеки на самом деле довольно приятны в отношении стиля их кодирования, но если бы я мог избежать Java, я бы это сделал.
Итак, вопрос: могу ли я избежать этого? Несмотря на то, что на настольных компьютерах и серверах имеется множество языков JVM, VM Dalvik и сами устройства создают определенные ограничения. Это кажется немного лучше в 2.2 с JIT, но ограничение на передний край было бы довольно жестким решением.
Единственная альтернатива, которую я знаю, которая используется несколько, выглядит как Scala. Есть ли какая-то возможность, которую мне не хватает? Clojure, похоже, работает именно с проблемами, которые я проиллюстрировал выше, с Dalvik, но поскольку AppInventor построен на Kawa, может быть надежда на Lisp на мобильной платформе?
Какие другие языки уже можно использовать или сделать шаги к этому?
ОТВЕТЫ
Ответ 1
Лично я бы сказал, что Scala — ваш лучший выбор прямо сейчас. Он работает очень хорошо, и одним из недостатков является то, что вы должны включать Scala в качестве зависимости (что увеличит размер вашего приложения).
Ответ 2
Вы посмотрели Mirah? Он дает вам синтаксис Ruby и компилируется на Java. Его обозначили CoffeeScript Java.
Ответ 3
Есть ли какая-то возможность, которую я пропускаю?
Clojure, похоже, работает точно проблемы, которые я проиллюстрировал выше, с Dalvik
Я не знаю об этом. Любой JVM-язык, который является компилятором с опережением времени (т.е. Генерирует байт-код Java на ПК разработчика), должен работать с Dalvik.
но поскольку AppInventor построен на Кава может быть надеждой на Lisp на мобильная платформа
AFAIK, App Inventor использует только Kawa для генерации кода.
Какие еще языки уже использовать или сделать шаги к этому?
Ну, там HTML5 (Javascript), который работает нормально в автономном режиме.
Или, там PhoneGap (HTML + CSS + Javascript).
Или, там Rhodes (Rails-esque-приложения в Ruby на устройстве).
Или там Titanium Appcelerator Mobile (HTML + Javascript, но с Javascript-крючками для визуализации собственных виджетах пользовательского интерфейса).
Или, там Flash, по крайней мере для Android 2.2 +.
Или, там AIR. ну, хорошо, что все еще в предварительном выпуске.
Как заметил Элфред, когда я писал это, есть JRuby с Ruboto.
Есть Bedrock, Corona, DroidScript, Flixel, MobiForms, MonoDroid, MoSync, Squeak и SuperWaba.
Там C/С++ через NDK, хотя это в основном для добавления библиотек расширений в Java-приложение, а не для написания приложений с полным кодом.
Здесь есть SL4A (ранее среда сценариев Android или ASE), которая является вашим шлюзом на Python, Perl, Lua и другие языки сценариев. С этого момента вы не можете упаковать эти сценарии как APK, но они работают над этим.
Теперь ни один из них не даст вам точно взгляд на «обычное» приложение для Android. Для них вам нужен язык JVM с компиляцией со временем. И нет никаких сомнений в том, что большинство приложений Android для Android-болота являются самыми многочисленными. Но, в отличие от некоторых операционных систем с фруктовым ароматом, которые блокируют подобные вещи, у вас есть много возможностей для экспериментов с альтернативами традиционному Java-кодированию с Android.
Некоторые лысый парень пишет книгу, в которой будут рассмотрены все эти варианты, но это только частично готово прямо сейчас.
Ответ 4
В этой ссылке есть некоторые сведения о том, как получить приложения scala, работающие на android. Я уверен, что вы можете сделать что-то подобное для clojure или других языков jvm.
Ruboto стремится привести JRuby в.
Ответ 5
DroidScript, вероятно, является одним из самых простых из вышеупомянутых инструментов разработки, которые можно использовать для разработки Android. Как и в Кордове, вы используете JavaScript, но, в отличие от Кордовы, вы можете использовать собственный графический интерфейс Android или HTML5 для создания своих интерфейсов приложений.
Также у вас есть доступ ко всем устройствам/аппаратным средствам устройств, не требующим импорта загрузок сложных плагинов. Кроме того, вы получаете бонус от возможности разработки на своем мобильном устройстве, если вам нужно (вы даже можете создать APK и опубликовать их с вашего устройства).
Я бы сказал, что это очень хорошо для новичков или прототипов, но, возможно, недостаточно гибко для опытных разработчиков.
Ответ 6
Xamarin Studio позволяет создавать С#/Mono и создавать приложения для Android и iOS. Теперь слои презентации должны быть реализованы по-разному на обеих платформах, но для возможности использования С# это большая Win.
Ответ 7
Вы можете создать приложение для Android со знанием только Html/css/Js. Поэтому нет необходимости создавать Java-приложения для Android. Посетите здесь некоторые базовые знания. [1] http://www.chromeearth.com/requirements-cordova-platform/
Ответ 8
Я никогда не использовал его, но Kotlin — это новый язык, который работает на JVM, разработанном JetBrains (разработчиком Android Studio), который заслуживает упоминания. Сайт Kotlin утверждает, что язык на 100% совместим с Java и имеет учебник для Начало работы с Android и Kotlin и Android Studio теперь на самом деле поставляется с Kotlin поддержка.
Источник
Android с without java
Ever wanted to write C code and run it on Android? Sick of multi-megabyte packages just to do the most basic of things. Well, this is a demo of how to make your own APKs and build, install and automatically run them in about 2 seconds, and with an apk size of about 25kB (with API 26). API 30 (Android R+) is unfortunately at 45kB to support ARM64 + ARM32.
With this framework you get a demo which has:
- To make a window with OpenGL ES support
- Accelerometer/gyro input, multi-touch
- An android keyboard for key input
- Ability to store asset files in your APK and read them with AAssetManager
- Permissions support for using things like sound. Example in https://github.com/cnlohr/cnfa
- Directly access USB devices. Example in https://github.com/cnlohr/androidusbtest
DISCLAIMER: I take no warranty or responsibility for this code. Use at your own risk. I’ve never released an app on the app store, so there may be some fundamental issue with using this toolset to make commercial apps!
For support, you can try chatting with folks on my discord: https://discord.com/invite/CCeyWyZ
Because sometimes you want to do things that don’t fit into the normal way of doing it and all the discussions online revolve around doing it with all the normal processes. And those processes change, making it difficult to keep up and do specific things. By using Makefile s it’s easy to see what exact commands are executed and add custom rules and tweak your build. C is a universal language. Rawdraw operates on everything from an ESP8266, to RaspberryPi, Windows Linux and now, even Android. Write code once, use it everywhere.
When you don’t fill your build process with hills of beans, you end up being left with the parts that are important, and not the frivilous parts. This makes it easier to develop, deploy, etc, because everything takes much less time.
A little bit of this also has to do to stick it to all those Luddites on the internet who post «that’s impossible» or «you’re doing it wrong» to Stack Overflow questions. Requesting permissions in the JNI «oh you have to do that in Java» or other dumb stuff like that. I am completely uninterested in your opinions of what is or is not possible. This is computer science. There aren’t restrictions. I can do anything I want. It’s just bits. You don’t own me.
P.S. If you want a bunch of examples of how to do a ton of things in C on Android that you «need» java for, scroll to the bottom of this file: https://github.com/cntools/rawdraw/blob/master/CNFGEGLDriver.c — it shows how to use the JNI to marshall a ton of stuff to/from the Android API without needing to jump back into Java/Kotlin land.
Most of the testing was done on Linux, however @AEFeinstein has done at least cursory testing in Windows. You still need some components of Android studio set up to use this, so it’s generally easier to just install Android studio completely, but there are instructions on sort of how to do it piecemeal for Windows.
Linux install Android Studio with NDK.
This set of steps describes how to install Android Studio with NDK support in Linux. It uses the graphical installer and installs a lot more stuff than the instructions below. You may be able to mix-and-match these two sets of instructions. For instance if you are on Linux but don’t want to sacrifice 6 GB of disk to the Googs.
NOTE You probably should use the WSL instructions instead of these instructions as it will produc a more lean installation.
- Download Android Studio: https://developer.android.com/studio
- Start ‘studio.sh’ in android-studio/bin
- Let it install the SDK.
- Go to sdkmanager («Configure» button in bottom right)
- Probably want to use Android 24, so select that from the list.
- Select «SDK Tools» -> «NDK (Side-by-side)»
- Download this repo
- Turn on developer mode on your phone (will vary depending on android version)
- Make your own key
- Go into developer options on your phone and enable «USB debugging» make sure to select always allow.
- Plug your phone into the computer.
- Run your program.
Steps for GUI-less install (Windows, WSL)
If you’re developing in Windows Subsystem for Linux (WSL), follow the «Steps for GUI-less install» to install the Android components from the command line, without any GUI components.
Extra note for actually deploying to device in Windows
In order to push the APK to your phone, you need adb installed in Windows as well. You can do that by getting the full Android Studio from https://developer.android.com/studio#downloads or directly https://dl.google.com/android/repository/platform-tools_r24.0.4-windows.zip. Installing the full Android Studio is easier, but you can also get the «Command line tools only» and install adb from there. The steps below outline how to do this with the direct link.
Install Windows Subsystem for Linux (WSL). You can find instructions here: https://docs.microsoft.com/en-us/windows/wsl/install-win10 — we use «Ubuntu» for this.
- Download «Command line tools only»: https://developer.android.com/studio#downloads — you can get a URL and use wget in WSL to download the tools by clicking on the «Linux» toolset, then right-clicking on the accept link and saying copy link to location. Then you can say wget
- in WSL.
- Create a folder for the Android SDK and export it. You may want to add that export to your
- Unzip the «Command line tools only» file so that tools is in your brand new android-sdk folder.
- Install the SDK and NDK components:
If you are using Android 29 or older, do this.
If your platform command-line tools are 30 or newer, the command-line tools will be placed in the cmdline-tools folder. So, you will need to execute the following:
NOTE If you are upgrading NDK versions, you may need to remove old versions, this Makefile does not necessarily do the best job at auto-selecting NDK versions.
You can see all avialable versions of software with this command:
- Install the Windows ADB toolset.
- NOTE: because of updates to environment variables, you may want to close and re-open your WSL terminal.
- Download this repo
- Turn on developer mode on your phone (will vary depending on android version)
- Go into developer options on your phone and enable «USB debugging» make sure to select always allow.
- Plug your phone into the computer.
- Make your keystore.
If you are going to use this
You may want to copy-and-paste this project, but, you could probably use it as a submodule. You may also want to copy-and-paste the submodule.
You MUST override the app name.
- See in Makefile APPNAME and PACKAGENAME you should be able to include this project’s makefile and override that.
- You must also update AndroidManifest.xml with whatever name and org you plan to use.
- You will need to update: package in to be your PACKAGENAME variable in Makefile.
- Both android:label labels need to reflect your new app name. They are in your and sections.
- Update the android:value field in android.app.lib_name
If you are using permission you have to prompt for, you must both add it to your AndroidManifest.xml as well as check if you have it, and if not, prompt the user. See helper functions below. You can see an example of this with sound_android.c from ColorChord. https://github.com/cnlohr/colorchord/blob/master/colorchord2/sound_android.c
Be sure to uninstall any previously installed apps which would look like this app, if you have a different build by the same name signed with another key, bad things will happen.
You can see your log with:
- If your app opens and closes instantly, try seeing if there are any missing symbols:
Because we are doing this entirelly in the NDK, with the JNI, we won’t have the luxury of writing any Java/Kotlin code and calling it. That means all of the examples online have to be heavily marshalled. In rawdraw’s EGL driver, we have many examples of how to do that. That said, you can use the following functions which get you most of the way there.
struct android_app * gapp;
int AndroidHasPermissions(const char* perm_name);
void AndroidRequestAppPermissions(const char * perm);
void AndroidDisplayKeyboard(int pShow);
int AndroidGetUnicodeChar( int keyCode, int metaState );
int android_width, android_height;
extern int android_sdk_version; //Derived at start from property ro.build.version.sdk
Departures from regular rawdraw.
Also, above and beyond rawdraw, you must implement the following two functions to handle when your apps is suspended or resumed.
void HandleResume(); void HandleSuspend();
In addition to that, the syntax of HandleMotion(. ) is different, in that instead of the mask variable being a mask, it is simply updating that specific pointer.
As it turns out, Google somehow lets apps built with this onto the store. Like ColorChord https://github.com/cnlohr/colorchord.
Part 0: Changes to your app.
- Make sure you are using the newest SDK.
- You will need to add a versionCode to your AndroidManifest.xml . In your AndroidManifest.xml , add android:versionCode=»integer» to the tag where «integer» is a version number.
- In your AndroidManifest.xml , change android:debuggable to false.
- You may want to support multiple platforms natively. Add the following to your Makefile : TARGETS:=makecapk/lib/arm64-v8a/lib$(APPNAME).so makecapk/lib/armeabi-v7a/lib$(APPNAME).so makecapk/lib/x86/lib$(APPNAME).so makecapk/lib/x86_64/lib$(APPNAME).so
- You will need to specify target and Min SDK in your AndroidManifest.xml See:
- Those target / min versions must match your Makefile. Note that without a minSdkVerson google will wrongfully assume 1. This is dangerous. Be sure to test your app on a device with whichever minSdkVersion you’ve specified.
- You will need to disable the debuggable flag in your app. See
Get a google play account. Details surrounding app creation are outside the scope of this readme. When getting ready to upload your APK.
Keys: You will want a key for yourself that’s a real key. Not the fake one.
First you will need to make a real key. This can be accomplished by deleting our fake key my-release-key.keystore and executing the following command (being careful to fill #### in with real info):
make keystore STOREPASS=#### DNAME=»\»CN=####, OU=ID, O=####, L=####, S=####, C=####\»» ALIASNAME=####
The alias name will be standkey . You will want to verify you can build your app with this key. Be sure to fill in STOREPASS the same.
make clean run STOREPASS=####
Let Google create and manage my app signing key (recommended)
Export and upload a key and certificate from a Java keystore
If you want to use the play store key with «Export and upload a key and certificate from a Java keystore» Instead of Let Google create and manage my app signing key (recommended) and follow PEKP instructions.
Prepping your app for upload.
You MUST have aligned ZIPs for the Play store. You must run the following command:
zipalign -c -v 8 makecapk.apk
Upload your APK makecapk.apk made with your key.
Try a bunch of these cool priveleges, see what they all do.
- permission.ACCESS
- permission.INTERNET
- permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS
- permission.ACCESS_NETWORK_STATE
- permission.WRITE_EXTERNAL_STORAGE
- permission.READ_PHONE_STATE
- permission.GET_TASKS
- permission.REORDER_TASKS
- permission.WRITE_APN_SETTINGS
- permission.READ_SECURE_SETTINGS
- permission.READ_SETTINGS
- permission.REAL_GET_TASKS
- permission.INTERACT_ACROSS_USERS
- permission.MANAGE_USERS
- permission.INSTALL_PACKAGES
- permission.DELETE_PACKAGES
- permission.INTERACT_ACROSS_USERS_FULL
- permission.READ_MEDIA_STORAGE
- permission.WRITE_MEDIA_STORAGE
- android.permission.VR
- android.permission.INSTALL_PACKAGES
About
Build android apps without any java, entirely in C and Make
Источник