I creating an Android application that allow to execute some iperf commands. To do that, I got the version 3 of the source code of the IPerf C project and I cross-compile it using those commands :
> make clean
> ./configure --host=arm-linux --prefix=/home/laboPC/Downloads CC=arm-linux-androideabi-gcc CXX=arm-linux-androideabi-g++ CFLAGS="-static" CXXFLAGS="-static" LDFLAGS="-pie -fuse-ld=bfd"
> make
After the cross-compile, I got a binary file that I put in the assets folder in my android project.
For using IPerf from Android, I create a copy of the binary in this way :
private String binariePath = context.getApplicationInfo().dataDir + "/iperf3";
private void setupBinaries(){
InputStream in = context.getResources().openRawResource(R.raw.iperf3);
OutputStream out = new FileOutputStream(binariePath);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.flush();
out.close();
Runtime.getRuntime().exec("chmod 751 " + binariePath);
}
And then, I using a Runtime object to execute a iperf command like this :
public String runClient (String server, String argument) {
try {
setupBinaries();
process = Runtime.getRuntime().exec(binariePath + " -c " + server + " " + argument);
BufferedReader reader = new BufferedReader( new InputStreamReader(process.getInputStream()));
final StringBuilder result = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
result.append(line + "\n");
}
reader.close();
process.destroy();
return result.toString();
} catch (IOException e) {
Log.d("IPERF", e.getLocalizedMessage());
return e.getLocalizedMessage();
}
}
Everythings works fine except in Android 7.0. When I runnig my app on the Nexus 5X in Android 7, the iperf command seems not to be execute and my result
variable is empty.
I checked that the Runtime.exec() works fine in android 7 and that the binary is correctly copy in the app data directory.
Is everyone has an idea what is wrong in my process ? Is my commands fo compile IPerf project is correct ?
Thanks for your help.
EDIT
I found in the followings threads that Android 6.0 and higher can execute binaries that are compiled with the -fPIC option :
android ndk: are -fPIC and -pie mututally exclusive?
Position Independent Executables and Android Lollipop
So I tried to compile my C project by using this command line :
./configure --host=arm-linux --prefix=/home/laboPC/Downloads CC=arm-linux-androideabi-gcc CXX=arm-linux-androideabi-g++ CFLAGS="-static -fPIC" CXXFLAGS="-static" LDFLAGS="-pie -fuse-ld=bfd"
I think there is something wrong about my command line but I don't know what. Is anybody can help me to identifiate what I wrong in my command line ?