在包含资源的库项目上构建错误

时间:2016-07-08 16:55:13

标签: android makefile android-ndk android-source android-build

我试图在系统构建环境中构建项目。该项目包含一个包含一些资源的图书馆项目。库项目中的代码访问这些资源。建筑失败了一些错误。以下是详细信息:

项目的结构是:

packages/experimental/MyApplication/
  |--AndroidManifest.xml
  |--Android.mk
  |--proguard.flags
  |--libs/
  |--res/
  |--src/
  |--mylibrary/
  |    |--AndroidManifest.xml
  |    |--Android.mk
  |    |--libs/
  |    |--res/
  |    |    |--values/strings.xml
  |    |--src/
  |    |--  |--com/example/mytest/CustomView.java

mylibrary是图书馆项目。在其中,有一个CustomView.java访问strings.xml中定义的字符串资源。主项目的makefile是:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
mylib_dir := mylibrary/res
res_dir := $(mylib_dir) res

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dir))
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages com.example.popoalex.mylibrary

LOCAL_STATIC_JAVA_LIBRARIES := mylibrary okhttp

LOCAL_PACKAGE_NAME := MyApplication
#LOCAL_CERTIFICATE := platform
#LOCAL_PROGUARD_FLAG_FILES := proguard.flags

include $(BUILD_PACKAGE)
##################################################
include $(CLEAR_VARS)

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := okhttp:libs/okhttp-1.0.0.jar

include $(BUILD_MULTI_PREBUILT)

# only include rules to build other stuff for the original package, not the derived package.
ifeq ($(strip $(LOCAL_PACKAGE_OVERRIDES)),)
# Use the folloing include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
endif

库项目的makefile是:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := mylibrary
LOCAL_STATIC_JAVA_LIBRARIES := gson
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
include $(BUILD_STATIC_JAVA_LIBRARY)

##################################################

include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := gson:libs/gson-2.2.4.jar
include $(BUILD_MULTI_PREBUILT)

##################################################
# Build all sub-directories

include $(call all-makefiles-under,$(LOCAL_PATH))

我使用的构建命令是:

mmm packages/experimental/MyApplication/

建筑物输出是:

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.3.1
CM_VERSION=10.2-20160708-UNOFFICIAL-n8000
TARGET_PRODUCT=cm_n8000
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=cortex-a9
HOST_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.16.0-76-generic-x86_64-with-Ubuntu-14.04-trusty
HOST_BUILD_TYPE=release
BUILD_ID=JLS36I
OUT_DIR=/home/popoalex/Projects/cm/out
============================================
PRODUCT_COPY_FILES device/samsung/smdk4412-common/rootdir/init.trace.rc:root/init.trace.rc ignored.
PRODUCT_COPY_FILES device/samsung/smdk4412-common/configs/audio_effects.conf:system/etc/audio_effects.conf ignored.
PRODUCT_COPY_FILES device/samsung/n80xx-common/ueventd.smdk4x12.rc:root/ueventd.smdk4x12.rc ignored.
PRODUCT_COPY_FILES device/samsung/n80xx-common/ueventd.smdk4x12.rc:recovery/root/ueventd.smdk4x12.rc ignored.
PRODUCT_COPY_FILES device/samsung/n80xx-common/configs/audio_policy.conf:system/etc/audio_policy.conf ignored.
PRODUCT_COPY_FILES device/samsung/n8000/configs/gps.conf:system/etc/gps.conf ignored.
No private recovery resources for TARGET_DEVICE n8000
make: Entering directory `/home/popoalex/Projects/cm'
Proguard: /home/popoalex/Projects/cm/out/target/common/obj/APPS/MyApplication_intermediates/proguard.classes.jar
ProGuard, version 4.4
Reading program jar [/home/popoalex/Projects/cm/out/target/common/obj/APPS/MyApplication_intermediates/classes.jar]
Reading library jar [/home/popoalex/Projects/cm/out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes.jar]
Reading library jar [/home/popoalex/Projects/cm/out/target/common/obj/JAVA_LIBRARIES/core-junit_intermediates/classes.jar]
Reading library jar [/home/popoalex/Projects/cm/out/target/common/obj/JAVA_LIBRARIES/ext_intermediates/classes.jar]
Reading library jar [/home/popoalex/Projects/cm/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar]
Warning: com.example.popoalex.mylibrary.CustomView: can't find referenced class com.example.popoalex.mylibrary.R$string
Warning: com.example.popoalex.mylibrary.CustomView: can't find referenced class com.example.popoalex.mylibrary.R$string
Warning: com.example.popoalex.mylibrary.CustomView: can't find referenced class com.example.popoalex.mylibrary.R
Note: com.squareup.okhttp.internal.Platform accesses a method 'setHostname(java.lang.String)' dynamically
      Maybe this is library method 'gov.nist.core.Host { void setHostname(java.lang.String); }'
      Maybe this is library method 'org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl { void setHostname(java.lang.String); }'
Note: com.squareup.okhttp.internal.Platform accesses a method 'setNpnProtocols(byte[])' dynamically
      Maybe this is library method 'org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl { void setNpnProtocols(byte[]); }'
Note: com.squareup.okhttp.internal.Platform accesses a method 'getNpnSelectedProtocol()' dynamically
      Maybe this is library method 'org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl { byte[] getNpnSelectedProtocol(); }'
Note: com.squareup.okhttp.internal.Platform accesses a method 'get(javax.net.ssl.SSLSocket)' dynamically
Note: there were 4 accesses to class members by means of introspection.
      You should consider explicitly keeping the mentioned class members
      (using '-keep' or '-keepclassmembers').
Warning: there were 3 unresolved references to classes or interfaces.
         You may need to specify additional library jars (using '-libraryjars'),
         or perhaps the '-dontskipnonpubliclibraryclasses' option.
Error: Please correct the above warnings first.
make: *** [/home/popoalex/Projects/cm/out/target/common/obj/APPS/MyApplication_intermediates/proguard.classes.jar] Error 1
make: Leaving directory `/home/popoalex/Projects/cm'

如果我注释掉访问字符串资源的代码,则构建成功。我只使用默认的proguard.flags。我运行该系统的系统是Ubuntu 14.04,源代码基于CM 10.2(与AOSP 4.3.1等效)。

更新

成功生成了库项目构建的中间文件。在目录中:out / target / common / obj / JAVA_LIBRARIES / mylibrary_intermediates /

1 个答案:

答案 0 :(得分:0)

我终于解决了这个问题。构建脚本没问题,只是因为上次生成的中间文件不正确。删除文件夹“out / target / common / obj / APPS / MyApplication_intermediates /”并再次运行建筑物后,它就成功了。

顺便说一句,对于库包含和使用资源。建筑的关键是“LOCAL_AAPT_FLAGS:= --extra-packages”,它可以结合库jar和amp;主要项目的资源。