当前位置: 代码迷 >> Android >> [Android]_[初级]_[sdk docs reference api 文档打开慢的解决方法]
  详细解决方案

[Android]_[初级]_[sdk docs reference api 文档打开慢的解决方法]

热度:474   发布时间:2016-04-28 02:34:05.0
[Android]_[初级]_[sdk docs reference api 文档打开慢的解决办法]


场景:

1. 下载sdk时下载了docs/reference文档,文档是html形式的,因为里面带有google的相关网址,浏览器打开时会去访问这些被墙的网址,所以显示巨慢。

2. 解决办法就是遍历子目录删除google相关网址,由于是android开发,就用Java实现吧.

3.以下运行用时9分钟,i5双核,4G内存,开了其他东西,最新的sdk docs,android 5L.

4.即使删除了这些, firefox打开一个package链接还是得5秒左右.


文件.Cleaner.java

import java.io.*;public class Cleaner{	public static void main(String[] args) {		System.out.println("begin to clean google.com;googleapis.com;google-analytics.com");		String currentDir = args[0];		Cleaner c = new Cleaner();		c.work(currentDir);		System.out.println("end to clean google.com;googleapis.com;google-analytics.com");		}	public Cleaner(){}	public void work(String currentDir){		File file = new File(currentDir);		deleteReference(file);	}	public void deleteReference(File file)	{		String[] files = file.list();		String path = file.getPath();		for (String one : files) {			String filePath = path+File.separatorChar+one;			// System.out.println(filePath);				File fileTemp = new File(filePath);				if(fileTemp.isDirectory())			{				deleteReference(fileTemp);			}else{				// delete google reference				if(filePath.endsWith(".html"))				{					try					{						BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileTemp),"UTF-8"));						filePath = filePath+".tmp";						File newFile = new File(filePath);						BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile),"UTF-8"));						String line = null;						while((line = br.readLine())!= null)						{							String newLine = line.replaceAll("google\\.com|googleapis\\.com|google-analytics\\.com","");							bw.write(newLine);							bw.newLine();						}						br.close();						bw.close();						fileTemp.delete();						newFile.renameTo(fileTemp);					}catch(Exception e)					{						e.printStackTrace();					}				}			}				}		}}

编译执行:

C:\Users\Admin\Desktop>javac Cleaner.java & java Cleaner E:\software\adt\sdk\docs\referencebegin to clean google.com;googleapis.com;google-analytics.comend to clean google.com;googleapis.com;google-analytics.com

补充一点会快点,但是firefox还是得要5秒,有时间再分析加载过程吧,凑合用着:

删除 sdk/docs/assets/js/docs.js里的 https://apis.google.com/js/plusone.js


1楼u0140404108小时前
表示没啥效果
Re: infoworld6小时前
回复u014040410n补充一点会快点,但是firefox还是得要5秒,有时间再分析加载过程吧,凑合用着:nn删除 sdk/docs/assets/js/docs.js里的 https://apis/js/plusone.js
Re: infoworld6小时前
回复infoworldn打错了,应该是删这个 https://apis.google.com/js/plusone.js
  相关解决方案