安卓系统集成第三方apk

项目集成所需文件清单,需拷贝至ANDROID_SOURCE/packages/app/PROJECT_NAME/目录下

PROJECT_NAME
    │  Android.mk
    │  AndroidManifest.xml
    ├─libs[若包含jar包、静态库或动态库]
    ├─res
    └─src

 

src、res、AndroidManifest.xml皆为普通应用程序会包含内容(项目下gen文件夹不要放进源码,会报错)以下主要对Android.mk做说明。直接上mk内容:

 

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := testMid
LOCAL_CERTIFICATE := platform

include $(BUILD_PACKAGE)

 

 

 

1、外部jar包依赖

LOCAL_STATIC_JAVA_LIBRARIES := mirror androidsupport

include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := mirror:libs/mirrorcastandroid4.jar androidsupport:libs/android-support-v4.jar

LOCAL_MODULE_TAGS := optional
include $(BUILD_MULTI_PREBUILT)

 

2、依赖动态库

LOCAL_PREBUILT_LIBS :=libjpeg-turbo:libs/armeabi/libjpeg-turbo.so liblinkyuv:libs/armeabi/liblinkyuv.so

 

以上注意参数 LOCAL_MODULE_TAGS := optional 的值,optional直接make时不会将相应的.so输出至system/lib下,对应TARGET_BUILD_VARIANT=eng的值(TARGET_BUILD_VARIANT指定编译形成的版本风格,一般发布时使用这个值,当然还有user、debuguser等风格值),即会输出

 

编译eng[即debug]版本和user[即release]版本会存在差异,可能遇到如下错误

错误一:

 

build/core/base_rules.mk:64: *** Module name: libjpeg-turbo
build/core/base_rules.mk:65: *** Makefile location: packages/apps/*****/Android.mk
build/core/base_rules.mk:66: *
build/core/base_rules.mk:67: * Module is attempting to use the 'user' tag.  This
build/core/base_rules.mk:68: * used to cause the module to be installed automatically.
build/core/base_rules.mk:69: * Now, the module must be listed in the PRODUCT_PACKAGES
build/core/base_rules.mk:70: * section of a product makefile to have it installed.
build/core/base_rules.mk:71: *
build/core/base_rules.mk:72: *** user tag detected on module..  Stop.
 

 

如log输出详细所示,系统依赖库需要在PRODUCT_PACKAGES中作声明,即需修改build/target/product/generic_*.mk文件[generic_no_telephony.mk]

# my product apps
PRODUCT_PACKAGES += \
    libktuart \
    libBT \
    libOUT \
    libUpdate \    
    libjpeg-turbo

 

错误二:

Warning: library class android.util.Xml depends on program class org.xmlpull.v1.XmlPullParser
Warning: library class android.util.Xml depends on program class org.xmlpull.v1.XmlSerializer
Warning: library class android.util.Xml depends on program class org.xmlpull.v1.XmlPullParser
Note: there were 5 unresolved dynamic references to classes or interfaces.
      You should check if you need to specify additional program jars.
Note: there were 2 class casts of dynamically created class instances.
      You might consider explicitly keeping the mentioned classes and/or
      their implementations (using '-keep').
Note: there were 2 accesses to class members by means of introspection.
      You should consider explicitly keeping the mentioned class members
      (using '-keep' or '-keepclassmembers').
Warning: there were 78 instances of library classes depending on program classes.
         You must avoid such dependencies, since the program classes will
         be processed, while the library classes will remain unchanged.
Error: Please correct the above warnings first.
make: *** [out/target/common/obj/APPS/******_intermediates/proguard.classes.jar] Error 1
make: Leaving directory `/home/android'

 

错误二解决:

发生以上错误是由于编译release版本时默认会对所有应用程序进行混淆编译,某些文件所包含的警告信息不允许存在。可进行混淆配置,先修改Android.mk,可选择关掉系统对当前app的混淆,或自定义混淆配置文件proguard-project.txt

#LOCAL_PROGUARD_ENABLED := disabled
LOCAL_PROGUARD_FLAG_FILES := proguard-project.txt

 

proguard-project.txt文件内容

1、忽略警告提示。如项目工程内有加入安卓源码,并存在修改,如下

-dontwarn android.hardware.usb.**

2、部门java类不需要做混淆。如某些方法是native jni方法,或某些方法是给c层调用,无需做混淆:

-keep class com.test.TestNative{*;}

你可能感兴趣的:(安卓系统集成第三方apk)