0
votes

I'm trying to build a project in system building environment. The project contains a library project which includes some resources. The codes in library project access these resources. The building failed by some errors. Here are the details:

The structure of the project is:

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 is the library project. In it, there is a CustomView.java access the string resource defined in strings.xml. The makefile for main project is:

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

And the makefile for library project is:

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))

The building command I used was:

mmm packages/experimental/MyApplication/

The building output are:

============================================
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'

If I comment out the codes that accessing the string resource, the building was successful. The proguard.flags I'm using just the default one. The system I ran the building is Ubuntu 14.04, and the source code is based on CM 10.2 (which equivalence to AOSP 4.3.1).

Updated:

The intermediate files of library project building are generated successfully. In the directory: out/target/common/obj/JAVA_LIBRARIES/mylibrary_intermediates/

1
It seems you're trying to use mylibrary before it has been built. Check the build orderChris Watts
How to see the build order? Could you give more instructions since I'm not very familiar with it. Thanks :)popo
I'm not familiar with Android Makefiles myself but make sure that the line include $(call all-makefiles-under,$(LOCAL_PATH)) is being executed before your project starts building. You need the library to be available to your main project before it tries to build.Chris Watts
well...I think the order should be correct, because I referenced a lot of makefile in the system to write my own. And in addition, this error only happens when CustomView access the string resource. If not, the building was successfully.popo
This is because the library you built won't be used until you try using the string functions it provides. The error you're seeing seems to be from just not being able to find the library - likely because it hasn't been compiled as intended.Chris Watts

1 Answers

0
votes

I solved the problem finally. The build scripts are OK, just because the intermediate files generated last time are not correct. After I deleted the folder "out/target/common/obj/APPS/MyApplication_intermediates/" and run the building again, it succeed.

By the way, for library contains and uses the resources. The key for the building is "LOCAL_AAPT_FLAGS := --extra-packages" which can combine the library jar & resources with the main project.