日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

Building Android App Without an IDE

發(fā)布時間:2025/3/15 Android 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Building Android App Without an IDE 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

UPDATE 2018-03-12:?“android create project” command is removed from newer sdk tools (since 25.3.0). But you still can download older sdk from these links:

  • http://dl-ssl.google.com/android/repository/tools_r[rev]-windows.zip
  • http://dl-ssl.google.com/android/repository/tools_r[rev]-linux.zip
  • http://dl-ssl.google.com/android/repository/tools_r[rev]-macosx.zip

where?[rev]?is the exact revision number such as?24,?25.2.5. Lookup the revision at?this page.


To build an?Android app, the recommended tool is?Android Studio. But I decided to do it without Android Studio nor Eclipse. I did this, to understand how Android app works and because I prefer command line over heavy IDEs. I have to admit though, that you will need an IDE to build a serious app. In this article, I will walk through how to build a simple Android App?from command line. The app will have?proguard?enabled, and use?JNI?feature.

This tutorial is tested only in Ubuntu 14.04 LTS x86_64.

1. Install tools

1.1. Requirements

JDK?and?Ant?are required.

sudo apt-get install openjdk-7-jdk ant

If your system is 64-bit Ubuntu, install these:

sudo apt-get install lib32z-dev lib32stdc++6

1.2. Download Android SDK

From?official download page, download?“SDK Tools Only”?version. Then uncompress the file. Then add?<uncompressed_dir>/tools/?and?<uncompressed_dir>/platform-tools/?to your?PATH.

1.3. Install Android SDK Packages

Android SDK itself is not enough to build an app. You have to install following additional SDK elements using SDK manager.

  • tools
  • platform-tools
  • build-tools (latest version)
  • SDK platform (API version you want to use)

First query available packages with following command.

android list sdk --no-ui --all --extended

Then install(update) the tools.

android update sdk --no-ui --all --filter tools,platform-tools,build-tools-23.0.2,android-23

2. Building an App

2.1. Create an Empty Android Project

First you check which targets (API version) are available using this command

$ android list targets

Then create an empty Android project

android create project \--target <target id> \--name <app name> \--path <project root> \--activity <default activity name> \--package <package name>

For example,

android create project --target 1 --name HelloApp --path ./helloapp \--activity MainActivity --package com.example.helloapp

Then initial files will be created under?helloapp?directory.

2.2. Build the app

Now auto-generate?build.xml.

cd helloapp android update project --path .

Then build the app using Ant.

ant release

The app will be created at?bin/HelloApp-release-unsigned.apk.

You can clean the build using

ant clean

2.3. Sign the app

Only signed app can be installed in an Android device. You can sign an apk with your own keystore. If you don’t have a keystore, here’s how to make one.

keytool -genkey -v \-keystore mykey.keystore \-alias mykeyname \-keyalg RSA -keysize 2048 \-validity 365

It will ask you a?keystore password, your information (optional) and the?alias password?you provided. (A?keystore?can hold multiple entries and each entry is called?alias. This is why it asks for two passwords.) After it’s done,?mykey.keystore?file will be created. Keep this keystore file somewhere safe.

Then add these lines to?ant.properties?file.

key.store=<keystore file location> key.alias=<alias name> key.store.password=<keystore password> key.alias.password=<alias password>

Now?ant release?command will sign the app. The signed app will be produced as?bin/HelloApp-release.apk.

2.4. Install and run the app

Move?bin/HelloApp-release.apk?to your Android machine or a virtual device, then install it. It may have to enable “Allow installation of apps from unknown source” option. Enjoy your hello world!

3. Enabling ProGuard

ProGuard is an Android obfuscation & minification tool. If an app is filtered through ProGuard, then method names and class names will change into something like a, b, c, …. It makes reverse engineers’ life difficult.

Turning on ProGuard is simple. Uncomment following line in?project.properties

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

That’s it. Now?ant release?will apply ProGuard.

4. Using JNI

JNI(Java Native Interface) allows calling native programs directly from Java code. For example, you can call C function just like a Java method. You can use JNI feature using Android NDK(Native Development Kit).

4.1. Download NDK

Download NDK?here?and uncompress it. Add the uncompressed directory to your?PATH.

4.2. Write code and configs

Write this into?jni/Android.mk

LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := hello-jni LOCAL_SRC_FILES := hello-jni.c include $(BUILD_SHARED_LIBRARY)

Write this into?jni/Application.mk

APP_ABI := all

Write this into?jni/hello-jni.c

#include <string.h> #include <jni.h>jstring Java_com_example_myapp_HelloActivity_helloJni(JNIEnv* env, jobject thiz) {return (*env)->NewStringUTF(env, "Hello!!"); }

Modify?src/com/example/helloapp/MainActivity.java

// ... public class MainActivity extends Activity {static {System.loadLibrary("hello-jni");}public native String helloJni();// ... }

4.3. Build native library

Then at the project root,

ndk-build

Shared library (*.so) files for each architecture should be created at?libs/. Then package the app.

ant release

References

  • https://developer.android.com/studio/tools/help/android.html
  • http://eqdn.tech/android-development-on-the-command-line/
  • https://stackoverflow.com/a/46994747/8939955
  • https://stackoverflow.com/a/27043655/8939955

https://blukat29.github.io/2016/03/building-android-app-without-an-ide/

與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的Building Android App Without an IDE的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。