Adding Android APK packages

From Variscite Wiki
Revision as of 19:43, 21 September 2023 by Harshesh (talk | contribs) (→‎Android Build Process)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
DART-MX8M - Android O8.1.0_1.3.0 Adding Android APK to AOSP Build

Android Build Process

The Android Build Cookbook offers code snippets to help you quickly implement some common build tasks. For additional instruction, please see the other build documents in this section. Change to Android top-level directory.

$ cd ~/var_imx-o8.1.0_1.3.0_8m/android_build
$ source build/envsetup.sh
$ lunch dart_mx8m-userdebug
or
$ lunch dart_mx8m-user

Note: dart_mx8m-user : creates an release production of Android.
     where development mode is enabled but some tools are not available on the target.
     dart_mx8m-userdebug: creates a debuggable version of Android.
     Development mode enables and development tools are available on the target.


Create your folder containing the source code:

$ mkdir -p ~/var_imx-o8.1.0_1.3.0_8m/android_build/packages/app/<_your_app_folder_>
  • Note: Please change <_your_app_folder_> to some meaning ful package name.

Building a simple APK

Snippet:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
  
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
 
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
  
# Tell it to build an APK
include $(BUILD_PACKAGE)
 
 

Building a APK that depends on a static .jar file

Snippet:

 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
  
 # List of static libraries to include in the package
 LOCAL_STATIC_JAVA_LIBRARIES := static-library
  
 # Build all java files in the java subdirectory
 LOCAL_SRC_FILES := $(call all-subdir-java-files)
  
 # Name of the APK to build
 LOCAL_PACKAGE_NAME := LocalPackage
  
 # Tell it to build an APK
 include $(BUILD_PACKAGE)
 

Building a APK that should be signed with the platform key

 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
  
 # Build all java files in the java subdirectory
 LOCAL_SRC_FILES := $(call all-subdir-java-files)
  
 # Name of the APK to build
 LOCAL_PACKAGE_NAME := LocalPackage
  
 LOCAL_CERTIFICATE := platform
  
 # Tell it to build an APK
 include $(BUILD_PACKAGE)

Building a APK that should be signed with a specific vendor key

 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
  
 # Build all java files in the java subdirectory
 LOCAL_SRC_FILES := $(call all-subdir-java-files)
  
 # Name of the APK to build
 LOCAL_PACKAGE_NAME := LocalPackage
  
 LOCAL_CERTIFICATE := vendor/example/certs/app
  
 # Tell it to build an APK
 include $(BUILD_PACKAGE)
 
 

Adding a prebuilt APK

 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
  
 # Module name should match apk name to be installed.
 LOCAL_MODULE := LocalModuleName
 LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
 LOCAL_MODULE_CLASS := APPS
 LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
  
 include $(BUILD_PREBUILT)
 
 

Adding a Static Java Library

 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
  
 # Build all java files in the java subdirectory
 LOCAL_SRC_FILES := $(call all-subdir-java-files)
  
 # Any libraries that this library depends on
 LOCAL_JAVA_LIBRARIES := android.test.runner
  
 # The name of the jar file to create
 LOCAL_MODULE := sample
  
 # Build a static jar file.
 include $(BUILD_STATIC_JAVA_LIBRARY)


Verify that it can build

$ mm

If build works, it should get built.

Adding Apk to the Android Images

added the following instruction in device/variscite/imx8/dart_mx8m.mk:

PRODUCT_PACKAGES += \
LocalModuleName
  • Note: You need to change LocalModuleName to your package name as per Android.mk.