"Hello World" Android App with as Few Files as Possible, No Ide, and Text Editor Only

Hello world Android app with as few files as possible, no IDE, and text editor only

Yes you can easily do it ALL from the command line (NO IDE involved, I promise).

This uses the old faithful Apache Ant. It does not use Gradle, that takes more work.

To Summarize

What you type is (just 2 lines to produce an apk):

    android create project --target "android-16" --path basj --activity TestActivity --package com.android.basj 

(This produces an Apache Ant build file called build.xml file which is like the build.gradle file. Now write some code but TestActivity.java is there already and will compile)

    ant debug

Setup

(Note: The "android.bat" command is deprecated since Build Tools v26, so use an old one (see link below), deprecated in this case means TOTALLY removed !{naughty Google}).

  1. Install Java JDK if not installed already (you can use jdk-8u151-windows-x64.exe for example), and make sure JAVA_HOME environment variable is defined e.g.:

    JAVA_HOME=C:\Program Files\Java\jdk1.8.0_112

    JAVA_PATH=C:\Program Files\Java\jre1.8.0_112\bin

JDK is the Java Development Kit.

JRE is the Java Run-time Environment.


  1. Install Android SDK Tools (e.g. installer_r24.4.1-windows.exe, see this answer) if not already done, and then in the SDK Manager GUI, deselect everything and choose "Android SDK Build-Tools" (e.g. Android SDK Build-Tools 19.1) + one (or many) platforms (e.g. Android 4.1.2 (API 16) JELLY_BEAN). To prove you don't need Android Studio, were not going to download it ! (only the SDK).

  2. Download Apache Ant (for example apache-ant-1.9.9-bin.zip)

Detail

To create a project from the command line using Android SDK:

Decide on a place to put your project:

cd c:\android
mkdir antTest
cd antTest

Run the command:

C:\Android\sdk1\tools\android create project --target "android-16" --path basj --activity TestActivity --package com.android.basj 
^
|
--------------+ (here's where I keep an old version of tools (version 25 in my case)

Here is the directory structure created (and all the files you need to build):

C:.
+---basj
+---bin
+---libs
+---res
¦ +---drawable-hdpi
¦ +---drawable-ldpi
¦ +---drawable-mdpi
¦ +---drawable-xhdpi
¦ +---layout
¦ +---values
+---src
+---com
+---android
+---basj

detailed output of create project:

Created project directory: C:\Android\antTest\basj
Created directory C:\Android\antTest\basj\src\com\android\basj
Added file C:\Android\antTest\basj\src\com\android\basj\TestActivity.java
Created directory C:\Android\antTest\basj\res
Created directory C:\Android\antTest\basj\bin
Created directory C:\Android\antTest\basj\libs
Created directory C:\Android\antTest\basj\res\values
Added file C:\Android\antTest\basj\res\values\strings.xml
Created directory C:\Android\antTest\basj\res\layout
Added file C:\Android\antTest\basj\res\layout\main.xml
Created directory C:\Android\antTest\basj\res\drawable-xhdpi
Created directory C:\Android\antTest\basj\res\drawable-hdpi
Created directory C:\Android\antTest\basj\res\drawable-mdpi
Created directory C:\Android\antTest\basj\res\drawable-ldpi
Added file C:\Android\antTest\basj\AndroidManifest.xml
Added file C:\Android\antTest\basj\build.xml
Added file C:\Android\antTest\basj\proguard-project.txt

Download Apache Ant from http://ant.apache.org/.

See this tutorial for setup:http://www.vogella.com/tutorials/ApacheAnt/article.html

Also see this tutorial:http://blog.vogella.com/2011/03/16/creating-android-applications-via-the-command-line-ant/

Write your code (Hello world).

Run this command and you get an Android Apk out the other side (called TestActivity-debug.apk):

ant debug

Hey presto, you got an android apk !
With new structure added:

C:.
├───bin
│ ├───classes
│ │ └───com
│ │ └───android
│ │ └───basj
│ ├───dexedLibs
│ └───res
│ ├───drawable-hdpi
│ ├───drawable-ldpi
│ ├───drawable-mdpi
│ └───drawable-xhdpi
├───gen
│ └───com
│ └───android
│ └───basj

For a final build :

ant release

If your interested in a more extensive example of Ant build.xml, or DEX files, and the deeper workings of Android look here

How to sign an already compiled apk

See how to sign an already compiled apk and also this

From an answer by @for3st here's a relevant piece of that post:

Manual Process:

Step 1: Generate Keystore (only once)

You need to generate a keystore once and use it to sign your unsigned apk.
Use the keytool provided by the JDK found in %JAVA_HOME%/bin/

keytool -genkey -v -keystore my.keystore -keyalg RSA -keysize 2048 -validity 10000 -alias app

Step 2 or 4: Zipalign

zipalign which is a tool provided by the Android SDK found in e.g. %ANDROID_HOME%/sdk/build-tools/24.0.2/ is a mandatory optimization step if you want to upload the apk to the Play Store.

zipalign -p 4 my.apk my-aligned.apk

Note: when using the old jarsigner you need to zipalign AFTER signing. When using the new apksigner method you do it BEFORE signing (confusing, I know). Invoking zipalign before apksigner works fine because apksigner preserves APK alignment and compression (unlike jarsigner).

You can verify the alignment with:

zipalign -c 4 my-aligned.apk

Step 3: Sign & Verify

Using build-tools 24.0.2 and older

Use jarsigner which, like the keytool, comes with the JDK distribution found in %JAVA_HOME%/bin/ and use it like so:

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my.keystore my-app.apk my_alias_name

and can be verified with

jarsigner -verify -verbose my_application.apk

Using build-tools 24.0.3 and newer

Android 7.0 introduces APK Signature Scheme v2, a new app-signing scheme that offers faster app install times and more protection against unauthorized alterations to APK files (See here and here for more details). Therefore, Google implemented their own apk signer called: apksigner (duh!)
The script file can be found in %ANDROID_HOME%/sdk/build-tools/24.0.3/ (the .jar is in the /lib subfolder). Use it like this:

apksigner sign --ks my.keystore my-app.apk --ks-key-alias alias_name

and can be verified with:

apksigner verify my-app.apk

JNI FatalError called: Unable to load library

Make sure the unity library is loaded using SplitCompat in your dynamic feature modules: https://developer.android.com/guide/app-bundle/playcore#load_native_libs

I'm not sure if this is handled automatically by Unity, but if it is you might want to reach out to them to address this.

Start ACODE or any other text editor from Termux

I have found a solution to get my work done. I opened an FTP server in Termux and then connected my ACODE to the FTP. Now everything works fine.



Related Topics



Leave a reply



Submit