0

I meet a question about running android emulator, here is the details below. Thanks a lot!

I need to run android emulator automatically, so tend to use execve in Linux, the source code shown below:

/*initailize passed command line\*/

char *binary = (char*)malloc(8*sizeof(char));  
char **newargv = (char **)malloc(16*sizeof(char *));

newargv[0] = "/media/career/android/source/out/host/linux-x86/sdk/android-sdk_eng.corey_linux-x86/tools/emulator";  
newargv[1] = "-avd";

newargv[2] = "new1";

newargv[3] = "-system";

newargv[4] = "/media/career/android/source/out/target/product/generic/system.img";

newargv[5] = "-ramdisk";

newargv[6] = "/media/career/android/source/out/target/product/generic/ramdisk.img";

newargv[7] = "-data";

newargv[8] = "/media/career/android/source/out/target/product/generic/userdata.img";

newargv[9] = NULL;        

/*initialize the env value of new process(emulator) */

const char *temp = getenv("ANDROID_AVD_HOME");

envp[0] = temp;

envp[1] = getenv("PATH");

envp[2] = NULL;

/*main function*/
if (execve (binary, (char **)newargv, (char **)envp) < 0 )  

environment variable:
declare -x ANDROID_AVD_HOME="/home/corey/.android/avd"
declare -x PATH="/media/career/android/source/out/host/linux-x86/sdk/android-sdk_eng.corey_linux-x86/platform-tools:/media/career/android/source/out/host/linux-x86/sdk/android-sdk_eng.corey_linux-x86/tools:

The console shows: PANIC: Could not open: /tmp/.android/avd/new1.ini

My avd stored path is ~/.android/avd by default. But the new process only find the root filesystem's path for reading avd files with bad portability. Actually the process of emulator has run. I focus on setting env variables, but failed.

May I ask how should I set my environment variables?

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
corey
  • 1

1 Answers1

0

You have passed wrong envp

const char *temp = getenv("ANDROID_AVD_HOME");
envp[0] = "ANDROID_AVD_HOME=" + temp;
envp[1] = "PATH=" + getenv("PATH");
envp[2] = NULL;

replace + with safety strcat

Zang MingJie
  • 5,164
  • 1
  • 14
  • 27