Adding and using aar file with resources in AOSP build - android-source

I need to build an application with android.mk in aosp build tree. I have a custom .arr lib with some resources like drawables,strings..etc, Which resides in the following folder apps/libs/mylib.aar
Anyone can tell me how to include the aar in the android aosp build and use that aar resources in another applications. I already tried the following method described here in Stackoverflow.
https://stackoverflow.com/questions/31205856/aar-support-in-android-mk
Android.mk of my application is looked like
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_PACKAGE_NAME := TestSampleAarLib
LOCAL_STATIC_JAVA_AAR_LIBRARIES:= sampleaarlib
LOCAL_STATIC_ANDROID_LIBRARIES += android-support-v7-appcompat
LOCAL_STATIC_ANDROID_LIBRARIES += android-support-v7-gridlayout
LOCAL_STATIC_ANDROID_LIBRARIES += android-support-v13
LOCAL_USE_AAPT2 := true
LOCAL_AAPT_FLAGS := \
--auto-add-overlay \
--extra-packages com.myaar.sample.lib
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_TAGS := optional
LOCAL_PRIVILEGED_MODULE := true
LOCAL_MANIFEST_FILE := AndroidManifest.xml
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := sampleaarlib:libs/sampleaarlib.aar
include $(BUILD_MULTI_PREBUILT)
If anyone have idea about using resources from aar in AOSP Please share.
Thanks in advance.

To add resources from the aar file, please add the following in your android.mk file.
LOCAL_RESOURCE_DIR +=$(call intermediates-dir-for,JAVA_LIBRARIES,<aar_file_name>,,common)/aar/res
Tested and verified in the Android 8.1 version.
NB: In the latest android versions like 9+ resources automatically merged to the project.

Related

How do I add an application in AOSP?

We are trying to develop a custom ROM using AOSP's master branch. We have successfully built and run the compiled image on the emulator provided by AOSP.
Now we are trying to add an application in the AOSP so that the AOSP branch compiles and runs with the application present in it, that means when we run the android version our newly added application will act as a default/system application.
We have tried doing that using following steps, but have failed:
Place the App_name folder to /packages/apps
Add Android.mk to /packages/apps/App_name/
Add App_name entry to /build/target/product/core.mk
PRODUCT_PACKAGES := \
... \
SomeApp \
App_name
Note: App_name is the application folder that is developed using android studio and is present the Android-Studio Projects folder.
After performing these steps we compile the entire source code/AOSP and eventually the compilation fails.
Could someone please help me out??
For adding a default application to AOSP , You should create a directory with arbitrary name in packages/apps (name of directory doesn't matter) , then you should put necessary code and resources in it . Notice AOSP build system doesn't use Gradle ,hence you don't need to copy gradle build files (like build.gradle and setting.gradle and etc).
For a typical app you should create these directories :
src : place your java codes here .
res : place your resources directory for examle drawable , layout , ...
assets : if your project has any assests file , place them in this folder
Your AndroidManifest.xml file should be added in top of your directory.After placing your code and resources , create an Android.mk file and write the following lines in it :
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := <Name of your app>
LOCAL_SDK_VERSION := current
LOCAL_SRC_FILES := $(call all-java-files-under, src)
# Include libraries
LOCAL_JAVA_LIBRARIES := <Java lib dependencies>
LOCAL_STATIC_JAVA_LIBRARIES := android-common
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-appcompat
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_ASSETS_DIR := $(LOCAL_PATH)/assets
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat
include $(BUILD_PACKAGE)
LOCAL_PACKAGE_NAME is name of your app (for examle camera , app1 , ...) ,you should add this name to /build/target/product/core.mk (no folder name , folder name is not important) .
LOCAL_SRC_FILES is pointer to Java codes.
LOCAL_JAVA_LIBRARIES : if your project has java lib dependency , reference to it here.
LOCAL_RESOURCE_DIR is address of res directory
LOCAL_ASSETS_DIR is address of assets directory
Finally build your app and add it to system image . use these commands
make <name of your app>
make snod
<name of your app> is value of LOCAL_PACKAGE_NAME in your Android.mk file. You don't need to build whole AOSP build tree using something like make -j8 . Just build your app and add it to system image. Default applications are placed in read only system partition.

Build NDK with included shared library on multiple platforms

I have built a C++ shared library with NDK builder in Eclipse (firestly creating a JNI project with no MainActivity), which provided as output the different platforms that I have specified in the Application.mk file. The output is in the /obj/local/ directory, spread over the platforms subdirectories (armabi, mips, ... i.e. all the platforms that I have specified in the above file).
Now, I want to use this shared library inside an Android native project, where my shared library is called inside a project's native library (therefore it is about "native-calling-native").
If I build both the shared library and the Android native aplication for just one type of platform (let's say "armeabi"), everything works fine.
My question is how to create the make files, Android.mk and Application.mk, of the Android native project so that to build for ALL the platforms.
I suppose the key is in the Android.mk file, which, for just one platform build it looks like this (on Linux, for the .so type, C++11 for info):
LOCAL_PATH := $(call my-dir)
# Define the shared library module used by the calling JNI C++ module
include $(CLEAR_VARS)
LOCAL_SRC_FILES := libs/libCreateSharedWithJni.so
LOCAL_MODULE := CreateSharedWithJni
LOCAL_EXPORT_C_INCLUDES := libs/CreateSharedWithJni.h
include $(PREBUILT_SHARED_LIBRARY)
# Define the calling JNI C++ module
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_MODULE := finalmodule
LOCAL_SRC_FILES := CppJniCallShared.cpp
LOCAL_SHARED_LIBRARIES := libCreateSharedWithJni
include $(BUILD_SHARED_LIBRARY)
Thanks!
Got it!
In the above Android.mk file just change the line as following
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libCreateSoWithJni.so
i.e. using the $(TARGET_ARCH_ABI) in the path drives the builder to process all platforms specified in the Application.mk APP_ABI variable.

Building Oculus Mobile VR SDK with Eclipse: VrApi module already defined

I am building a blank project in Eclipse with the Oculus Mobile VR SDK. I am getting the following error:
Android NDK: Trying to define local module 'vrapi' in jni/../../../../../../VrApi/Projects/AndroidPrebuilt/jni/Android.mk.
Android NDK: But this module was already defined by jni/../../../../../../VrApi/Projects/AndroidPrebuilt/jni/Android.mk.
Looks like that Android.mk is somehow included twice. I'm using Oculus Mobile VR SDK 0.6.2.0. The following projects are included in my Eclipse workspace:
LibOVRKernel_Prebuilt
MediaSurface
VrApi_Prebuilt
VrAppFramework_Prebuilt
VrGUI
VrLocale
VrSound
Tried re-creating the workspace twice, but still the same error. How can vrapi module be included twice? The only Android.mk where it says
LOCAL_MODULE := vrapi
is in VrApi_Prebuilt and nowhere else.
Thanks
I fixed this by modifying Android.mk inside VrApi_Prebuilt in the following way.
I added
include $(BUILD_SHARED_LIBRARY)
right before the following block:
ifneq (,$(wildcard $(LOCAL_PATH)/$(LOCAL_SRC_FILES)))
include $(PREBUILT_SHARED_LIBRARY)
endif
I removed .so extension from
LOCAL_SRC_FILES := ../../../Libs/Android/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE).so
Hence, the line becomes
LOCAL_SRC_FILES := ../../../Libs/Android/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE)

