package com.qy.utils;

import java.io.File;
import java.io.IOException;


public  class ApkSignTools {
	public static void main(String[] args) {
		File file=new File("/media/yutou/_dde_data/AndroidStudio_Data/buildTools/hezi/test.apk.out/test.apk");
		ApkSignTools tools=new ApkSignTools();
		tools.setApkFile(file);
		tools.setSignFile(new File("/media/yutou/_dde_data/AndroidKeys/langtian.jks"));
		tools.setName("langtian");
		tools.setKeyStorePassword("134679");
		tools.setSignKey("134679");
		tools.sign();
	}
	private File apkFile;
	private File signFile;
	private String signKey;
	private String keyStorePassword;
	private String name;
	
	public ApkSignTools() {
		// TODO Auto-generated constructor stub
	}
	public boolean sign() {
		String exec="jarsigner -verbose -keystore \"" + signFile.getAbsolutePath() + "\" -keypass " + signKey
				+ " -storepass " + keyStorePassword + " -signedjar \"" + apkFile.getAbsolutePath()+"_sign.apk" + "\" \"" + apkFile.getAbsolutePath() + "\" " + name;
		System.out.println(exec);
		try {
			Runtime.getRuntime().exec(exec).waitFor();
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}
	public File getSignFile() {
		return signFile;
	}
	public void setSignFile(File signFile) {
		this.signFile = signFile;
	}
	public String getSignKey() {
		return signKey;
	}
	public void setSignKey(String signKey) {
		this.signKey = signKey;
	}
	public String getKeyStorePassword() {
		return keyStorePassword;
	}
	public void setKeyStorePassword(String keyStorePassword) {
		this.keyStorePassword = keyStorePassword;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public File getApkFile() {
		return apkFile;
	}
	public void setApkFile(File apkFile) {
		this.apkFile = apkFile;
	}
	public boolean chack() {
		// TODO Auto-generated method stub
		if(apkFile==null||!apkFile.exists()) {
			return false;
		}
		if(signFile==null||!signFile.exists()) {
			return false;
		}
		return true;
	}
	
	
	
}
