Create android apk manually via command line (Makefile) - android

Problem
I want to create an android app
via a vim & makefile only
no gradle, no ant, no maven, no android.mk and all other stuff
Why?
It is a high performance C++ code that is wrapped for an android device.
Ergo, I do not need 99% of gradles services
15+ seconds built time via gradle for a small program? That is unacceptable.
The incorporation of native code in gradle is ridiculous. These gradle guys come up with an experimental ndk plugin that keeps changing syntax.
I only target ARMv8-A. I will have partly AARCH64 assembler code. And I use a pre-processor m4 that generates *.cpp before they get compiled. Can't imagine gradle has something for this.
My Progress
I know that the following steps are REQUIRED:
Create keystore by keytool from $JAVA_HOME/bin.
Compile source files via javac from $JAVA_HOME/bin.
Create Dalvik Executables for the device by dx from $ANDROID_HOME/built-tools.
Create the .apk file by aapt from $ANDROID_HOME/built-tools.
Sign apk package by jarsigner from $JAVA_HOME/bin.
Align apk package by zipalign from $ANDROID_HOME/built-tools.
Install software on phone by adb from $ANDROID_HOME/tools.
The app crashes on startup. Even when I want to create a blank activity.
-

ok, I figured it out. I placed my sample code on https://github.com/skanti/Android-Manual-Build-Command-Line
Hope it helps you guys too.

Inspired by your work, I published a similar package. However, I use a simple make.sh script instead of Makefile (because I had issues interpreting its syntax). https://github.com/Kolodez2106/HelloWorld-app-compiled-in-bash

Related

Is there apktool on Android? I want to assemble ".smali" and make new ".apk" in an Android application

I want to assemble ".smali" and make new ".apk" in an Android application. I don't have so much time to do this so I have to use some source code that already exists.
There is an Apktool project which can build on Windows/Mac OS X/Linux, but I want to build it on Android.
I also tried to include the "apktool.jar" as an external library in an Android Application Project in Eclipse, but it failed.
After some research, it seems more clear that I need only the following two projects running on Android:
Smali (independent project)
JarSigner (from OpenJDK)
And, Apktool is not necessary.
This project has what I need:
https://code.google.com/p/java-ide-droid/
Requirements
JRE 1.6 (Java Runtime Environment)
aapt command in a PATH
basic knowledge of what is SDK, aapt, PATH, smali and Google search engine may be useful
This is from the apktools official website. Because it needs aapt, it seems quite hard to use apktools in an Android app. But if you can get the source code and compiled in an aosp environment, it could possibly make it run on the Android side.
Yes, there is a program also named apktool, but which runs on Android! Just have a look at http://code.google.com/p/apktool.
As of 2022, Yes there is a mobile version of Apktool, it is however not developed by iBotPeaches it's developed by Maximoff.
It's called Apktool M, you can grab the latest stable version from the link below.
https://maximoff.su/apktool/?lang=en
As far as stability goes it's definitely stable for Android 12 as far as I've tested.
Because I'm also a security freak, I ran it through about 7 different AV scanners to make sure I wasn't installing some hogwash virus masquerading as a legit app, and all of the scan results returned nothing malicious.
As far as usage goes it definitely decompiles APK's like Apktool as far as I've tested, however I don't expect it to work on every APK though.
According to the documentation,
Apktool M uses the following open source projects:
Apktool-android
aapt, aapt2
Commons IO
Apktool
antlr4
apksig
smali, baksmali, dexlib2
guava
jadx
textwarrior
axml
unapkm
imagetracerandroid
ZipAligner-for-Android
Dex2Jar_Android_2x
AndroidX
AndroidSVG
PhotoView

can i compile android project without eclipse?

Hello there is one question which comes in my mind from last 2 days. Can we compile our android project without Eclipse? If yes then what is alternatives? Please share it.
one option is ant, and an extremely reduced tutorial goes like this:
first update your project with a proper build script and all the files that ant needs, you can do that with just one command, for example
android update project -p . -t android-10
this command has many options, feel free to browse for those options.
after that just do
ant debug
or
ant release
depending on what you want to produce, again, ant has other variations and you can easily discover them with the Android docs.
If you are developing in a non-Eclipse environment, you can build your
project with the generated build.xml Ant file that is in the project
directory. The Ant file calls targets that automatically call the
build tools for you.
Look at Here for more details.
cd /path/to/my/app
ant release
it will ask you every time for your private key to sign the app, it can be configured to auto-sign by editing "build.properties" file:
key.store=release.keystore
key.alias=release
key.store.password=my_key_password
key.alias.password=my_key_password
you can also investigate Android SDK, find the ANT build scripts it actually uses, and insert your custom obfuscator/optimizer call in middle of build process.
For people that are not used to coding in java and want to use HTML/JavaScript and CSS to build native apps for android -- you can use PhoneGap -- you can upload your code in a zip and get an APK. Currently its in beta, and thats why free.
https://build.phonegap.com/
Other Phone OSes are also supported. Its pretty interesting.
You can use maven with the maven android plugin http://code.google.com/p/maven-android-plugin/. Afterwards you can use any IDE that supports maven (NetBeans, Eclipse, IntelliJ IDEA).
If you just do not want to use Eclipse IDE you can choose other IDE like IntelliJ IDEA.

