Build Android APK programmatically - android

I need to build a web environment which creates signed Android .apk files from a given Android application source code. How can I get this? The web environment will be running on a Linux machine.
I was thinking on a Linux shell script which builds signed .apk file. However, I've read some information about Apache Ant but I don't understand exactly its purpose and if it could do the trick.

Related

How can I sign Android application with AOSP certificate

The context of my issue is the following:
I build AOSP for our hardware device on Linux
Together with the system, I build an APK as a system application
Everything works fine in this setup when I flesh it together with system image
However, I would like to have this application build separated from the AOSP build and be able to build it standalone and install from Windows.
On windows, I am trying to build it with Gradle
And the problem arises when I try to push the build to the device the following way:
adb install -r my_app.apk
adb: failed to install my_app.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package <...> signatures do not match the previously installed version; ignoring!]
Obviously the error means that I am missing a platform signature in the application, but where to take it from the AOSP build and how to sign it with Gradle build is not so clear.
Also here I found an advice to uninstall the system app first before installing. Unfortunately, for my case it does not help, the error is still the same even I uninstall it first.
I already spend quite some time on this, searching in the Android make-files for the signing script, but it seems to be not that straight forward there.
Any help would be highly appreciated...
Create a keystore from platform.x509.pem and platform.pk8 files located in build/target/product/security. Then use that with gradle.
See this answer for how to do the conversion: https://stackoverflow.com/a/22214826/3801327
Note: Don't use the default keys included with AOSP, everyone has those, and would be able to make their app a system app in your platform. Generate your own keys.

Generate apk file from playground online

I have written a small test app on nativescript playground online, and I want .apk file of it. Is there any online tool to generate .apk file from playground, instead of having to install tns and run 'tns run'/'tns debug'/'tns build' on my local machine ?
No, it's not possible to generate APK from Playground.
If you don't want to setup Android SDK locally, you may try cloud build option but at least that requires NativeScript CLI / Sidekick setup on your local machine.

Phonegap remote build

I'm developing app in Sencha touch(Touch 2.4 && CMD 5) and packaging using Phonegap/Cordova for Android and iOS. I'm developing on windows machine with Android device(HTC) and iOS device(iPhone 5).
Initially i packaged the app with cordova, and with limitation of iOS build i keep working for Android build only. I added 5 plugins (Facebook, Network Information, Camera, FIle Transfer, Email Composer) using cordova and all working fine for android build. My latest Android apk file size is 3.8 MB.
Now i need to build iOS ipa as well, so i opted "Phonegap Remote Build Service" option. I clone my Sencha touch project and packaged it to Phonegap, added all plugins, mention the iOS platform in app.json and set remote true and add local.properties file with email and password set of paid adobe phonegap account. When i execute command "sencha app build native" , it did everything right but gave error of "Invalid email or password". Then i went for other option, i made zip file of phonegap folder and uploaded manually, and build on Adobe Phonegap Build portal, it provided me both the builds but with one big issue of huge size. Both files(apk, ipa) reached 37-40 MB.
Now i need help of different options which i can take(Other than iOS machine), how i can minimize the size of files. As locally cordova packaging providing me very lightweight apk file. If I'm doing something wrong in Phonegap packaging, please mention it.
Thanx in advance.
When you say manuall upload turns zip size to 37 - 40 MB ,i think it must contain library folder as well .
for Invalid email or password : - there must be some typo mistake only this is possible scenario i could think off.
Thanks

Building an Android APK with same certificate as the system

I'm trying to make a system app work. Here's what I have:
An OEM OMAP platform with full 4.4.2 source code. I've built the system and loaded on my platform using Ubuntu 14.04. That all works.
Now, there is an app from the OEM which directly accesses the hardware (DSP, I2C, UART) etc. The original APK that came from the OEM works on my platform.
I built the exact same app using make command (not using Eclipse); It builds and I can install on the platform. But when I try to launch the app, it gets stuck in an eternal wait state.
I am not sure, but I suspect my locally built app tries to initialize a hardware component on the board and then gets blocked there.
I've been reading articles all over, and seems like it has something to do with the app signing and certificate. I think the general idea is the app needs to be signed with the same certificate with the system itself. I thought, since I built both the app and the system on the same machine using same commands, they would have a same certificate.
If it helps, the manifest file has this line:
android:sharedUserId="android.uid.system"
And the project make file Android.mk has this line:
LOCAL_CERTIFICATE := platform
Can anyone show me how can I make the app work? I am not sure, seems like I have to rebuild the app with proper certificates so that it can access all the hardware resources.
Thanks.
Check signing system apk.
Optionally:
You need to create a keystore file by using keytool-importkeypair which you can find here.
Go into the: build/target/product/security/ directory in your platform source tree (source codes related to your Android version and vendor).
You will find platform.pk8 and platform.x509.pem files.
Create keystore file by using this example command:
keytool-importkeypair -k ~/.android/debug.keystore -p android -pk8 platform.pk8 -cert platform.x509.pem -alias platform
You can use this keystore file to sign your apk which will have system permissions afterwards.

Building the apk using the ant script .

I am facing problem in creating the .apk file using the ant script . The generated .apk named as _unaligned.apk instead of .apk and on installing the _unaligned.apk file to the device I get force-close showing the java.lang.VerifyError exception, but the same apk generated using IDE works fine. I am struck on this for a long time. Can you share the build.xml file that generates the .apk file?
this Bloq entry explains all necessary steps. Especially if you want to customize your build script.
If your are looking for the actual build script, just look into your Android SDK folder platforms/android-X/templates. There should be a file called android_rules.xml.
I customized my build script to clean, build, sign and distributing the apk to an attached device. If you like, I can provide you with my script. Just contact me!
You'll need to use zipalign & sign your apk with some key; as long as you're testing the app you can simply use the debug key with ant debug
At least that's what I understand from this page which you may want to read carefully.
What ant command are you running at the command / terminal prompt?
I have been having different problems with manually running ant (Repackage apk file to contain custom assets what build tool to use) and there might be some info on that thread to help you.
Alternatively, remember that one needs to sign the apk file before deploying it (see Joubarc's link).

Categories

Resources