码迷,mamicode.com
首页 > 移动开发 > 详细

android 简单打jar包

时间:2016-12-27 13:58:45      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:make   nal   build   http   lib   rename   nec   lis   打开   

 

先建议一个moduel,先写一个下载图片代码:

public class LoadTest extends AsyncTask<Void,Void,byte[]>{

public static LoadTest loadtest;

private byte[] data;

private String url;
public setDataL listence;


public void setDataListence(setDataL l){
this.listence = l;
}
public byte[] getload(){

return data;
}

public void setUrl(String s){
this.url = s;
}
@Override
protected byte[] doInBackground(Void... params) {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URL urlimage = new URL(url);
HttpURLConnection urlconn = (HttpURLConnection) urlimage.openConnection();
urlconn.setConnectTimeout(5000);
urlconn.setRequestMethod("GET");
int sumLenght = urlconn.getContentLength();
InputStream errorStream = urlconn.getErrorStream();
int code = urlconn.getResponseCode();
if (HttpURLConnection.HTTP_OK == code){
InputStream is = urlconn.getInputStream();
byte[] buff = new byte[512];
int len;
while ((len = is.read(buff))!= -1){
outputStream.write(buff,0,len);

}
is.close();
outputStream.flush();
data = outputStream.toByteArray();

}

} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return data;
}

@Override
protected void onPostExecute(byte[] datainfo) {
if (null != datainfo){

listence.getData(datainfo);
}else {

super.onPostExecute(datainfo);
}
}

public interface setDataL{
void getData(byte[] data);
}

}

打开moduel的gradle:
写入代码:

task makeJar(type: Copy) {
delete ‘build/libs/myjar.jar‘
from(‘build/intermediates/bundles/release/‘)
into(‘build/libs/‘)
include(‘classes.jar‘)
rename(‘classes.jar‘, ‘myjar.jar‘)
}
// 在终端执行生成JAR包
// ./gradlew build
//build.finalizedBy makeJar
// 或者
makeJar.dependsOn(build)
// ./gradlew makeJar

打开终端机Terminal输入命令:gradview makeJar

生成的jar在\build\intermediates\bundles\release目录下。可以看到一个java标志如图:

技术分享

这样就可以啦,导入其他的项目几可以使用了

 

demo下载地址:https://github.com/tiaodong/OkHttpTest

 

测试demo:https://github.com/tiaodong/JarTest

android 简单打jar包

标签:make   nal   build   http   lib   rename   nec   lis   打开   

原文地址:http://www.cnblogs.com/renjiemei1225/p/6225300.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!