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;
}
}