极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4312|回复: 0

Android.mk中加入选项,编译生成可以直接安装的apk包

[复制链接]
发表于 2014-10-9 17:57:27 | 显示全部楼层 |阅读模式
平台ubuntu 64, 环境 android 4.0.3, 可以直接编译出可安装apk的Android.mk大致如下


LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

# We only want this apk build for tests.

LOCAL_MODULE_TAGS := eng

# 加入这个选项,避免生成odex文件
WITH_DEXPREOPT := false

LOCAL_STATIC_JAVA_LIBRARIES := libarity android-support-v4

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_SDK_VERSION := current

LOCAL_PACKAGE_NAME := kivi

include $(BUILD_PACKAGE)


在android里如何将一个应用的apk包编译到自己的系统里呢,我总结了一下三种方法,供大家参考:

方法一:


    LOCAL_PATH := $(call my-dir)   
    include $(CLEAR_VARS)   
    file := $(TARGET_OUT_APPS)/AppInstaller.apk   
    $(file) : $(LOCAL_PATH)/AppInstaller.apk | $(ACP)   
       $(transform-prebuilt-to-target)   
    ALL_PREBUILT += $(file)   


方法二:


      include$(CLEAR_VARS)  
      
      LOCAL_SRC_FILES:= AppInstaller.apk  
      
      LOCAL_BUILT_MODULE_STEM:= AppInstaller.apk  
      
      LOCAL_MODULE_SUFFIX:= .pak  
      
      LOCAL_MODULE:= AppInstaller  
      
      LOCAL_MODULE_CLASS:= APPS  
      
      LOCAL_CERTIFICATE:= paltform  
      
      include$(BUILD_PREBUILT)   


方法三:


    LOCAL_PATH:= $(call my-dir)   
                                                                                                                                                         
    include $(CLEAR_VARS)   
    LOCAL_MODULE := AppInstaller.apk   
    LOCAL_MODULE_TAGS := user   
    LOCAL_MODULE_CLASS := APPS   
    LOCAL_MODULE_PATH :=$(TARGET_OUT_APP)   
    LOCAL_SRC_FILES := $(LOCAL_MODULE)   
    LOCAL_CERTIFICATE := paltform   
      
    include $(BUILD_PREBUILT)  



如果你想了解Android.mk的更多内容请参考《Android.mk简介》
一、编译一个简单的APK
  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)
二、编译一个依赖静态.jar文件的APK
  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)
注:LOCAL_STATIC_JAVA_LIBRARIES 后面应是你的APK程序所需要的JAVA库的JAR文件名。
三、编译一个需要platform key签名的APK
  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)
注:LOCAL_CERTIFICATE 后面应该是签名文件的文件名
四、编译一个需要特殊vendor key签名的APK
  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)
五、装载一个普通的第三方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)
  LOCAL_CERTIFICATE := platform
  include $(BUILD_PREBUILT)
六、装载需要.so(动态库)的第三方apk
LOCAL_PATH := $(my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := baiduinput_android_v1.1_1000e
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := platform
include $(BUILD_PREBUILT)

#################################################################
####### copy the library to /system/lib #########################
#################################################################
include $(CLEAR_VARS)
LOCAL_MODULE := libinputcore.so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)
LOCAL_SRC_FILES := lib/$(LOCAL_MODULE)
OVERRIDE_BUILD_MODULE_PATH := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)
include $(BUILD_PREBUILT)
七、编译一个静态java库
  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)
注:LOCAL_JAVA_LIBRARIES表示生成的java库的jar文件名。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊 ( 浙ICP备09023225号 )

GMT+8, 2019-8-19 04:05 , Processed in 0.042670 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表