【发布时间】:2016-07-08 16:55:13
【问题描述】:
我正在尝试在系统构建环境中构建一个项目。该项目包含一个包含一些资源的库项目。图书馆项目中的代码访问这些资源。该建筑因一些错误而失败。以下是详细信息:
项目的结构是:
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/
【问题讨论】:
-
您似乎在尝试使用
mylibrary在它构建之前。检查构建顺序 -
如何查看构建顺序?由于我不是很熟悉,您能否提供更多说明。谢谢:)
-
我自己对 Android Makefile 并不熟悉,但请确保在您的项目开始构建之前 执行
include $(call all-makefiles-under,$(LOCAL_PATH))行。在尝试构建之前,您需要该库可用于您的主项目。 -
嗯...我觉得顺序应该是正确的,因为我在系统中引用了很多makefile来编写自己的。另外,这个错误只有在CustomView访问字符串资源时才会发生。如果没有,则构建成功。
-
这是因为在您尝试使用它提供的字符串函数之前,您构建的库不会被使用。您看到的错误似乎只是无法找到该库 - 可能是因为它没有按预期编译。
标签: android makefile android-ndk android-source android-build