CubieBoard中文论坛

 找回密码
 立即注册
搜索
热搜: unable
查看: 8507|回复: 2

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

[复制链接]
发表于 2014-10-9 17:48:36 | 显示全部楼层 |阅读模式
平台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)

回复

使用道具 举报

发表于 2014-10-10 12:42:16 | 显示全部楼层
{:soso_e179:}{:soso_e179:}必须顶,楼主应该多放点出来,大家共同进步嘛。
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|Archiver|手机版|粤ICP备13051116号|cubie.cc---深刻的嵌入式技术讨论社区

GMT+8, 2024-12-22 09:53 , Processed in 0.019414 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2012 Comsenz Inc. | Style by Coxxs

返回顶部