附的 build tool 是 gradle.
build 的過程大概就是...
找不到 android sdk ..
ref: http://xinyustudio.wordpress.com/2014/07/02/gradle-sdk-location-not-found-the-problem-and-solution/
new 一個 local.properties:
sdk.dir=/home/charles-chang/adt-bundle-linux-x86_64-20140702/sdk這樣就可以。
剩下就是 需要對應的 sdk version, build tool version, support repository 等等。
就有 error 就開啟 android sdk manager 來 install 就可以。
github: https://github.com/checko/iperf-project
這個 project 很有趣,是分成兩部份: iperf, Android UI
iperf 就是一般的 iperf 執行城市,所以是用 ndk-build,
build 出來執行檔 iperf 會被放在 Android package 的 assets 中。
UI 啟動後,把 assets/iperf copy 到 /data/data/iperf.project/ 來執行。
InputStream in = getResources().getAssets().open("iperf");
OutputStream out = new FileOutputStream("/data/data/iperf-project/iperf", false);
byte[] buf = new byte[1024];
int len;
while ((len=in.read(buf)) > 0) {
out.write(buf,0,len);
}
in.close();
out.close();
然後 chmod +x :
Process processchmod = runtime.GetRuntime().exec("/system/bin/chmod 744 /data/data/iperf.project/iperf");
processchmod.waitFor();
執行 iperf 和取得結果的動作在令一個 , AsyncTask 做:
先把 command process 做出來,執行。
List<String> commandList = new ArrayList<String>(Arrays.asList(commands)); commandsList.add(0,"/data/data/iperf.project/iperf"); Process process = new ProcessBuilder().command(commandList).redirectErrorStream(true).start();
然後拿到這個 process 的 output, 接到一個 InputStream 來讀:
BufferReader reader = new BufferReader(new InputStreamReader(process.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while((read = reader.read(buffer)) > 0) {
output.append(buffer,0,read);
publishProgress(output.toString());
output.delete(0,output.length());
}
reader.close();
process.destroy();
沒有留言:
張貼留言