Build/Package Android application with rake?

Is it possible to build an android application with rake? The only other question on this subject I saw was a while back and someone advised using Gradle.
So is there any way to do this on the command line, as I am sure under the hood eclipse just runs a lot of command line guff to get the apk file generated then spits it to the device, I just want to generate the apk file (there is alot of other things to be done but these are prior to the APK building).
Is it possible to build an android application with rake?
Yes, insofar as it is possible to build an Android application using Ant, and rake can in theory do everything Ant can.
If you are expecting to find an existing rake script, though, you will likely be disappointed. The Ant scripts necessary to build an Android app are rather substantial, and porting all of that to rake will take quite some time. And, then, they will perpetually be out of date, as those Ant scripts are often modified with Android tools releases.
Here's a small example project that's worth a look: https://github.com/jberkel/android-helloworld-rake
I've been meaning to try it out myself.

Is there a nice guide to making android apps by hand with just a text editor (e.g. no eclipse ide)?

I want to create apps manually. Using eclipse is the easy way. Using just a text editor is the hard way, but ensure I will know exactly what I'm doing, which is how I like to work.
Are there any good tutorials out there?
EDIT 3:31pm 10/17/2011: I realized what my question should have really been after googling around: Are there any good resources that describe the directory contents of an Android project in detail? The idea here is to be able to create them manually.
Google tells you all about how to manage things from the command line here. Pretty straight forward.
That said, I think I'd have to recommend against going low level here. I used emacs and ant for several months while learning/tinkering with android programming, but it wasn't really that helpful. The whole android system seems designed for use in an IDE: use of XML for layout, automatically generated values in R.java, a big API with many similar sounding names (layouts vs views, OnTouchListener vs OnClickListener), etc. I can't say I really started to get the big picture of the system until I could see it all organized for me. I'm still on the command line for a lot of C/C++, and even some Java stuff too, but all it did for android was cause frustration.
EDIT
Just saw your edit for the directory structure. Check here.
If you must...
First install ant, then assuming sdk/tools is in your $PATH:
android create-project -n projectname -t android-13 -k here.namespace.your -a MyActivity -p projectname
Where android-13 is an installed platform, run android list targets to see which platforms you have. Then run ant release or ant debug to build, or just ant to get a list of possible targets. When you're ready to test, run ant install to install it onto a running emulator or attached device.
See Tools in the dev guide.
Intel xdk. Do the whole app in html, css, php, and javascript. Inel xdk can build it in different platforms.(android, iphone, and windows.)
Yes, there is a way.
See this link:-
http://animeshrivastava.blogspot.in/2017/07/generate-android-app-apk-on-shell-or.html
I am attaching the relevant parts :-
Generation of Android app at command prompt of Windows will be as follows:
Install Java .Only install version 6 standard edition as it is small size compatible with Android.
Next install Android in folder.
Run Android package manager and put Android API level 23 platform tools for version 6 of Android lollipop in directory
.This will have a file Android.jar containing all class files as a library jar for making a DALVIK-EXECUTABLE file run and execute as app on Android lollipop mobile.
Set path environment variable in advance system settings of Windows. Include java-installation in path variable.
Lets use shortcut mypro for my project. Mypkg means my package. Make directory folder
Note that com.pkg is a package where dot or period separates com and pkg sub directories.
In case your package doesn't have this dot or period, then during compilation no error but when you install in mobile, it will say invalid
Now we generate R class for res directory.
enter code hereaapt p -S res -J ./com/pkg -I android.jar

Why we use build.xml in android?

I am android developer.I am not aware of ant in android .I have downloaded a code from internet But It has file called build.xml but I am not able to find out what it is doing and for what purpose it is used please give some advise or some kind of tutorial.So I can understand its working thanks in advance.
When you are developing your application, Eclipse is the most convenient way of building the project.
However Ant is most useful when you come to produce a release version. You can set up your Ant build, such that it takes the same source files as the Eclipse project, yet produces a signed, zip-aligned version of the apk in completely separate output location.
By means of a custom build.properties file you can specify source and output locations, keystore names and locations and passwords. It also takes care of any Proguard obfuscation you may want.You can do all this from the command line with a single statement and know that you are going through a repeatable process, not vulnerable to a mouse click in the wrong place.
Have a look at Managing Projects from the Command Line and Building and Running from the Command Line
Take the build.xml from the sample project referred to and use it as a basis for your own project. It works pretty much out of the box.
This build file is an alternative (and less common) way to build your projects using ant.
Eclipse (and the Android plugins) do a n excellent job of saving you the trouble - just use the plugin to build your projects and export APKs.

Categories

Resources