Share Point:How to make another framework-res.apk for OEM to share resource.

1,244 views
Skip to first unread message

James Wang

unread,
Dec 3, 2009, 9:27:46 PM12/3/09
to android-platform
I have asked a question "how is framework-res.apk loaded?"(http://
groups.google.com/group/android-porting/browse_thread/thread/
730a22ab62d76c24/b07c2e7d54e98f79#b07c2e7d54e98f79) and got some
suggestions from Dianne.

My colleague got the solution about how to make resource apk of our
own self and I am sharing it with others and want some expert can tell
me whether there is any risk. ( Dianne suggested :Don't do it)

1. Make an apk project for your resource: AppRes
write Android.mk as others and add command below to it:
#tell aapt to generate resource ID from 0x20
LOCAL_AAPT_FLAGS := -x

LOCAL_EXPORT_PACKAGE_RESOURCES := true

2. create an apk to use resource apk APP1
add command below to its Android.mk
{{{
# include R.java of resource apk
LOCAL_INTERMEDIATE_SOURCES := $(framework-res-source-path)/my/own/
resource/apk/R.java
}}}

3. modify Android build script
modify build/target/product/core.mk like below:

PRODUCT_PACKAGES := \
framework-res \
AppRes \ <-- our resource apk name, created under
system/framework


modify build/target/product/generic.mk

PRODUCT_PACKAGES := \
AlarmClock \
......
SyncProvider \
App1 <-- apk to use resouce, created under
system/app


4. modify frameworks/base/libs/utils/AssetManager.cpp
let android load both frame-res.apk and our resource apk.

//our resource apk path
static const char* kMyAssets = "framework/appres.apk";

//修改下面的方法
bool AssetManager::addDefaultAssets()
{
const char* root = getenv("ANDROID_ROOT");
LOG_ALWAYS_FATAL_IF(root == NULL, "ANDROID_ROOT not set");
/* This is original code
String8 path(root);
path.appendPath(kSystemAssets);

return addAssetPath(path, NULL);
*/
//add code below
bool isOK1 = false;
bool isOK2 = false;
{ // load framework-res.apk
String8 path(root);
path.appendPath(kSystemAssets);
isOK1 = addAssetPath(path, NULL);
}
{ // load our resource apk
String8 path(root);
path.appendPath(kMyAssets);
isOK2 = addAssetPath(path, NULL);
}
return isOK1 && isOK2;
}
}}}
5. how to use it.

We can write code like below:

tv1 = (TextView) findViewById(R.id.tvWelcome1);
tv1.setText(my.own.resource.apk.R.string.welcome);


6. compile

>make clean
>make
if you got any error message complaining about needing resource apk,
do next:
>source build/envsetup.sh
>mmm packages/apps/AppRes/
>make

My colleague tell me we even can add class to resource apk to share
it.

Any suggestion and question is welcome.

James

Dianne Hackborn

unread,
Dec 4, 2009, 4:02:16 AM12/4/09
to android-...@googlegroups.com
You are only lucky if that works.  I'll say this one more time, and then I'll let you hang yourself: the resource system does not support this, and if you do this you are likely to cause all kinds of problems for yourself.  Just don't do this.  Seriously.

Now if you want to continue to ignore me, fine, it's on your head.


--

You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.





--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

James Wang

unread,
Dec 5, 2009, 9:28:21 AM12/5/09
to android-platform
Hi, Dianne. Thanks for your advice again.

We are doing some research on how to share resource as OEM for our
customer.
Any possbile way will be take into consideration. And of course, your
professional opinion will also be included into our research report.

Thank you very much.


Reply all
Reply to author
Forward
0 new messages