I want to build some arbitrary application, for example, found on GitHub: https://github.com/heruoxin/Clip-Stack (I already have the application, so I don’t need to send links to binary builds)

Often, bundled with the application is a wrapper for Gradle, sometimes the project properties from Eclipse, sometimes nothing. The process itself, despite its apparent simplicity, is rather complicated: you need to deflate the SDK / NDK (now they don't give direct references to them, but more on that later), set up environment variables and run ./gradlew , and after ./gradlew 200-300 megabytes of dependencies, very often some kind of error comes out (for example, that proprietary Java 8 is needed). And even if there is no error, the assembly can gobble up 2-3 gigabytes of memory, the entire swap and then fall, citing a lack of memory (after all, now all the rich are developing on the latest generation macbooks, and everyone is in a hurry - so it’s all going in 10 threads, otzhiraya 10 times more memory). In addition, this approach makes it impossible to compile the application on a network-isolated machine: Android Studio Gradle without connecting to the Internet

Question: how to build an application without the use of thick collectors?

Perhaps the main problem is due to the complexity of settling dependencies. For example, to build the application above, I needed:

 support-fragment-25.2.0.aar support-compat-25.2.0.aar support-annotations-25.2.0.jar support-core-utils-25.2.0.aar support-core-ui-25.2.0.aar appcompat-v7-22.2.1.aar recyclerview-v7-25.2.0.aar cardview-v7-25.2.0.aar 

But it quickly became clear that in the 25th version something was changed and it does not fit, the compiled application just crashes. I downloaded a lot of versions of aar-packages and self-made scripts indexed them, creating a self-made base of characters, but I ran into the problem that in some version there is no necessary feature, and after a couple of versions of this feature (or another) anymore. In addition, it is not very clear where and how to get official binaries, without a proprietary SDK Manager. In general, I gave up.

Analysis of Gradle's behavior showed that javac + dx are not used at all, and aapt is used only for processing images.

If someone has the opportunity / wants to write a light-hearted IDE, or at least a script to build applications, then I will gladly join the project.

References:

  1. https://developer.android.com/studio/build/building-cmdline.html - official instructions lead me to the Gradle that I hate

  2. https://stackoverflow.com/questions/41132753/ - this briefly describes the build process via javac + dx + aapt, additional shine from jarsigner + zipalign. It works (checked personally), however, it doesn’t describe how to do it exactly (however, if you read the manuals, it becomes clear), it’s not described how to resolve dependencies, what to do with resources, etc., but also how to install packages from the sdk.

  3. https://metacpan.org/pod/Android::Build - the link is no longer working, but in the archives you can find a wonderful script that could build simple Android applications

A Lex Hobbit is called into question from How to create a modular android application

  • four
    The most reasonable thing for you would be to suppress your own exclusiveness, special opinion and install the standard Android developer package (1.9 GB), which includes ALL the necessary and even the necessary version of the JDK, while fully configured to work, and also love Gradle as soon as possible, or buy a lot of valerian with glycine, because the modern build APK without the help of Android Studio is able to "finish off" anyone. - pavlofff
  • My exclusivity comes from the fact that I’m probably the only one who can’t understand: why to build a trivial application is a little harder to Hellow World, you need to download gigabytes of files and take up gigabytes of RAM. My uniqueness is that at one time, several megabytes of RAM were enough to build programs, and they made these programs much more than the average Android applications developed in our time. And I just can not understand and accept the situation around the development, I just disgusted. - bukkojot
  • If you are uncontrollably pulled into an old school and everything is so disgusting that it is so functional, then with respect to android development you can try Eclipse with ADT earlier versions (times of the 2nd android), this is still the bottom, of course, according to modern ideas, but since everything will be nice to your heart: volumes in megabytes, build via Ant, all handles .. I really don’t know how it will interact with modern Android API there, but theoretically an application under API9 will work on API26 as well, naturally with all sorts of Material Design and other mainstream will probably have to say goodbye. - pavlofff
  • ".. why for assembling a frivolous application is a bit more complicated than the Helloworld .." - because they can. In general, “in your time” (it’s also mine, for I started in the far 80s) development tools were somewhat simpler in terms of functionality, as well as solvable tasks and I, for example, wouldn’t want to go back to the development tools of that time I’m just too lazy to do huge amounts of stupid work - IDE will do it for me and I don’t feel sorry for either gigabytes or gigahertz, they are relatively expensive in our time. - pavlofff
  • In addition, the IDE is unknown, your application will be more difficult or easier, and it provides opportunities for the most complex project, so that its development is comfortable and with the least amount of routine. Light versions for fans of helovords as it is not provided, unfortunately. - pavlofff

2 answers 2

As already written in the commentary on the issue - the assembly and "life" without Android Studio is very difficult. But since the conditions dictate the need to live without it, we will adapt.

Pre-assembly environment preparation

  • Java jdk
  • Android SDK (at the very bottom of the page in the section "Get just the command line tools" )
  • Setting Environment Variables
    • JAVA_BIN Path to the bin folder of the Java JDK
    • ANDROID_SDK path to the folder with the Android SDK
  • Private key for signing an APK file (let's call it release_key.keystore )

    keytool -genkey -v -keystore release_key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

  • Write application code and verify application structure

Step by step assembly algorithm

Step-by-step algorithm for assembling an Android application without using gradle / ant / Android Studio (we assume that all the source code, including AndroidManifest.xml , we already have the necessary libraries):

  1. Create a R.java , PK file from assets, resources, and AndroidManifest.xml and get MyApplication.apk.unaligned using using aapt package
  2. Compile java sources in *.class using javac for this
  3. Create an executable classes.dex file from *.class using dx
  4. Add MyApplication.apk.unaligned file to classes.dex using aapt add
  5. Sign MyApplication.apk.unaligned with debug or release key
  6. Align our APK using zipalign and voila!

Creating a .aar library

The algorithm for creating the .aar library is similar to the algorithm for creating an APK file.

  • in item 1 instead of R.java we create R.txt using aapt with the option --output-text-symbols and the name of the archive with the extension *.aar
  • in item 3 instead of classes.dex we create classes.jar using

    jar cvf classes.jar * .class

  • in item 4 we add classes.jar to the archive with the extension *.aar and that's it, our separate AAR library is created

P / S correct later and you can write a script for the assembly.

And it seems that everything would be simpler if they even went to Jack & Jill , but as the developers report , they realized what it would cost them. Below is the process of building an APK using Jack Jacket. enter image description here

  • one
    How about external libraries, libraries of support without public repositories? it’s hard to imagine an android application without them if it is a little harder to “hello the world” - pavlofff
  • one
    @pavlofff I will write this a little later ... while I wrote the quick build version, add the rest in the evening, as soon as I return from work =) Thanks for the comment - I’ll take into account - Lex Hobbit
  • Actually, for the sake of all this, the question was created. This is the main thing. - bukkojot
  • By the way, do not copy the answer from the language tutorial. Points 1 and 4 can be combined by making a blank, which then patch - there will be a faster assembly. You can compile to dex only the necessary files - also acceleration. aapt add is not needed, the usual zip archiver is enough. Zip-align is only needed for the market, for debug it is not necessary (it is necessary for mmapa assets). - bukkojot
  • one
    jcenter is actually the official android repository for third-party external libraries, it is the default that is specified as the external repository in Android Studio, and MavenCentral is also often used. The AAR format is the Android library format, it is much "larger" than the JAR and can include resources, other libraries, and native modules. - pavlofff

Can be assembled under Intellij IDEA without Gradle. A couple of years ago, I practiced this ... Hand-to-hand collecting all the jar/aar manually add dependencies and go ahead.

There are fans of the Android build under maven, oh well, yes - it's a fat builder :)

There was an experience of assembly under Ant - I do not know how thick it is for the vehicle ...

In any case, I fully subscribe to @pavlofff:

wholeheartedly love Gradle in the shortest possible time, or buy a lot of valerian with glycine, because the modern build APK without the help of Android Studio is able to "finish off" any

  • Maven Faster Gradle - Alex78191
  • one
    So, the first shot in the holivar is :) - Barmaley
  • Intellij IDEA - does it no longer eat gigabytes of operatives? And with regards to "finish off" - I can apply sed-magic and quickly all these new-fangled SuperCoolActiviti quickly degrade to simple Activity with the first version. - bukkojot
  • one
    I do not understand these arguments at all. A gigabyte of RAM costs roughly 1,000 rupees, the price of a movie ticket for a couple with a girl or a trip to a coffee shop. Well, mlin, really difficult? - Barmaley
  • @ Alex78191 buckbuild.com , the fastest of the above =) - Lex Hobbit