集中修复升级ADT22以后ClassNotFoundException的项目

Google前段时间放出了ADT22的版本,很多Android开发人员都升级了,结果一些问题导致和原来的project出现问题,具体表现为:

如果在libs下面引用了其他项目的jar包,会抛ClassNotFoundException,检查后发现bin目录里面的dexedLibs压根没东西,根本没有将libs下面的jar包编译进去。

解决:找到对应project里面的 .classpath文件将

 <classpathentry  kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>

改成
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>

即可。

可惜我workspace里面的project太多,手工改起来不方便,写个程序吧,处理一下workspace里面的project

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class ProjectFixer {

	public static void main(String[] args) {
		System.out.println("Fix workspace after ADT22 upgraded V0.1*");
		System.out.println("**Please input workspace directory path**");
		Scanner scanner = new Scanner(System.in);
		File workspace = new File(scanner.nextLine());
		if (!workspace.isDirectory()) {
			System.out.println("**Not a path ! Exiting......**\n");
			return;
		}
		System.out.println("Scanning workspace......");
		ArrayList<File> progjectFils = scanDir(workspace);
		System.out.println("Found " + progjectFils.size()
				+ " Files ,Enter to fix...");
		scanner.nextLine();
		scanner.close();
		fixProject(progjectFils);
	}

	static void fixProject(ArrayList<File> progjectFils) {
          for (File file : progjectFils) {
			fixClassPathFile(file);
		}
	}

	
	
	public static void fixClassPathFile(File inFile) {
		try {
			FileInputStream fs = new FileInputStream(inFile);
			if (!inFile.isFile()) {
				System.out.println(inFile.getPath()+" is not an existing file");
				return;
			}else{
				System.out.println(inFile.getPath()+"   *fixing....");
			}
			File tempFile = new File(inFile.getAbsolutePath() + ".tmp");
			BufferedReader br = new BufferedReader(new InputStreamReader(fs,
					"UTF-8"));
			PrintWriter pw = new PrintWriter(new OutputStreamWriter(
					new FileOutputStream(tempFile), "UTF-8"));
			String line = null;

			while ((line = br.readLine()) != null) {
				if (!line
						.trim()
						.contains(
								"path=\"com.android.ide.eclipse.adt.LIBRARIES\"")) {
					pw.println(line);
					pw.flush();
				} else {
					pw.println(" <classpathentry exported=\"true\" kind=\"con\" path=\"com.android.ide.eclipse.adt.LIBRARIES\"/>");
					pw.flush();
				}
			}
			pw.close();
			br.close();
			if (!inFile.delete()) {
				System.out.println("Could not delete file");
				return;
			}
			if (!tempFile.renameTo(inFile))
				System.out.println("Could not rename file");

		} catch (FileNotFoundException ex) {
			ex.printStackTrace();
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}

	static ArrayList<File> scanDir(File dir) {
		ArrayList<File> classpaths = new ArrayList<File>();
		for (File projectDir : dir.listFiles()) {
			if (projectDir.isDirectory()) {
				for (File frojectFile : projectDir.listFiles()) {
					if (frojectFile.getName().equals(".classpath"))
						classpaths.add(frojectFile);
				}
			}
		}
		return classpaths;
	}

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值