Android 引用完整工程包括Activity和资源文件
来源:互联网 发布:手机扫描条码软件 编辑:程序博客网 时间:2024/04/30 09:24
最近需要把以前做的一个完整工程打包成SDK.供别的工程调用.开发过程中,参考过一些其他的相关文章, 一点点心得,自己在此记录一下.1. 首先把需要打包成SDK的工程种, Activity的 layout, string, color, drawable等文件, 重新命名, 做到命名唯一.2. 由于主工程引用SDK工程, 自动生成SDK工程的R文件, 则在主工程Gen文件下面.3. 修改查找资源文件方法,见类Resource.
Resource
public class Resource { private static final String TAG = "Resource"; public static final String ID = "id"; public static final String LAYOUT = "layout"; public static final String DRAWABLE = "drawable"; public static final String STRING = "string"; public static final String COLOR = "color"; public static final String ANIM = "anim"; public static final String STYLE = "style"; public static final String DIMEN = "dimen"; @SuppressWarnings("rawtypes") public static int getResId(Context context, String className, String name) { String packageName = context.getPackageName(); Class r = null; int id = 0; try { r = Class.forName(packageName + ".R"); Class[] classes = r.getClasses(); Class desireClass = null; for (int i = 0; i < classes.length; ++i) { if (classes[i].getName().split("\\$")[1].equals(className)) { desireClass = classes[i]; break; } } if (desireClass != null){ id = desireClass.getField(name).getInt(desireClass); Log(TAG, "class name : " + desireClass.getName()+" id : " + id); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } return id; } /** * id * @param context * @param name * @return */ public static int getId(Context context, String name){ return getResId(context, ID, name); } /** * stringId * @param context * @param name * @return */ public static int getStringId(Context context, String name){ return getResId(context, STRING, name); } public static int getLayoutId(Context context, String name){ return getResId(context, LAYOUT, name); } public static int getColorId(Context context, String name){ return getResId(context, COLOR, name); } public static int getAnimId(Context context, String name){ return getResId(context, ANIM, name); } public static int getStyleId(Context context, String name){ Log(TAG, "getStyleId : " + getResId(context, STYLE, name)+" name : " + name); return getResId(context, STYLE, name); } public static int getDimen(Context context, String name){ return getResId(context, DIMEN, name); } /** * drawableId * @param context * @param name * @return */ public static int getDrawableId(Context context, String name){ return getResId(context, DRAWABLE, name); } private static void Log(String tag, String log) { LogUtils.i(tag, log); }}
找到相应的资源文件.
4.关于AndroidManifest.xml清单文件配置:
–>4.1. 把SDK中的权限,以及activity,receiver,service,拷贝到当前主工程下面.
–>4.2. project.properties文件中 manifestmerger.enabled=true 不过有个要求
(Commented content should be opened if your ADT version is lower than v20, or you remove the “manifestmerger.enabled=true” from project.properties)
0 0
- Android 引用完整工程包括Activity和资源文件
- android工程引用另外一个工程的类和资源
- android引用另一工程的源文件及资源文件方法
- 如何引用android系统公开(非公开)的资源文件,包括字符串,layout,color,等等
- [Android] 将Android工程做成jar包和资源文件
- [Android] 将Android工程做成jar包和资源文件
- 解决android引用依赖工程资源问题
- 将Android工程做成jar包和资源文件
- android Xml文件引用资源中@和?的区别
- Android工程依赖:android中打包含有Activity以及资源文件的jar包在工程中调用
- Android工程依赖:android中打包含有Activity以及资源文件的jar包在工程中调用
- Android工程依赖:android中打包带有Activity以及资源文件的jar包在工程中调用
- Android工程依赖:android中打包带有Activity以及资源文件的jar包在工程中调用
- android中打包含有Activity以及资源文件的jar包在工程中调用
- Android中打包含有Activity以及资源文件的jar包在工程中调用
- Android中打包含有Activity以及资源文件的jar包在工程中调用
- android中打包含有Activity以及资源文件的jar包在工程中调用
- android中打包含有Activity以及资源文件的jar包在工程中调用
- 用okhttp实现webSocket长连接
- BASE64编码
- git 分支
- c 求素数的一般方法
- int 0x13 中断理解
- Android 引用完整工程包括Activity和资源文件
- Android 侧滑菜单(DrawerLayout+ToolBar的使用)
- 常用js模板代码-模块化
- 栈和队列面试题(四)
- JVM垃圾回收器工作原理及实例介绍
- IOS应用网络数据包拦截之三 网络环境模拟软件Network Link Conditioner使用介绍
- 编程是一门艺术,我们是艺术家,很严谨。
- mysql 数据库操作
- 探码科技深度解析——技术合伙人怎么合作