有界面(Activity或其他View)的SDK项目混淆发布
2016-07-15 14:50
232 查看
1.首先,作为SDK的项目查找界面时不能按常规的套路来,之前的Activity设置界面是setContentView(R.layout.activity_main)。现在提供一个资源工具类(据说是一个天才少年写的,我直接复制给大家了),所有资源都通过该类查找。
自定义view属性的获取:
2.确保所有资源的名字唯一,比如预设的activity_main.xml最好改一个名字,因为引用SDK的人(后面称为Client)很可能也有一个xml文件叫做activity_main.xml。
3.所有涉及到声明的东西,必须在Client的AndroidManifest.xml中声明,比如权限、Activity、Service、BroadcastReceiver等(仅针对eclipse,AndroidStudio另算)。
4.lib打包成jar时,除了src以外其他都不能选择。
5.将jar包混淆,参考http://blog.csdn.net/ithouse/article/details/51605955
6.删除你之前SDK项目中src目录下的所有源码,拷贝混淆之后的jar包到SDK项目的libs目录下。
7.将该SDK项目发布出去,让Client引用该项目即可。
/* * Copyright (C) 2015 pengjianbo(pengjianbosoft@gmail.com), Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.vzone.tmdsdk.tool; import java.lang.reflect.Field; import android.content.Context; /** * Desction: Author:pengjianbo Date:15/10/22 下午9:01 */ public class ResourceUtils { /** * 获取 layout 布局文件 * * @param context * Context * @param resName * layout xml 的文件名 * @return layout */ public static int getLayoutId(Context context, String resName) { return context.getResources().getIdentifier(resName, "layout", context.getPackageName()); } /** * 获取 string 值 * * @param context * Context * @param resName * string name的名称 * @return string */ public static int getStringId(Context context, String resName) { return context.getResources().getIdentifier(resName, "string", context.getPackageName()); } /** * 获取 drawable 布局文件 或者 图片的 * * @param context * Context * @param resName * drawable 的名称 * @return drawable */ public static int getDrawableId(Context context, String resName) { return context.getResources().getIdentifier(resName, "drawable", context.getPackageName()); } /** * 获取 style * * @param context * Context * @param resName * style的名称 * @return style */ public static int getStyleId(Context context, String resName) { return context.getResources().getIdentifier(resName, "style", context.getPackageName()); } /** * 获取 styleable * * @param context * Context * @param resName * styleable 的名称 * @return styleable */ /*public static Object getStyleableId(Context context, String resName) { return context.getResources().getIdentifier(resName, "styleable", context.getPackageName()); }*/ /** * 获取 anim * * @param context * Context * @param resName * anim xml 文件名称 * @return anim */ public static int getAnimId(Context context, String resName) { return context.getResources().getIdentifier(resName, "anim", context.getPackageName()); } /** * 获取 id * * @param context * Context * @param resName * id 的名称 * @return */ public static int getId(Context context, String resName) { return context.getResources().getIdentifier(resName, "id", context.getPackageName()); } /** * color * * @param context * Context * @param resName * color 名称 * @return */ public static int getColorId(Context context, String resName) { return context.getResources().getIdentifier(resName, "color", context.getPackageName()); } private static Object getResourceId(Context context, String name, String type) { String className = context.getPackageName() + ".R"; try { Class<?> cls = Class.forName(className); for (Class<?> childClass : cls.getClasses()) { String simple = childClass.getSimpleName(); if (simple.equals(type)) { for (Field field : childClass.getFields()) { String fieldName = field.getName(); if (fieldName.equals(name)) { System.out.println(fieldName); return field.get(null); } } } } } catch (Exception e) { e.printStackTrace(); } return null; } /** * 获取styleable的ID号数组 */ public static int[] getStyleableArray(Context context,String name) { return (int[])getResourceId(context, name,"styleable"); } /** *context.getResources().getIdentifier无法获取到styleable的数据 */ public static int getStyleable(Context context, String name) { return ((Integer)getResourceId(context, name,"styleable")).intValue(); } }
自定义view属性的获取:
TypedArray a = context.obtainStyledAttributes(attrs, ResourceUtils.getStyleableArray(context, "CircleImageView"), defStyle, 0); mBorderWidth = a.getDimensionPixelSize(ResourceUtils.getStyleable(context, "CircleImageView_civ_border_width"), DEFAULT_BORDER_WIDTH); mBorderColor = a.getColor(ResourceUtils.getStyleable(context, "CircleImageView_civ_border_color"), DEFAULT_BORDER_COLOR); mBorderOverlay = a.getBoolean(ResourceUtils.getStyleable(context, "CircleImageView_civ_border_overlay"), DEFAULT_BORDER_OVERLAY); mFillColor = a.getColor(ResourceUtils.getStyleable(context, "CircleImageView_civ_fill_color"), DEFAULT_FILL_COLOR); a.recycle();
2.确保所有资源的名字唯一,比如预设的activity_main.xml最好改一个名字,因为引用SDK的人(后面称为Client)很可能也有一个xml文件叫做activity_main.xml。
3.所有涉及到声明的东西,必须在Client的AndroidManifest.xml中声明,比如权限、Activity、Service、BroadcastReceiver等(仅针对eclipse,AndroidStudio另算)。
4.lib打包成jar时,除了src以外其他都不能选择。
5.将jar包混淆,参考http://blog.csdn.net/ithouse/article/details/51605955
6.删除你之前SDK项目中src目录下的所有源码,拷贝混淆之后的jar包到SDK项目的libs目录下。
7.将该SDK项目发布出去,让Client引用该项目即可。
相关文章推荐
- Android ADT 23.0.0无法更新到23.0.2问题解决方案
- windows用windeployqt发布qt quick application程序
- SDKMAN:轻松管理多个软件开发套件 (SDK) 的命令行工具
- Java 版的 Ruby 解释器 JRuby 1.7.14 发布
- Fedora Linux 7 Test 4 发布 下载地址
- 使用npm发布Node.JS程序包教程
- Parse正式发布开源PHP SDK
- .Net下的签名与混淆图文分析
- 微软NET Framework 3.5 Beta 1 发布 提供下载
- 可简单避免的三个JS发布错误的详细介绍
- Jquery 自定义事件实现发布/订阅的简单实例
- Android实现将一个Activity设置成窗口样式的方法
- ASP.NE网站发布注意事项简析
- Android Activity 完全结束并退出程序的实例
- Android开发 旋转屏幕导致Activity重建解决方法
- Android 中动态加载.jar的实现步骤
- 基于Android SDK-在64位Linux中使用需要注意的问题
- android横竖屏切换时候Activity的生命周期
- Android学习笔记--使用剪切板在Activity中传值示例代码
- Android开发技巧之在a标签或TextView控件中单击链接弹出Activity(自定义动作)