I am able to compile and execute Trade Federation test cases which are located inside /tools/tradefederation/core/tests. But how can I execute the test cases which are located inside my project? My Unit and Instrumentation test cases are located inside /vendor/xyz/packages/apps/MyApp/test folder. How can I build Trade Federation inside this folder and run my test cases? Any help regarding this is appreciated.
Since I couldn't get an answer from others, I did little research and managed to solve it myself. I built my project main classes and test classes into a separate jar file which has the reference to all its dependencies. Then I put it inside out/host/linux-x86/tradefed folder so that tradefed can detect my tests. Then I executed them from the terminal after building tradefed. Below Android.mk file will generate the jar file and copy it to tradefed folder,
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_JAVA_LIBRARIES := \
android-support-v13 \
android-support-v4
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, res)
LOCAL_PACKAGE_NAME:= MyUTSampleApp
LOCAL_CERTIFICATE := platform
LOCAL_DEX_PREOPT := false
include $(BUILD_PACKAGE)
# To include test folder.
#include $(call all-makefiles-under,$(LOCAL_PATH))
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under, test)
LOCAL_MODULE := sample-tests
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_JAVA_LIBRARIES := mockito-host junit-host android-support-test MyUTSampleApp android_stubs_current
#LOCAL_JAVA_LIBRARIES := tradefed host-libprotobuf-java-full
LOCAL_JAR_MANIFEST := MANIFEST.mf
include $(BUILD_HOST_JAVA_LIBRARY)
# makefile rules to copy jars to HOST_OUT/tradefed
# so tradefed.sh can automatically add to classpath
DEST_JAR := $(HOST_OUT)/tradefed/$(LOCAL_MODULE).jar
$(DEST_JAR): $(LOCAL_BUILT_MODULE)
$(copy-file-to-new-target)
$(LOCAL_INSTALLED_MODULE) : $(DEST_JAR)
And you can use another shell script file to execute the test cases like this,
TEST_CLASS="com.example.myutsampleapp.LocalManagerTest"
FORWARDED_ARGS=()
while [[ $# -gt 0 ]]; do
next="$1"
case ${next} in
--class)
TEST_CLASS="$2"
shift
;;
*)
FORWARDED_ARGS+=("$1")
;;
esac
shift
done
/home/bsherif/workspace/source/tools/tradefederation/core/tradefed.sh run singleCommand host -n \
--console-result-reporter:suppress-passed-tests \
--class ${TEST_CLASS} ${FORWARDED_ARGS[*]}
Related
I'm trying to build my java based android app through building as a module inside AOSP source. My app uses android.support.constraint.ConstraintLayout. But, I didn't find a direct way to include constraint-layout dependency in my Android.mk.
I've put my project under AOSP_ROOT/packages/apps and tried with this Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_PRIVILEGED_MODULE := true
LOCAL_PACKAGE_NAME := MyApp
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_SRC_FILES := $(call all-java-files-under, java)
LOCAL_MANIFEST_FILE := AndroidManifest.xml
LOCAL_AAPT_FLAGS := \
--auto-add-overlay \
--extra-packages android.support.constraint
LOCAL_STATIC_JAVA_LIBRARIES := \
android-common \
android-support-v4 \
android-support-constraint-layout-solver
LOCAL_STATIC_JAVA_AAR_LIBRARIES := \
android-support-constraint-layout
include $(BUILD_PACKAGE)
But, this comes up with build error:
ninja: error: 'out/target/common/obj/JAVA_LIBRARIES/android-support-constraint-layout_intermediates/aar/classes.jar', needed by 'out/target/common/obj/APPS/MyApp_intermediates/AndroidManifest.xml', missing and no known rule to make it
20:57:54 ninja failed with: exit status 1
What I understand - it is searching for classes.jar which could be built from .aar file, but it is missing. However, the answer here solves the issue: How to include constraint layout library in an AOSP project
But, the problem is, that answer suggests to add external constraint-layout.aar and constraint-layout-solver.jar within my project libs directory.
My question, is it possible to add constraint-layout support in my project using built-in library inside AOSP without adding external .aar and .jar to my project?
Anyways, I've found the solution. There is no need to include the constraint-layout in the project libs as extra library.
To solve the issue, in Android.mk we need to add one extra line:
LOCAL_USE_AAPT2 := true
And also use LOCAL_STATIC_ANDROID_LIBRARIES instead of LOCAL_STATIC_JAVA_AAR_LIBRARIES.
This is the working Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_PRIVILEGED_MODULE := true
LOCAL_PACKAGE_NAME := MyApp
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_USE_AAPT2 := true
LOCAL_SRC_FILES := $(call all-java-files-under, java)
LOCAL_MANIFEST_FILE := AndroidManifest.xml
LOCAL_AAPT_FLAGS := \
--auto-add-overlay \
--extra-packages android.support.constraint
LOCAL_STATIC_ANDROID_LIBRARIES:= \
android-support-constraint-layout
LOCAL_STATIC_JAVA_LIBRARIES := \
android-common \
android-support-v4 \
android-support-constraint-layout-solver
include $(BUILD_PACKAGE)
I am having issues creating a Android prebuilt shared library. In hope of figuring out what I'm doing wrong, I followed Google's example where I found the source for this example in the android-8.1.0_r52 tree at development/ndk/tests/prebuilt-library/jni.
Here's how I configure the ASOP
$ . build/envsetup.sh
$ lunch (I selected 29 aosp_bullhead_userdebug)
Then in the above jni folder I issued "$ mm"
The error I get is (which is the same is my other project)
ninja: error: 'out/target/product/bullhead/obj/SHARED_LIBRARIES/foo-prebuilt_intermediates/export_includes', needed by 'out/target/product/bullhead/obj/SHARED_LIBRARIES/foo-user_intermediates/import_includes', missing and no known rule to make it
When I grep the out/target/products/bullhead folder for "foo" I get nothing.
I also tried replacing
include $(PREBUILT_SHARED_LIBRARY)
with
include $(BUILD_PREBUILT)
and get the same error, but "obj" is replaced with "obj_arm".
Below is the stock Android.mk that comes with the tree.
LOCAL_PATH := $(call my-dir)
# Define BUILD_FOO=1 to rebuild libfoo.so from scratch, then
# copy obj/local/armeabi/libfoo.so to jni/libfoo.so
#
ifneq ($(BUILD_FOO),)
include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := foo/foo.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/foo
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/foo
include $(BUILD_SHARED_LIBRARY)
else # not build libfoo.so, trying to use PREBUILT_SHARED_LIBRARY instead.
# Note: the module is named foo-prebuilt, but the library is libfool.so !
#
include $(CLEAR_VARS)
LOCAL_MODULE := foo-prebuilt
LOCAL_SRC_FILES := libfoo.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/foo
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := foo-user
LOCAL_SRC_FILES := foo-user.c
LOCAL_SHARED_LIBRARIES := foo-prebuilt
include $(BUILD_SHARED_LIBRARY)
endif
This is the jni/ directory structure
jni/
Android.mk
foo-user.c
libfoo.so
foo/
foo.c
foo.h
I'm building a custom ROM and would like to include a simple launcher I built as a system app. Here is my Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# General
LOCAL_PACKAGE_NAME := Tott
LOCAL_SDK_VERSION := current
LOCAL_MODULE_TAGS := optional
LOCAL_PROGUARD_ENABLED := disabled
# To make system app
LOCAL_CERTIFICATE := platform
LOCAL_UNINSTALLABLE_MODULE := true
LOCAL_PRIVILEGED_MODULE := true
LOCAL_OVERRIDES_PACKAGES := Home Launcher2 Launcher3
# src/res files
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
# libraries
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v7-appcompat
#flags
LOCAL_AAPT_FLAGS := \
--auto-add-overlay \
--extra-packages android.support.v7.appcompat
include $(BUILD_PACKAGE)
I have placed the Android.mk, AndroidManifest.xml, res folder, and src (containing java) in a directory called Tott which has been placed in [source]/packages/apps. I've also added Tott to PRODUCT_PACKAGES at [source]/build/target/product/core.mk
When I build the android system.img, it says that that it is including [source]/packages/apps/Tott/Android.mk in terminal but my app never shows in [source]/out/target/product/vender/system/app or priv-app. I'm also able to build my app successfully by simply running make Tott at [source].
What am I doing wrong here????
Thanks
Comment out LOCAL_SDK_VERSION and LOCAL_UNINSTALLABLE_MODULE. I don't use those in my Android.mk files and I never have a problem.
I'm trying to learn how to compile an app in android source. The app is just a simple hello world application. I followed instructions from Making an app in the Android Source compile into system/app instead of data/app? and a couple of other sources. But when I make the application the apk file is written to obj/APPS with suffix intermediates instead of system/app and fails to show up in the emulator when I boot up. Please find below the Android.mk file.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := tests
LOCAL_MODULE_PATH := system/app
LOCAL_UNINSTALLABLE_MODULE := true
LOCAL_SDK_VERSION := current
LOCAL_PACKAGE_NAME := MyApplication
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-appcompat
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-gridlayout
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v13
LOCAL_STATIC_JAVA_LIBRARIES += android-support-design
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/appcompat/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/gridlayout/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/design/res
LOCAL_CERTIFICATE := platform
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat:android.support.v7.gridlayout
include $(BUILD_PACKAGE)
##################################################
include $(CLEAR_VARS)
include $(BUILD_MULTI_PREBUILT)
# Use the following include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
I make the application by going to the application directory in packages/apps and doing 'mm'. Is there anything I'm missing here?
Find out the BoardConfig.mk and add this :
PRODUCT_PACKAGES += MyApplication
AOSP build system will build every Android.mk, but only packages defined in BoardConfig will be put into the final product path.
you have to add the app module into the PRODUCT_PACKAGE from the devices/"your preferred vendor"/"device_name"/aosp_"device Name".mk file
It should look something like the following
$(call inherit-product, device/lge/hammerhead/full_hammerhead.mk)
PRODUCT_NAME := aosp_hammerhead
PRODUCT_PACKAGES += \
Launcher3 \
MyApplication \
It has little bit changed. Aosp checks /device/"vendor"/"your_device"/"your_platform"/base.mk file for compiling and /device/"vendor"/"your_device"/common/base.mk for installing apk to /out/target/product/"your_device/system/app/"
You should add your app name to both files.
In my case; aosp/device/qcom/qssi/base.mk to compile,
aosp/device/qcom/common/base.mk to install output(apk) to /out/target/product/msm8953/system/app/
I want to add some features into Browser app by start an activity from another android application. It gives me package does not exist while I make the Main Project. Notice that I see the AndroidLib is built successfully into an out/target/product/generic/data/app/AndroidLib.apk
Here are two android.mk files:
AndroidLib(a normal Android App)
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_STATIC_JAVA_LIBRARIES := \
google-ps \
android-support-v4 \
LOCAL_SRC_FILES := \
$(call all-java-files-under, src) \
LOCAL_MODULE := AndroidLib
LOCAL_PACKAGE_NAME := AndroidLib
LOCAL_MODULE_TAGS := tests
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := google-ps:libs/google-play-services.jar
include $(BUILD_PACKAGE)
# additionally, build tests in sub-folders in a separate .apk
include $(call all-makefiles-under,$(LOCAL_PATH))
Browser App
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_JAVA_LIBRARIES := \
android-common \
guava \
android-support-v13 \
android-support-v4 \
LOCAL_SRC_FILES := \
$(call all-java-files-under, src) \
src/com/android/browser/EventLogTags.logtags
LOCAL_PACKAGE_NAME := Browser
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
LOCAL_EMMA_COVERAGE_FILTER := *,-com.android.common.*
# We need the sound recorder for the Media Capture API.
LOCAL_REQUIRED_MODULES := SoundRecorder, AndroidLib
include $(BUILD_PACKAGE)
# additionally, build tests in sub-folders in a separate .apk
include $(call all-makefiles-under,$(LOCAL_PATH))
Then I do:
make -j Browser
It gives me:
packages/apps/Browser/src/com/android/browser/BrowserActivity.java:36: package com.om.AndroidLib does not exist
import com.om.AndroidLib.MainActivity;
Update
Essentially your problem is that the line:
LOCAL_REQUIRED_MODULES := SoundRecorder, AndroidLib
Tells the Android build that your Browser depends on AndroidLib being built first, however it will not be linked to AndroidLib in any way. To do that you need:
LOCAL_JAVA_LIBRARIES := AndroidLib
Except that requires the AndroidLib to be a java library project, using the build type:
include $(BUILD_JAVA_LIBRARY)
And java libraries cannot include resources, unfortunately. And there is no way to link one app to another app in the Android build system.
We are working around that issue frequently, and it is frankly a bit of a mess to do so. But the only workaround we have found is to include all the resources directly in the apps that use those resources. Sorry.
How to make your AndroidLib a java library and link to it
Your android lib should probably be built as a java library, and not as a app package.
So instead of:
include $(BUILD_PACKAGE)
You should probably do:
include $(BUILD_JAVA_LIBRARY)
Then you lib will be placed in out/target/product/generic/system/framework/AndroidLib.jar along with the other system libs.
Also you do not need a LOCAL_MODULE_NAME for a lib, it is only applicable for an app. So strip that.
And you should probably consider changing your LOCAL_MODULE_TAGS to:
LOCAL_MODULE_TAGS := user
tests indicates that you lib should only be built for testing, user says to build you lib for all user builds (and implicitly also for engineering builds)
In you app Android.mk you should then add a line:
LOCAL_JAVA_LIBRARIES := AndroidLib
Such that your app will be built with AndroidLib in the classpath.
In you apps AndroidManifest.xml you also need to put a uses library in the application tag:
<uses-library android:name="AndroidLib" />
And last you need to create a permissions xml file, with the following content:
<?xml version="1.0" encoding="utf-8"?>
<permissions>
<library name="AndroidLib"
file="/system/framework/AndroidLib.jar"/>
</permissions>
And update your product configuration file such that the xml file will be deployed to target:
PRODUCT_COPY_FILES += device/XXX/libs/AndroidLib.xml:system/etc/permissions/AndroidLib.xml
Replace device/XXX/libs/ with the path to the permissions xml file.
This is how we add and use an Android library in our Android builds. I hope it helps. :)
I know I'm digging this out of the grave a little bit, but there was never really an answer for how to actually include an Android Library Project (or other apk with resources) within an AOSP built application.
Here is what I have done with two projects. "main" is the main application I am building the apk for. "util" is a utility library with resources I am linking against. Both of the projects reside in external/seabold/{package}:
Android.mk in seabold/
LOCAL_PATH := $(call my-dir)
UTIL_PATH := $(LOCAL_PATH)/util
UTIL_JAVA_SRC := $(call all-java-files-under, util/src)
#Filter out if the util library isn't present
UTIL_RES_DIR := $(wildcard $(UTIL_PATH)/res)
include $(call all-subdir-makefiles)
Android.mk in seabold/main/
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := main
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src)
#Since the BUILD_PACKAGE makefile expects java files to be relative paths,
#we need to add the ../ in front of each file (which is stored as relative
#to seabold/
LOCAL_SRC_FILES += $(patsubst %.java,../%.java,$(UTIL_JAVA_SRC))
#Make sure both packages' resources are included
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res $(UTIL_RES_DIR)
#Since we are including resouces for two packages (This app and the util lib),
#we need to tell aapt to generate an R.java for the util package as well
LOCAL_AAPT_FLAGS := --generate-dependencies --extra-packages com.seabold.util --auto-add-overlay
include $(BUILD_PACKAGE)
Be careful here to make sure you fiddle with the filenames correctly. For me, the files defined in UTIL_JAVA_SRC are in the form of util/src/com/seabold/util/*.java. Since, the build script for the main app expects java files to be relative paths to the location of Android.mk, I'm adding a ../ to properly get to the util library's path.
The key for resources is the LOCAL_AAPT_FLAGS. This tells the resource packager to make sure it generates an R.java for the package in the utility library. Without this, all of the utility's resources will get put into the main applications R.java, and the utility classes will fail to compile because its R.java will be missing.
To add a pre-build jar file to the framework I did that:
Locate a folder with the jar and the Android.mk file under
prebuilds/misc/common/
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := <jar name>
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := <jar name>.jar
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_MODULE_SUFFIX := $(COMMON_JAVA_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
Run make on the Android.mk file: make prebuilds/misc/common/Android.mk
Add the jar file to the frameworks/base/services/Android.mk:
LOCAL_STATIC_JAVA_LIBRARIES := $(addprefix services.,$(services)) jar-name
I've stumbled over a solution, on how a java library can access resources. The resources are build as a separate apk. The jar-lib can be used from any app that says so in its Manifest. The java-library-code has the R.java of the resources-apk and uses createPackageContext() to gain access to the actual resources. createPackageContext() gets the app-context as parameter which each app must provide whenever it uses a java-lib-function that needs access to the resources.
I'm not that deep into the AOSP-build-system yet, so I'm hoping what I document here makes sense. It's not my solution either, I just improoved on something that some other developer created here at my job so I don't know where he got the approach from.
for the resource-only-apk we have:
Android.mk
include $(CLEAR_VARS)
LOCAL_PATH := $(call my-dir)
LOCAL_PACKAGE_NAME := shared-resources
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_APPS)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
include $(BUILD_PACKAGE)
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.company.common.resources">
<application android:hasCode="false"/>
</manifest>
For the jar-lib we have:
Android.mk
LOCAL_PATH:= $(call my-dir)
####################
# compile the jar #
include $(CLEAR_VARS)
LOCAL_MODULE := helper-lib
LOCAL_SRC_FILES := $(call all-java-files-under, src)
# add package-context-ressources
resource-intermediates := $(call intermediates-dir-for,APPS,shared-resources,,common)
shared_res := $(resource-intermediates)/src/my/company/common/resources/R.java
$(shared_res): $(resource-intermediates)/src/R.stamp
LOCAL_GENERATED_SOURCES := $(shared_res)
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_JAVA_LIBRARIES)
LOCAL_ADDITIONAL_DEPENDENCIES := helper-lib.xml
include $(BUILD_JAVA_LIBRARY)
######################
# deliver permisions #
include $(CLEAR_VARS)
LOCAL_MODULE := helper-lib.xml
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT)/etc/permissions
LOCAL_SRC_FILES := helper-lib.xml
include $(BUILD_PREBUILT)
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.company.helper">
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
<uses-permission android:name="android.permission.MANAGE_USERS" />
<application />
</manifest>
helper-lib.xml
<?xml version="1.0" encoding="utf-8"?>
<permissions>
<library name="helper-lib" file="/vendor/framework/helper-lib.jar" />
</permissions>
Last but not least here is how we declare them in that over-all-makefile that says what all to include -> base_packages.mk
PRODUCT_PACKAGES += \
my.company.common \
shared-resources \
helper-lib