simplify settings for deb only build with sbt native packager

I am trying to package my scala main app code as a .deb file. the app will only run on an ubuntu machine, so I do not really care about windows etc.
Currently, I am struggling to find the most easiest way to compile the .deb using the simpliest settings. Let's assume I have a simple object Kernel extends App scala file in my src folder that should be bundled inlcuding the jardependencies.
my current scala based debian settings for the project are:
import com.typesafe.sbt.SbtNativePackager._
import NativePackagerKeys.
val debSettings = mapGenericFilesToLinux ++ linuxSettings ++ debianSettings ++ Seq(
name in Debian := "my-app",
version in Debian := "0.1-version",
mainClass := Some("Kernel"),
packageSummary := "",
target := new java.io.File("target"),
packageDescription := "my app",
packageDescription := "my app desciption",
NativePackagerKeys.normalizedName := "normalizedName",
maintainer := "my name",
sourceDirectory := new java.io.File("./src"),
debianPackageDependencies in Debian ++= Seq("openjdk-7-jre"),
debianPackageRecommends in Debian ++= Seq(),
linuxPackageMappings in Debian ++= Seq() ,
debianMaintainerScripts ++=Seq())
the debian:package-bincall works and a deb is created but no binaries/jars are copied into the deb so i'm obviously missing some configuration. i know that there are still missing linuxPackageMappings etc but i'm wondering if there is an easier configuration for the compilation? using packageArchetype.java_server forces me to include so many not-used variables for windows etc. I want to avoid this.
Any suggestion how to simplify the settings + mappings for a deb-only build?
You can just pull in the settings that are relevant to you from:
https://github.com/sbt/sbt-native-packager/blob/master/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala#L24
and
So, this should be something like:
import com.typesafe.sbt.packager.archetypes._
packagerSettings
mapGenericMappingsToLinux
JavaAppPackaging.settings
JavaServerAppPackaging.debianSettings
caveat the correct imports. Let's cover what each of these do:
packagerSettings adds the basic "flow" of the packager tasks, but does not configure any of the files or settings
mapGenericMappingsToLinux is the hook which will take everything configured in mappings in Universal and attempt to make it linux friendly for linux packages.
JavaAppPackaging.settings will take your build definition, and automatically fill out the mappings in Universal configuration with defaults for your application.
JavaServerAppPackaging.debianSettings adds additional settings specifically for debian such that the bundled default application can be started as a server.
One of the goals of the plugin is to allow you the flexibility to use any of these "mappings" and get default behavior or override. It's just not well documented how. I hope this helps!

Change 'play dist' output file name via command-line

Is it possible to change play dist output file name apart from modifying appName on Build.scala?
I'm trying to automate the creation of two different zip files from the same project tree, e.g.: myapp-production-1.0-SNAPSHOT.zip and myapp-integration-1.0-SNAPSHOT.zip.
Thank you very much!
For Play Framework 2.4 changing the name of the output file worked like this in build.sbt:
packageName in Universal := "dist"
In Play Framework 2.2, you can add the following line to the build.sbt file:
name in Universal := "dist"
Your app will be packaged in target/universal/dist.zip
You can modify the output by changing the build.sbt file in your project directory.
name := "myname"
version := "1.0-SNAPSHOT"
Remember to recompile, might have to clean too.