android 简单打jar包

欠伸展肢体,吟咏心自愉。这篇文章主要讲述android 简单打jar包相关的知识,希望能为你提供帮助。
 
先建议一个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 voidsetUrl(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 = https://www.songbingjia.com/android/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标志如图:
android 简单打jar包

文章图片

这样就可以啦,导入其他的项目几可以使用了
 
demo下载地址:https://github.com/tiaodong/OkHttpTest
 
【android 简单打jar包】测试demo:https://github.com/tiaodong/JarTest

    推荐阅读