public static boolean addFilesToExistingZipAapt(File tempApk,ArrayList<File> classesFiles){
  ArrayList<String> rmCmd=new ArrayList<String>();
  rmCmd.add(S.getAapt());
  rmCmd.add("r");
  rmCmd.add("-k");
  rmCmd.add(tempApk.getAbsolutePath());
  for (  File f : classesFiles)   rmCmd.add(f.getName());
  String[] cmdRm=new String[rmCmd.size()];
  for (int i=0; i < rmCmd.size(); i++)   cmdRm[i]=rmCmd.get(i);
  CmdUtils.runCommand(cmdRm);
  ArrayList<String> cmds=new ArrayList<String>();
  cmds.add(S.getAapt());
  cmds.add("a");
  cmds.add("-k");
  cmds.add(tempApk.getAbsolutePath());
  for (  File f : classesFiles)   cmds.add(f.getAbsolutePath());
  String[] cmd=new String[cmds.size()];
  for (int i=0; i < cmds.size(); i++)   cmd[i]=cmds.get(i);
  boolean sucess=(CmdUtils.runCommand(cmd) == 0);
  if (!sucess) {
    sucess=true;
    for (    File f : classesFiles) {
      try {
        sucess=sucess && ZipTools.isFileinZip(f.getName(),new ZipFile(tempApk));
      }
 catch (      ZipException e) {
        e.printStackTrace();
      }
    }
  }
  return sucess;
}

public static boolean addFilesToExistingZipAapt ( File tempApk , ArrayList < File > classesFiles ) { ArrayList < String > rmCmd = new ArrayList < String > ( ) ; rmCmd . add ( S . getAapt ( ) ) ; rmCmd . add ( "r" ) ; rmCmd . add ( "-k" ) ; rmCmd . add ( tempApk . getAbsolutePath ( ) ) ; for ( File f : classesFiles ) rmCmd . add ( f . getName ( ) ) ; String [ ] cmdRm = new String [ rmCmd . size ( ) ] ; for ( int i = 0 ; i < rmCmd . size ( ) ; i ++ ) cmdRm [ i ] = rmCmd . get ( i ) ; CmdUtils . runCommand ( cmdRm ) ; ArrayList < String > cmds = new ArrayList < String > ( ) ; cmds . add ( S . getAapt ( ) ) ; cmds . add ( "a" ) ; cmds . add ( "-k" ) ; cmds . add ( tempApk . getAbsolutePath ( ) ) ; for ( File f : classesFiles ) cmds . add ( f . getAbsolutePath ( ) ) ; String [ ] cmd = new String [ cmds . size ( ) ] ; for ( int i = 0 ; i < cmds . size ( ) ; i ++ ) cmd [ i ] = cmds . get ( i ) ; boolean sucess = ( CmdUtils . runCommand ( cmd ) == 0 ) ; if ( ! sucess ) { sucess = true ; for ( File f : classesFiles ) { try { sucess = sucess && ZipTools . isFileinZip ( f . getName ( ) , new ZipFile ( tempApk ) ) ; } catch ( ZipException e ) { e . printStackTrace ( ) ; } } } return sucess ; }
this method uses aapt to add classes files to the given apk / jar the junk path are ignored ( classes file will be added to the root of the apk / jar )
